IOUSBUserClientInit.cpp [plain text]
#include <libkern/OSAtomic.h>
#include <libkern/c++/OSDictionary.h>
#include <IOKit/IOLib.h>
#include <IOKit/IOService.h>
#include <IOKit/usb/IOUSBDevice.h>
#include <IOKit/usb/IOUSBInterface.h>
#include <IOKit/usb/IOUSBUserClient.h>
OSDefineMetaClassAndStructors(IOUSBUserClientInit, IOService);
#define super IOService
bool
IOUSBUserClientInit::init(OSDictionary * propTable)
{
return super::init(propTable) ;
}
IOService*
IOUSBUserClientInit::probe(IOService* provider, SInt32* score)
{
return super::probe(provider, score) ;
}
bool
IOUSBUserClientInit::start(IOService* provider)
{
OSObject* dictObj = getProperty("IOProviderMergeProperties");
OSDictionary* providerMergeProperties = NULL;
providerMergeProperties = OSDynamicCast(OSDictionary, dictObj);
if ( !providerMergeProperties )
{
return false;
}
const OSSymbol* userClientClass;
OSObject* temp = providerMergeProperties->getObject( gIOUserClientClassKey ) ;
if ( OSDynamicCast(OSSymbol, temp) )
userClientClass = NULL; else if ( OSDynamicCast(OSString, temp) )
userClientClass = OSSymbol::withString((const OSString *) temp); else
{
userClientClass = NULL; providerMergeProperties->removeObject(gIOUserClientClassKey);
}
if (userClientClass)
providerMergeProperties->setObject(gIOUserClientClassKey, (OSObject *) userClientClass);
OSDictionary* providerProps = provider->getPropertyTable();
if (providerProps)
{
mergeProperties(providerProps, providerMergeProperties) ;
}
return true ;
}
void
IOUSBUserClientInit::stop(IOService* provider)
{
IOService::stop(provider) ;
}
void
IOUSBUserClientInit::mergeProperties(OSObject* inDest, OSObject* inSrc)
{
OSDictionary* dest = OSDynamicCast(OSDictionary, inDest) ;
OSDictionary* src = OSDynamicCast(OSDictionary, inSrc) ;
if (!src || !dest)
return ;
OSCollectionIterator* srcIterator = OSCollectionIterator::withCollection(src) ;
OSSymbol* keyObject = NULL ;
OSObject* destObject = NULL ;
while (NULL != (keyObject = OSDynamicCast(OSSymbol, srcIterator->getNextObject())))
{
if ((NULL != (destObject = dest->getObject(keyObject))) && (OSDynamicCast(OSDictionary,src->getObject(keyObject))))
{
mergeProperties(destObject, src->getObject(keyObject)) ;
}
else
{
dest->setObject(keyObject, src->getObject(keyObject)) ;
}
}
srcIterator->release();
}