static kern_return_t IOFindPlugIns( io_service_t service, CFUUIDRef pluginType, CFArrayRef * factories, CFArrayRef * plists ) { CFURLRef url; CFPlugInRef onePlugin; CFBundleRef bundle; CFDictionaryRef plist; CFDictionaryRef matching; CFDictionaryRef pluginTypes; CFMutableStringRef path; LookUUIDContext context; CFStringRef pluginName; boolean_t matches; kern_return_t kr = kIOReturnSuccess; // -- loadables onePlugin = NULL; pluginName = NULL; path = NULL; url = NULL; do { pluginTypes = IORegistryEntryCreateCFProperty( service, CFSTR(kIOCFPlugInTypesKey), kCFAllocatorDefault, kNilOptions ); if( !pluginTypes ) continue; // look up UUID key this way - otherwise string case matters // CFShow( pluginTypes ); context.key = pluginType; context.result = 0; CFDictionaryApplyFunction( pluginTypes, &_IOGetWithUUIDKey, &context); pluginName = (CFStringRef) context.result; if( !pluginName) continue; path = CFStringCreateMutable( kCFAllocatorDefault, 0 ); if( !path) continue; CFStringAppendCString(path, "/System/Library/Extensions/", kCFStringEncodingMacRoman); CFStringAppend(path, pluginName); url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, TRUE); if( !url) continue; onePlugin = CFPlugInCreate(NULL, url); } while( false ); // if (pluginName && (!onePlugin)) // printf("Could not create CFPluginRef.\n"); if( url) CFRelease( url ); if( path) CFRelease( path ); if( pluginTypes ) CFRelease( pluginTypes ); // -- if( onePlugin && (bundle = CFPlugInGetBundle(onePlugin)) && (plist = CFBundleGetInfoDictionary(bundle)) && (matching = (CFDictionaryRef) CFDictionaryGetValue(plist, CFSTR("Personality")))) { kr = IOServiceMatchPropertyTable( service, matching, &matches); if( kr != kIOReturnSuccess) matches = FALSE; } else matches = TRUE; if( matches) { if( onePlugin) *factories = CFPlugInFindFactoriesForPlugInTypeInPlugIn(pluginType, onePlugin); else *factories = 0;//CFPlugInFindFactoriesForPlugInType(pluginType); } else *factories = 0; *plists = 0; return( kr ); }
static CFPlugInRef MyLoadPlugIn( void ) { CFPlugInRef newPlugIn; CFURLRef bundleURL; CFURLRef plugInURL; Boolean foundInterface = false; // Obtain a URL to the PlugIns directory inside our application. bundleURL = CFBundleCopyBuiltInPlugInsURL( CFBundleGetMainBundle() ); // We just want to load our test plug-in, so append its name to the URL. plugInURL = CFURLCreateCopyAppendingPathComponent( NULL, bundleURL, CFSTR( kPlugInName ), FALSE ); // Create a CFPlugin using the URL. This step causes the plug-in's types and factories to // be registered with the system. Note that the plug-in's code is not actually loaded at // this stage unless the plug-in is using dynamic registration. newPlugIn = CFPlugInCreate( NULL, plugInURL ); CFRelease( bundleURL ); CFRelease( plugInURL ); // The plug-in was located. Now locate the interface. if( newPlugIn ) { CFArrayRef factories; // See if this plug-in implements the Test type. factories = CFPlugInFindFactoriesForPlugInTypeInPlugIn( kTestTypeID, newPlugIn ); // If there are factories for the Test type, attempt to get the IUnknown interface. if ( factories != NULL ) { CFIndex factoryCount; CFIndex index; factoryCount = CFArrayGetCount( factories ); if ( factoryCount > 0 ) { for ( index = 0 ; (index < factoryCount) && (foundInterface == false) ; index++ ) { CFUUIDRef factoryID; // Get the factory ID for the first location in the array of IDs. factoryID = (CFUUIDRef) CFArrayGetValueAtIndex( factories, index ); if ( factoryID ) { IUnknownVTbl **iunknown; // Use the factory ID to get an IUnknown interface. Here the plug-in code is loaded. iunknown = (IUnknownVTbl **) CFPlugInInstanceCreate( NULL, factoryID, kTestTypeID ); if ( iunknown ) { // If this is an IUnknown interface, query for the test interface. (*iunknown)->QueryInterface( iunknown, CFUUIDGetUUIDBytes( kTestInterfaceID ), (LPVOID *)( &gDrawBallInterface ) ); // Now we are done with IUnknown (*iunknown)->Release( iunknown ); if ( gDrawBallInterface ) { // We found the interface we need foundInterface = true; } } } } } } CFRelease( factories ); } if ( foundInterface == false ) { CFRelease( newPlugIn ); newPlugIn = NULL; } return( newPlugIn ); }