1#include "AppleIrDA.h"
2#include "IrDAUser.h"
3#include "IrDAUserClient.h"
4
5#define super IORS232SerialStreamSync
6
7    OSDefineMetaClassAndAbstractStructors(AppleIrDASerial, IORS232SerialStreamSync);
8
9
10#undef super
11#define super IOService
12    OSDefineMetaClassAndStructors( AppleIrDA, IOService );
13
14/*static*/
15AppleIrDA*
16AppleIrDA::withNub(AppleIrDASerial *nub)
17{
18    AppleIrDA *obj;
19
20    obj = new AppleIrDA;
21
22    if (obj != NULL) {
23	if (obj->init() == false) {
24	    obj->release();
25	    obj = NULL;
26	}
27    }
28    if (obj != NULL) {
29	obj->fNub = nub;
30    }
31    return (obj);
32}
33
34IOReturn
35AppleIrDA::newUserClient( task_t owningTask, void*, UInt32 type, IOUserClient **handler )
36{
37
38    IOReturn ioReturn = kIOReturnSuccess;
39    IrDAUserClient *client = NULL;
40
41    ELG( 0, type, 'irda', "new user client" );
42
43   // Check that this is a user client type that we support.
44   // type is known only to this driver's user and kernel
45   // classes. It could be used, for example, to define
46   // read or write privileges. In this case, we look for
47   // a private value.
48    if (type != kIrDAUserClientCookie) {        // some magic cookie
49	ioReturn = -1;
50	ELG(0, 0, 'irda', "bad magic cookie");
51    }
52    else {
53       // Construct a new client instance for the requesting task.
54       // This is, essentially  client = new IrDAUserClient;
55       //                               ... create metaclasses ...
56       //                               client->setTask(owningTask)
57	client = IrDAUserClient::withTask(owningTask);
58	if (client == NULL) {
59	    ioReturn = -2;
60	    ELG(0, 0, 'irda', "Can not create user client");
61	}
62    }
63    if (ioReturn == kIOReturnSuccess) {
64       // Attach client to our nub.
65	if (client->attach(fNub) == false) {
66	    ioReturn = -3;
67	    ELG(0, 0, 'irda', "Can not attach user client");
68	}
69    }
70    if (ioReturn == kIOReturnSuccess) {
71       // Start the client so it can accept requests.
72	if (client->start(fNub) == false) {
73	    ioReturn = -4;
74	    ELG(0, 0, 'irda', "Can not start user client");
75	}
76    }
77    if (ioReturn != kIOReturnSuccess && client != NULL) {
78	client->detach(fNub);
79	client->release();
80    }
81    *handler = client;
82    return (ioReturn);
83}
84