static void _registerFactory(const void *key, const void *val, void *context) { CFStringRef factoryIDStr = (CFStringRef)key; CFStringRef factoryFuncStr = (CFStringRef)val; CFBundleRef bundle = (CFBundleRef)context; CFUUIDRef factoryID = (CFGetTypeID(factoryIDStr) == CFStringGetTypeID()) ? CFUUIDCreateFromString(kCFAllocatorSystemDefault, factoryIDStr) : NULL; if (!factoryID) factoryID = (CFUUIDRef)CFRetain(factoryIDStr); if (CFGetTypeID(factoryFuncStr) != CFStringGetTypeID() || CFStringGetLength(factoryFuncStr) <= 0) factoryFuncStr = NULL; CFPlugInRegisterFactoryFunctionByName(factoryID, bundle, factoryFuncStr); if (factoryID) CFRelease(factoryID); }
static void _IOGetWithUUIDKey(const void *key, const void * value, void *ctx) { LookUUIDContext * context = (LookUUIDContext *) ctx; CFUUIDRef uuid; uuid = CFUUIDCreateFromString(NULL, (CFStringRef)key); if( uuid) { if( CFEqual( uuid, context->key)) context->result = value; CFRelease(uuid); } }
/* ============================================================================= Name: PrintDialogPDEPluginFactory() Description: This is the factory function which should be the only entry point of this plugin. This factory function creates the "base class" for the system. The factory functions name (ie "PrintDialogPDEPluginFactory") needs to be listed in the Info.plist to associate the factory function name with the factory function UUID. For example, this is how this function is associated with the UUID in the Info.plist file. CFPlugInFactories = { "DFC01D58-0C4A-11D5-BB77-003065500EB8" = "PrintDialogPDEPluginFactory"; }; Input Parameters: allocator - the allocator function used by CoreFoundation reqTypeID - requested instance type. Output Parameters: None. Return Value: * ========================================================================== */ void* PrintDialogPDEPluginFactory( CFAllocatorRef allocator, CFUUIDRef reqTypeID ) { CFUUIDRef myInstID; IUnknownInstance* instance = NULL; // There is not much we can do with errors - just return NULL. myInstID = CFUUIDCreateFromString(kCFAllocatorDefault, kAppPrintDialogTypeIDStr); // If the requested type matches our plugin type (it should!) // have a plugin instance created which will query us for // interfaces: if (myInstID && CFEqual(reqTypeID, myInstID)) { CFUUIDRef myFactoryID = CFUUIDCreateFromString(kCFAllocatorDefault, kPrintDialogPDEIntfFactoryIDStr); if(myFactoryID) { // allocate and clear our instance structure instance = (IUnknownInstance*) calloc(1, sizeof(IUnknownInstance)); if (instance != NULL) { // Assign all members: instance->vtable = &instance->vtableStorage; instance->vtableStorage.QueryInterface = IUnknownQueryInterface; instance->vtableStorage.AddRef = IUnknownAddRef; instance->vtableStorage.Release = IUnknownRelease; instance->factoryID = myFactoryID; instance->refCount = 1; // Register the newly created instance CFPlugInAddInstanceForFactory(myFactoryID); } } } if(myInstID) CFRelease(myInstID); return ((void*) instance); }
static HRESULT IUnknownQueryInterface( void* obj, REFIID iID, LPVOID* intfPtr ) { IUnknownInstance* instance = (IUnknownInstance*) obj; CFUUIDRef myIntfID = NULL, reqIntfID = NULL; HRESULT err = E_UNEXPECTED; PlugInIntf* interface; // Get IDs for requested and PDE interfaces: reqIntfID = CFUUIDCreateFromUUIDBytes( kCFAllocatorDefault, iID ); myIntfID = CFUUIDCreateFromString( kCFAllocatorDefault, kDialogExtensionIntfIDStr ); if(reqIntfID && myIntfID){ // If we are asked to return the interface for // the IUnknown vtable, which the system already has access to, // just increment the refcount value if(CFEqual( reqIntfID, IUnknownUUID ) ) { instance->vtable->AddRef( (void*) instance ); *intfPtr = (LPVOID) instance; err = S_OK; } else if (CFEqual(reqIntfID, myIntfID)) // if we are asked for the PDEs interface, { // lets make one and return it. err = MyCreatePlugInInterface( &interface ); if ( noErr == err ) { *intfPtr = (LPVOID) interface; err = S_OK; }else{ *intfPtr = NULL; err = E_NOINTERFACE; } } else // we will return the err = E_NOINTERFACE and a *intfPtr of NULL; { *intfPtr = NULL; err = E_NOINTERFACE; } }else{ // we will return the err = E_NOINTERFACE and a *intfPtr of NULL; *intfPtr = NULL; err = E_NOINTERFACE; } // Clean up and return status: if(reqIntfID)CFRelease( reqIntfID ); if(myIntfID)CFRelease( myIntfID ); return( err ); }
static void _registerType(const void *key, const void *val, void *context) { CFStringRef typeIDStr = (CFStringRef)key; CFArrayRef factoryIDStrArray = (CFArrayRef)val; CFBundleRef bundle = (CFBundleRef)context; SInt32 i, c = (CFGetTypeID(factoryIDStrArray) == CFArrayGetTypeID()) ? CFArrayGetCount(factoryIDStrArray) : 0; CFStringRef curFactoryIDStr; CFUUIDRef typeID = (CFGetTypeID(typeIDStr) == CFStringGetTypeID()) ? CFUUIDCreateFromString(kCFAllocatorSystemDefault, typeIDStr) : NULL; CFUUIDRef curFactoryID; if (!typeID) typeID = (CFUUIDRef)CFRetain(typeIDStr); if (0 == c && CFGetTypeID(factoryIDStrArray) != CFArrayGetTypeID()) { curFactoryIDStr = (CFStringRef)val; curFactoryID = (CFGetTypeID(curFactoryIDStr) == CFStringGetTypeID()) ? CFUUIDCreateFromString(CFGetAllocator(bundle), curFactoryIDStr) : NULL; if (!curFactoryID) curFactoryID = (CFUUIDRef)CFRetain(curFactoryIDStr); CFPlugInRegisterPlugInType(curFactoryID, typeID); if (curFactoryID) CFRelease(curFactoryID); } else for (i = 0; i < c; i++) { curFactoryIDStr = (CFStringRef)CFArrayGetValueAtIndex(factoryIDStrArray, i); curFactoryID = (CFGetTypeID(curFactoryIDStr) == CFStringGetTypeID()) ? CFUUIDCreateFromString(CFGetAllocator(bundle), curFactoryIDStr) : NULL; if (!curFactoryID) curFactoryID = (CFUUIDRef)CFRetain(curFactoryIDStr); CFPlugInRegisterPlugInType(curFactoryID, typeID); if (curFactoryID) CFRelease(curFactoryID); } if (typeID) CFRelease(typeID); }
// ----------------------------------------------------------------------------- // QuickLookGeneratorPluginFactory // ----------------------------------------------------------------------------- void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) { QuickLookGeneratorPluginType *result; CFUUIDRef uuid; /* If correct type is being requested, allocate an * instance of kQLGeneratorTypeID and return the IUnknown interface. */ if (CFEqual(typeID,kQLGeneratorTypeID)) { uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID)); result = AllocQuickLookGeneratorPluginType(uuid); CFRelease(uuid); return result; } /* If the requested type is incorrect, return NULL. */ return NULL; }
// ----------------------------------------------------------------------------- // FLACMDImporterPluginFactory // ----------------------------------------------------------------------------- // Implementation of the factory function for this type. // void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) { #pragma unused(allocator) MetadataImporterPluginType *result; CFUUIDRef uuid; /* If correct type is being requested, allocate an * instance of TestType and return the IUnknown interface. */ if (CFEqual(typeID,kMDImporterTypeID)) { uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID)); result = AllocMetadataImporterPluginType(uuid); CFRelease(uuid); return result; } /* If the requested type is incorrect, return NULL. */ return NULL; }