| 1 |
#include <AvailabilityMacros.h> |
|---|
| 2 |
|
|---|
| 3 |
#include <CoreFoundation/CoreFoundation.h> |
|---|
| 4 |
#include <CoreFoundation/CFPlugInCOM.h> |
|---|
| 5 |
#include <CoreServices/CoreServices.h> |
|---|
| 6 |
|
|---|
| 7 |
#define PLUGIN_ID "BEB8A52D-7759-4331-9C3D-088295CF7E97" |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
Boolean GetMetadataForFile(void *thisInterface, |
|---|
| 12 |
CFMutableDictionaryRef attributes, |
|---|
| 13 |
CFStringRef contentTypeUTI, |
|---|
| 14 |
CFStringRef pathToFile); |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
typedef struct __MetadataImporterPluginType |
|---|
| 18 |
{ |
|---|
| 19 |
MDImporterInterfaceStruct *conduitInterface; |
|---|
| 20 |
CFUUIDRef factoryID; |
|---|
| 21 |
UInt32 refCount; |
|---|
| 22 |
} MetadataImporterPluginType; |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
MetadataImporterPluginType *AllocMetadataImporterPluginType(CFUUIDRef inFactoryID); |
|---|
| 26 |
void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance); |
|---|
| 27 |
HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv); |
|---|
| 28 |
void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID); |
|---|
| 29 |
ULONG MetadataImporterPluginAddRef(void *thisInstance); |
|---|
| 30 |
ULONG MetadataImporterPluginRelease(void *thisInstance); |
|---|
| 31 |
|
|---|
| 32 |
static MDImporterInterfaceStruct testInterfaceFtbl = { |
|---|
| 33 |
NULL, |
|---|
| 34 |
MetadataImporterQueryInterface, |
|---|
| 35 |
MetadataImporterPluginAddRef, |
|---|
| 36 |
MetadataImporterPluginRelease, |
|---|
| 37 |
GetMetadataForFile |
|---|
| 38 |
}; |
|---|
| 39 |
|
|---|
| 40 |
MetadataImporterPluginType *AllocMetadataImporterPluginType(CFUUIDRef inFactoryID) |
|---|
| 41 |
{ |
|---|
| 42 |
MetadataImporterPluginType *theNewInstance; |
|---|
| 43 |
|
|---|
| 44 |
theNewInstance = (MetadataImporterPluginType *)malloc(sizeof(MetadataImporterPluginType)); |
|---|
| 45 |
memset(theNewInstance,0,sizeof(MetadataImporterPluginType)); |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
theNewInstance->conduitInterface = &testInterfaceFtbl; |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
theNewInstance->factoryID = CFRetain(inFactoryID); |
|---|
| 52 |
CFPlugInAddInstanceForFactory(inFactoryID); |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
theNewInstance->refCount = 1; |
|---|
| 56 |
return theNewInstance; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance) |
|---|
| 60 |
{ |
|---|
| 61 |
CFUUIDRef theFactoryID; |
|---|
| 62 |
|
|---|
| 63 |
theFactoryID = thisInstance->factoryID; |
|---|
| 64 |
free(thisInstance); |
|---|
| 65 |
if (theFactoryID){ |
|---|
| 66 |
CFPlugInRemoveInstanceForFactory(theFactoryID); |
|---|
| 67 |
CFRelease(theFactoryID); |
|---|
| 68 |
} |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv) |
|---|
| 72 |
{ |
|---|
| 73 |
CFUUIDRef interfaceID; |
|---|
| 74 |
|
|---|
| 75 |
interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid); |
|---|
| 76 |
|
|---|
| 77 |
if (CFEqual(interfaceID,kMDImporterInterfaceID)){ |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
((MetadataImporterPluginType*)thisInstance)->conduitInterface->AddRef(thisInstance); |
|---|
| 83 |
*ppv = thisInstance; |
|---|
| 84 |
CFRelease(interfaceID); |
|---|
| 85 |
return S_OK; |
|---|
| 86 |
}else{ |
|---|
| 87 |
if (CFEqual(interfaceID,IUnknownUUID)){ |
|---|
| 88 |
|
|---|
| 89 |
((MetadataImporterPluginType*)thisInstance )->conduitInterface->AddRef(thisInstance); |
|---|
| 90 |
*ppv = thisInstance; |
|---|
| 91 |
CFRelease(interfaceID); |
|---|
| 92 |
return S_OK; |
|---|
| 93 |
}else{ |
|---|
| 94 |
|
|---|
| 95 |
*ppv = NULL; |
|---|
| 96 |
CFRelease(interfaceID); |
|---|
| 97 |
return E_NOINTERFACE; |
|---|
| 98 |
} |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
ULONG MetadataImporterPluginAddRef(void *thisInstance) |
|---|
| 103 |
{ |
|---|
| 104 |
((MetadataImporterPluginType *)thisInstance )->refCount += 1; |
|---|
| 105 |
return ((MetadataImporterPluginType*) thisInstance)->refCount; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
ULONG MetadataImporterPluginRelease(void *thisInstance) |
|---|
| 109 |
{ |
|---|
| 110 |
((MetadataImporterPluginType*)thisInstance)->refCount -= 1; |
|---|
| 111 |
if (((MetadataImporterPluginType*)thisInstance)->refCount == 0){ |
|---|
| 112 |
DeallocMetadataImporterPluginType((MetadataImporterPluginType*)thisInstance ); |
|---|
| 113 |
return 0; |
|---|
| 114 |
}else{ |
|---|
| 115 |
return ((MetadataImporterPluginType*) thisInstance )->refCount; |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID) |
|---|
| 120 |
{ |
|---|
| 121 |
MetadataImporterPluginType *result; |
|---|
| 122 |
CFUUIDRef uuid; |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
if (CFEqual(typeID,kMDImporterTypeID)){ |
|---|
| 128 |
uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID)); |
|---|
| 129 |
result = AllocMetadataImporterPluginType(uuid); |
|---|
| 130 |
CFRelease(uuid); |
|---|
| 131 |
return result; |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
return NULL; |
|---|
| 135 |
} |
|---|