IOHIDUserClient.cpp [plain text]
#include <IOKit/IOLib.h>
#include <libkern/c++/OSContainers.h>
#include "IOHIDUserClient.h"
#include "IOHIDParameter.h"
#undef super
#define super IOUserClient
OSDefineMetaClassAndStructors(IOHIDUserClient, IOUserClient)
OSDefineMetaClassAndStructors(IOHIDParamUserClient, IOUserClient)
bool IOHIDUserClient::start( IOService * _owner )
{
if( !super::start( _owner ))
return( false);
owner = (IOHIDSystem *) _owner;
return( true );
}
IOReturn IOHIDUserClient::clientClose( void )
{
owner->evClose();
#ifdef DEBUG
kprintf("%s: client token invalidated\n", getName());
#endif
owner->serverConnect = 0;
detach( owner);
return( kIOReturnSuccess);
}
IOService * IOHIDUserClient::getService( void )
{
return( owner );
}
IOReturn IOHIDUserClient::registerNotificationPort(
mach_port_t port,
UInt32 type,
UInt32 refCon )
{
if( type != kIOHIDEventNotification)
return( kIOReturnUnsupported);
owner->setEventPort(port);
return( kIOReturnSuccess);
}
IOReturn IOHIDUserClient::connectClient( IOUserClient * client )
{
Bounds * bounds;
IOService * provider;
IOGraphicsDevice * graphicsDevice;
provider = client->getProvider();
if( !provider || !provider->metaCast("IOGraphicsDevice"))
return( kIOReturnBadArgument );
graphicsDevice = (IOGraphicsDevice *) provider;
graphicsDevice->getBoundingRect(&bounds);
owner->registerScreen(graphicsDevice, bounds);
return( kIOReturnSuccess);
}
IOReturn IOHIDUserClient::clientMemoryForType( UInt32 type,
UInt32 * flags, IOMemoryDescriptor ** memory )
{
if( type != kIOHIDGlobalMemory)
return( kIOReturnBadArgument);
*flags = 0;
if (owner->globalMemory)
owner->globalMemory->retain();
*memory = owner->globalMemory;
return( kIOReturnSuccess);
}
IOExternalMethod * IOHIDUserClient::getTargetAndMethodForIndex(
IOService ** targetP, UInt32 index )
{
static const IOExternalMethod methodTemplate[] = {
{ NULL, (IOMethod) &IOHIDSystem::createShmem,
kIOUCScalarIScalarO, 1, 0 },
{ NULL, (IOMethod) &IOHIDSystem::setEventsEnable,
kIOUCScalarIScalarO, 1, 0 },
{ NULL, (IOMethod) &IOHIDSystem::setCursorEnable,
kIOUCScalarIScalarO, 1, 0 },
{ NULL, (IOMethod) &IOHIDSystem::extPostEvent,
kIOUCStructIStructO, 0xffffffff, 0 },
{ NULL, (IOMethod) &IOHIDSystem::extSetMouseLocation,
kIOUCStructIStructO, 0xffffffff, 0 },
{ NULL, (IOMethod) &IOHIDSystem::extGetButtonEventNum,
kIOUCScalarIScalarO, 1, 1 },
{ NULL, (IOMethod) &IOHIDSystem::extSetBounds,
kIOUCStructIStructO, sizeof( IOGBounds), 0 },
};
if( index > (sizeof(methodTemplate) / sizeof(methodTemplate[0])))
return( NULL );
*targetP = owner;
return( (IOExternalMethod *)(methodTemplate + index) );
}
IOReturn IOHIDUserClient::setProperties( OSObject * properties )
{
OSDictionary * dict = OSDynamicCast(OSDictionary, properties);
if (dict && dict->getObject(kIOHIDUseKeyswitchKey) &&
( clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator) != kIOReturnSuccess))
{
dict->removeObject(kIOHIDUseKeyswitchKey);
}
return( owner->setProperties( properties ) );
}
bool IOHIDParamUserClient::start( IOService * _owner )
{
if( !super::start( _owner ))
return( false);
owner = (IOHIDSystem *) _owner;
return( true );
}
IOReturn IOHIDParamUserClient::clientClose( void )
{
return( kIOReturnSuccess);
}
IOService * IOHIDParamUserClient::getService( void )
{
return( owner );
}
IOExternalMethod * IOHIDParamUserClient::getTargetAndMethodForIndex(
IOService ** targetP, UInt32 index )
{
static const IOExternalMethod methodTemplate[] = {
{ NULL, NULL, kIOUCScalarIScalarO, 1, 0 },
{ NULL, NULL, kIOUCScalarIScalarO, 1, 0 },
{ NULL, NULL, kIOUCScalarIScalarO, 1, 0 },
{ NULL, (IOMethod) &IOHIDSystem::extPostEvent,
kIOUCStructIStructO, 0xffffffff, 0 },
{ NULL, (IOMethod) &IOHIDSystem::extSetMouseLocation,
kIOUCStructIStructO, 0xffffffff, 0 },
};
if( (index >= 3)
&& (index < (sizeof( methodTemplate) / sizeof( methodTemplate[0])))) {
*targetP = owner;
return( (IOExternalMethod *) methodTemplate + index);
} else
return( NULL);
}
IOReturn IOHIDParamUserClient::setProperties( OSObject * properties )
{
OSDictionary * dict = OSDynamicCast(OSDictionary, properties);
if (dict && dict->getObject(kIOHIDUseKeyswitchKey) &&
( clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator) != kIOReturnSuccess))
{
dict->removeObject(kIOHIDUseKeyswitchKey);
}
return( owner->setProperties( properties ) );
}