00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <CoreFoundation/CoreFoundation.h>
00016 #include <CoreFoundation/CFPlugInCOM.h>
00017 #include <CoreServices/CoreServices.h>
00018
00019
00020
00021
00022
00023
00024 #define PLUGIN_ID "57D03001-2009-43F0-BB98-1BECC352D3AC"
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 Boolean GetMetadataForFile(void *thisInterface,
00040 CFMutableDictionaryRef attributes,
00041 CFStringRef contentTypeUTI,
00042 CFStringRef pathToFile);
00043
00044
00045 typedef struct __MetadataImporterPluginType
00046 {
00047 MDImporterInterfaceStruct *conduitInterface;
00048 CFUUIDRef factoryID;
00049 UInt32 refCount;
00050 } MetadataImporterPluginType;
00051
00052
00053
00054
00055
00056
00057
00058 MetadataImporterPluginType *AllocMetadataImporterPluginType(CFUUIDRef inFactoryID);
00059 void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance);
00060 HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv);
00061 void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID);
00062 ULONG MetadataImporterPluginAddRef(void *thisInstance);
00063 ULONG MetadataImporterPluginRelease(void *thisInstance);
00064
00065
00066
00067
00068
00069
00070 static MDImporterInterfaceStruct testInterfaceFtbl = {
00071 NULL,
00072 MetadataImporterQueryInterface,
00073 MetadataImporterPluginAddRef,
00074 MetadataImporterPluginRelease,
00075 GetMetadataForFile
00076 };
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 MetadataImporterPluginType *AllocMetadataImporterPluginType(CFUUIDRef inFactoryID)
00087 {
00088 MetadataImporterPluginType *theNewInstance;
00089
00090 theNewInstance = (MetadataImporterPluginType *)malloc(sizeof(MetadataImporterPluginType));
00091 memset(theNewInstance,0,sizeof(MetadataImporterPluginType));
00092
00093
00094 theNewInstance->conduitInterface = &testInterfaceFtbl;
00095
00096
00097 theNewInstance->factoryID = CFRetain(inFactoryID);
00098 CFPlugInAddInstanceForFactory(inFactoryID);
00099
00100
00101 theNewInstance->refCount = 1;
00102 return theNewInstance;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance)
00114 {
00115 CFUUIDRef theFactoryID;
00116
00117 theFactoryID = thisInstance->factoryID;
00118 free(thisInstance);
00119 if (theFactoryID){
00120 CFPlugInRemoveInstanceForFactory(theFactoryID);
00121 CFRelease(theFactoryID);
00122 }
00123 }
00124
00125
00126
00127
00128
00129
00130 HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv)
00131 {
00132 CFUUIDRef interfaceID;
00133
00134 interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid);
00135
00136 if (CFEqual(interfaceID,kMDImporterInterfaceID)){
00137
00138
00139
00140
00141 ((MetadataImporterPluginType*)thisInstance)->conduitInterface->AddRef(thisInstance);
00142 *ppv = thisInstance;
00143 CFRelease(interfaceID);
00144 return S_OK;
00145 }else{
00146 if (CFEqual(interfaceID,IUnknownUUID)){
00147
00148 ((MetadataImporterPluginType*)thisInstance )->conduitInterface->AddRef(thisInstance);
00149 *ppv = thisInstance;
00150 CFRelease(interfaceID);
00151 return S_OK;
00152 }else{
00153
00154 *ppv = NULL;
00155 CFRelease(interfaceID);
00156 return E_NOINTERFACE;
00157 }
00158 }
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168 ULONG MetadataImporterPluginAddRef(void *thisInstance)
00169 {
00170 ((MetadataImporterPluginType *)thisInstance )->refCount += 1;
00171 return ((MetadataImporterPluginType*) thisInstance)->refCount;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 ULONG MetadataImporterPluginRelease(void *thisInstance)
00181 {
00182 ((MetadataImporterPluginType*)thisInstance)->refCount -= 1;
00183 if (((MetadataImporterPluginType*)thisInstance)->refCount == 0){
00184 DeallocMetadataImporterPluginType((MetadataImporterPluginType*)thisInstance );
00185 return 0;
00186 }else{
00187 return ((MetadataImporterPluginType*) thisInstance )->refCount;
00188 }
00189 }
00190
00191
00192
00193
00194
00195
00196 void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID)
00197 {
00198 MetadataImporterPluginType *result;
00199 CFUUIDRef uuid;
00200
00201
00202
00203
00204 if (CFEqual(typeID,kMDImporterTypeID)){
00205 uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID));
00206 result = AllocMetadataImporterPluginType(uuid);
00207 CFRelease(uuid);
00208 return result;
00209 }
00210
00211 return NULL;
00212 }
00213