2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
30 #include <IOKit/IOLib.h>
31 #include <libkern/c++/OSContainers.h>
33 #include "IOHIDUserClient.h"
36 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
39 #define super IOUserClient
41 OSDefineMetaClassAndStructors(IOHIDUserClient
, IOUserClient
)
43 OSDefineMetaClassAndStructors(IOHIDParamUserClient
, IOUserClient
)
45 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
47 bool IOHIDUserClient::start( IOService
* _owner
)
49 static const IOExternalMethod methodTemplate
[] = {
50 /* 0 */ { NULL
, NULL
, kIOUCScalarIScalarO
, 1, 0 },
51 /* 1 */ { NULL
, NULL
, kIOUCScalarIScalarO
, 1, 0 },
52 /* 2 */ { NULL
, NULL
, kIOUCScalarIScalarO
, 1, 0 },
53 /* 3 */ { NULL
, NULL
, kIOUCStructIStructO
, sizeof(struct evioLLEvent
), 0 },
54 /* 4 */ { NULL
, NULL
, kIOUCStructIStructO
, sizeof(Point
), 0 },
55 /* 5 */ { NULL
, NULL
, kIOUCScalarIScalarO
, 1, 1 }
58 if( !super::start( _owner
))
61 owner
= (IOHIDSystem
*) _owner
;
63 bcopy( methodTemplate
, externals
, sizeof( methodTemplate
));
65 externals
[0].object
= owner
;
66 externals
[0].func
= (IOMethod
) &IOHIDSystem::createShmem
;
68 externals
[1].object
= owner
;
69 externals
[1].func
= (IOMethod
) &IOHIDSystem::setEventsEnable
;
71 externals
[2].object
= owner
;
72 externals
[2].func
= (IOMethod
) &IOHIDSystem::setCursorEnable
;
74 externals
[3].object
= owner
;
75 externals
[3].func
= (IOMethod
) &IOHIDSystem::extPostEvent
;
77 externals
[4].object
= owner
;
78 externals
[4].func
= (IOMethod
) &IOHIDSystem::extSetMouseLocation
;
80 externals
[5].object
= owner
;
81 externals
[5].func
= (IOMethod
) &IOHIDSystem::extGetButtonEventNum
;
86 IOReturn
IOHIDUserClient::clientClose( void )
90 kprintf("%s: client token invalidated\n", getName());
93 owner
->serverConnect
= 0;
96 return( kIOReturnSuccess
);
99 IOService
* IOHIDUserClient::getService( void )
104 IOReturn
IOHIDUserClient::registerNotificationPort(
109 if( type
!= kIOHIDEventNotification
)
110 return( kIOReturnUnsupported
);
112 owner
->setEventPort(port
);
113 return( kIOReturnSuccess
);
116 IOReturn
IOHIDUserClient::connectClient( IOUserClient
* client
)
119 IOGraphicsDevice
* graphicsDevice
;
122 if( 0 == (graphicsDevice
= OSDynamicCast(IOGraphicsDevice
,
123 client
->getProvider())) )
124 return( kIOReturnBadArgument
);
126 graphicsDevice
->getBoundingRect(&bounds
);
128 owner
->registerScreen(graphicsDevice
, bounds
);
130 return( kIOReturnSuccess
);
133 IOReturn
IOHIDUserClient::clientMemoryForType( UInt32 type
,
134 UInt32
* flags
, IOMemoryDescriptor
** memory
)
137 if( type
!= kIOHIDGlobalMemory
)
138 return( kIOReturnBadArgument
);
141 owner
->globalMemory
->retain();
142 *memory
= owner
->globalMemory
;
144 return( kIOReturnSuccess
);
147 IOExternalMethod
* IOHIDUserClient::getExternalMethodForIndex( UInt32 index
)
149 if( index
< (sizeof( externals
) / sizeof( externals
[0])))
150 return( externals
+ index
);
155 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
157 bool IOHIDParamUserClient::start( IOService
* _owner
)
159 static const IOExternalMethod methodTemplate
[] = {
160 /* 0 */ { NULL
, NULL
, kIOUCScalarIScalarO
, 1, 0 },
161 /* 1 */ { NULL
, NULL
, kIOUCScalarIScalarO
, 1, 0 },
162 /* 2 */ { NULL
, NULL
, kIOUCScalarIScalarO
, 1, 0 },
163 /* 3 */ { NULL
, NULL
, kIOUCStructIStructO
, sizeof(struct evioLLEvent
), 0 },
164 /* 4 */ { NULL
, NULL
, kIOUCStructIStructO
, sizeof(Point
), 0 },
167 if( !super::start( _owner
))
170 owner
= (IOHIDSystem
*) _owner
;
172 bcopy( methodTemplate
, externals
, sizeof( methodTemplate
));
174 externals
[3].object
= owner
;
175 externals
[3].func
= (IOMethod
) &IOHIDSystem::extPostEvent
;
177 externals
[4].object
= owner
;
178 externals
[4].func
= (IOMethod
) &IOHIDSystem::extSetMouseLocation
;
183 void IOHIDParamUserClient::free( void )
186 owner
->paramConnect
= 0;
191 void IOHIDParamUserClient::release() const
197 IOReturn
IOHIDParamUserClient::clientClose( void )
199 return( kIOReturnSuccess
);
202 IOService
* IOHIDParamUserClient::getService( void )
207 IOExternalMethod
* IOHIDParamUserClient::getExternalMethodForIndex(
210 // get the same library function to work for param & server connects
212 && (index
< (sizeof( externals
) / sizeof( externals
[0]))))
213 return( externals
+ index
);
218 IOReturn
IOHIDParamUserClient::setProperties( OSObject
* properties
)
222 IOHIDevice
* eventSrc
;
223 IOReturn err
= kIOReturnSuccess
;
226 dict
= OSDynamicCast( OSDictionary
, properties
);
228 ret
= owner
->setParamProperties( dict
);
229 if( (ret
!= kIOReturnSuccess
) && (ret
!= kIOReturnBadArgument
))
231 iter
= owner
->getOpenProviderIterator();
234 while( (eventSrc
= (IOHIDevice
*) iter
->getNextObject())) {
235 ret
= eventSrc
->setParamProperties( dict
);
236 if( (ret
!= kIOReturnSuccess
) && (ret
!= kIOReturnBadArgument
))
242 err
= kIOReturnBadArgument
;