Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDUserClient.cpp, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      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.
                     11:  * 
                     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
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: /*
                     23:  * Copyright (c) 1998 Apple Computer, Inc.  All rights reserved. 
                     24:  *
                     25:  * HISTORY
                     26:  *
                     27:  */
                     28: 
                     29: 
                     30: #include <IOKit/IOLib.h>
                     31: #include <libkern/c++/OSContainers.h>
                     32: 
                     33: #include "IOHIDUserClient.h"
                     34: 
                     35: 
                     36: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                     37: 
                     38: #undef super
                     39: #define super IOUserClient
                     40: 
                     41: OSDefineMetaClassAndStructors(IOHIDUserClient, IOUserClient)
                     42: 
                     43: OSDefineMetaClassAndStructors(IOHIDParamUserClient, IOUserClient)
                     44: 
                     45: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                     46: 
                     47: bool IOHIDUserClient::start( IOService * _owner )
                     48: {
                     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 }
                     56:     };
                     57: 
                     58:     if( !super::start( _owner ))
                     59:        return( false);
                     60: 
                     61:     owner = (IOHIDSystem *) _owner;
                     62: 
                     63:     bcopy( methodTemplate, externals, sizeof( methodTemplate ));
                     64: 
                     65:     externals[0].object = owner;
                     66:     externals[0].func = (IOMethod) &IOHIDSystem::createShmem;
                     67: 
                     68:     externals[1].object = owner;
                     69:     externals[1].func = (IOMethod) &IOHIDSystem::setEventsEnable;
                     70: 
                     71:     externals[2].object = owner;
                     72:     externals[2].func = (IOMethod) &IOHIDSystem::setCursorEnable;
                     73: 
                     74:     externals[3].object = owner;
                     75:     externals[3].func = (IOMethod) &IOHIDSystem::extPostEvent;
                     76: 
                     77:     externals[4].object = owner;
                     78:     externals[4].func = (IOMethod) &IOHIDSystem::extSetMouseLocation;
                     79: 
                     80:     externals[5].object = owner;
                     81:     externals[5].func = (IOMethod) &IOHIDSystem::extGetButtonEventNum;
                     82: 
                     83:     return( true );
                     84: }
                     85: 
                     86: IOReturn IOHIDUserClient::clientClose( void )
                     87: {
                     88:     owner->evClose();
                     89: #ifdef DEBUG
                     90:     kprintf("%s: client token invalidated\n", getName());
                     91: #endif
                     92: 
                     93:     owner->serverConnect = 0;
                     94:     detach( owner);
                     95: 
                     96:     return( kIOReturnSuccess);
                     97: }
                     98: 
                     99: IOService * IOHIDUserClient::getService( void )
                    100: {
                    101:     return( owner );
                    102: }
                    103: 
                    104: IOReturn IOHIDUserClient::registerNotificationPort(
                    105:                mach_port_t     port,
                    106:                UInt32          type,
                    107:                UInt32          refCon )
                    108: {
                    109:     if( type != kIOHIDEventNotification)
                    110:        return( kIOReturnUnsupported);
                    111: 
                    112:     owner->setEventPort(port);
                    113:     return( kIOReturnSuccess);
                    114: }
                    115: 
                    116: IOReturn IOHIDUserClient::connectClient( IOUserClient * client )
                    117: {
                    118:     Bounds *           bounds;
                    119:     IOGraphicsDevice * graphicsDevice;
                    120: 
                    121:     // yikes
                    122:     if( 0 == (graphicsDevice = OSDynamicCast(IOGraphicsDevice,
                    123:                                                client->getProvider())) )
                    124:        return( kIOReturnBadArgument );
                    125: 
                    126:     graphicsDevice->getBoundingRect(&bounds);
                    127: 
                    128:     owner->registerScreen(graphicsDevice, bounds);
                    129: 
                    130:     return( kIOReturnSuccess);
                    131: }
                    132: 
                    133: IOReturn IOHIDUserClient::clientMemoryForType( UInt32 type,
                    134:         UInt32 * flags, IOMemoryDescriptor ** memory )
                    135: {
                    136: 
                    137:     if( type != kIOHIDGlobalMemory)
                    138:        return( kIOReturnBadArgument);
                    139: 
                    140:     *flags = 0;
                    141:     owner->globalMemory->retain();
                    142:     *memory = owner->globalMemory;
                    143: 
                    144:     return( kIOReturnSuccess);
                    145: }
                    146: 
                    147: IOExternalMethod * IOHIDUserClient::getExternalMethodForIndex( UInt32 index )
                    148: {
                    149:     if( index < (sizeof( externals) / sizeof( externals[0])))
                    150:        return( externals + index);
                    151:     else
                    152:        return( NULL);
                    153: }
                    154: 
                    155: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                    156: 
                    157: bool IOHIDParamUserClient::start( IOService * _owner )
                    158: {
                    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 },
                    165:     };
                    166: 
                    167:     if( !super::start( _owner ))
                    168:        return( false);
                    169: 
                    170:     owner = (IOHIDSystem *) _owner;
                    171: 
                    172:     bcopy( methodTemplate, externals, sizeof( methodTemplate ));
                    173: 
                    174:     externals[3].object = owner;
                    175:     externals[3].func = (IOMethod) &IOHIDSystem::extPostEvent;
                    176: 
                    177:     externals[4].object = owner;
                    178:     externals[4].func = (IOMethod) &IOHIDSystem::extSetMouseLocation;
                    179: 
                    180:     return( true );
                    181: }
                    182: 
                    183: void IOHIDParamUserClient::free( void )
                    184: {
                    185:     retain(); retain();
                    186:     owner->paramConnect = 0;
                    187:     detach( owner);
                    188:     super::free();
                    189: }
                    190: 
                    191: void IOHIDParamUserClient::release() const
                    192: {
                    193:     super::release(2);
                    194: }
                    195: 
                    196: 
                    197: IOReturn IOHIDParamUserClient::clientClose( void )
                    198: {
                    199:     return( kIOReturnSuccess);
                    200: }
                    201: 
                    202: IOService * IOHIDParamUserClient::getService( void )
                    203: {
                    204:     return( owner );
                    205: }
                    206: 
                    207: IOExternalMethod * IOHIDParamUserClient::getExternalMethodForIndex(
                    208:                                                UInt32 index )
                    209: {
                    210:     // get the same library function to work for param & server connects
                    211:     if( (index >= 3)
                    212:      && (index < (sizeof( externals) / sizeof( externals[0]))))
                    213:        return( externals + index);
                    214:     else
                    215:        return( NULL);
                    216: }
                    217: 
                    218: IOReturn IOHIDParamUserClient::setProperties( OSObject * properties )
                    219: {
                    220:     OSDictionary *     dict;
                    221:     OSIterator *       iter;
                    222:     IOHIDevice *       eventSrc;
                    223:     IOReturn           err = kIOReturnSuccess;
                    224:     IOReturn           ret;
                    225: 
                    226:     dict = OSDynamicCast( OSDictionary, properties );
                    227:     if( dict) {
                    228:         ret = owner->setParamProperties( dict );
                    229:         if( (ret != kIOReturnSuccess) && (ret != kIOReturnBadArgument))
                    230:             err = ret;
                    231:         iter = owner->getOpenProviderIterator();
                    232: 
                    233:         if( iter) {
                    234:             while( (eventSrc = (IOHIDevice *) iter->getNextObject())) {
                    235:                 ret = eventSrc->setParamProperties( dict );
                    236:                 if( (ret != kIOReturnSuccess) && (ret != kIOReturnBadArgument))
                    237:                     err = ret;
                    238:             }
                    239:             iter->release();
                    240:         }
                    241:     } else
                    242:        err = kIOReturnBadArgument;
                    243: 
                    244:     return( err );
                    245: }
                    246: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.