Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1//
2// main.c
3// Oolite-importer
4//
5// Created by Jens Ayton on 2005-10-22.
6//
7
8
9
10
11
12//==============================================================================
13//
14// DO NO MODIFY THE CONTENT OF THIS FILE
15//
16// This file contains the generic CFPlug-in code necessary for your importer
17// To complete your importer implement the function in GetMetadataForFile.c
18//
19//==============================================================================
20
21
22
23
24
25
26#include <CoreFoundation/CoreFoundation.h>
27#include <CoreFoundation/CFPlugInCOM.h>
28#include <CoreServices/CoreServices.h>
29
30// -----------------------------------------------------------------------------
31// constants
32// -----------------------------------------------------------------------------
33
34
35#define PLUGIN_ID "44E7EDBD-F1D0-4031-9E99-D272D8166D11"
36
37//
38// Below is the generic glue code for all plug-ins.
39//
40// You should not have to modify this code aside from changing
41// names if you decide to change the names defined in the Info.plist
42//
43
44
45// -----------------------------------------------------------------------------
46// typedefs
47// -----------------------------------------------------------------------------
48
49// The import function to be implemented in GetMetadataForFile.c
50Boolean GetMetadataForFile(void *thisInterface,
51 CFMutableDictionaryRef attributes,
52 CFStringRef contentTypeUTI,
53 CFStringRef pathToFile);
54
55// The layout for an instance of MetaDataImporterPlugIn
57{
58 MDImporterInterfaceStruct *conduitInterface;
59 CFUUIDRef factoryID;
60 UInt32 refCount;
62
63// -----------------------------------------------------------------------------
64// prototypes
65// -----------------------------------------------------------------------------
66// Forward declaration for the IUnknown implementation.
67//
68
71HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv);
72void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID);
73ULONG MetadataImporterPluginAddRef(void *thisInstance);
74ULONG MetadataImporterPluginRelease(void *thisInstance);
75// -----------------------------------------------------------------------------
76// testInterfaceFtbl definition
77// -----------------------------------------------------------------------------
78// The TestInterface function table.
79//
80
88
89
90// -----------------------------------------------------------------------------
91// AllocMetadataImporterPluginType
92// -----------------------------------------------------------------------------
93// Utility function that allocates a new instance.
94// You can do some initial setup for the importer here if you wish
95// like allocating globals etc...
96//
98{
99 MetadataImporterPluginType *theNewInstance;
100
101 theNewInstance = (MetadataImporterPluginType *)malloc(sizeof(MetadataImporterPluginType));
102 memset(theNewInstance,0,sizeof(MetadataImporterPluginType));
103
104 /* Point to the function table */
105 theNewInstance->conduitInterface = &testInterfaceFtbl;
106
107 /* Retain and keep an open instance refcount for each factory. */
108 theNewInstance->factoryID = CFRetain(inFactoryID);
109 CFPlugInAddInstanceForFactory(inFactoryID);
110
111 /* This function returns the IUnknown interface so set the refCount to one. */
112 theNewInstance->refCount = 1;
113 return theNewInstance;
114}
115
116// -----------------------------------------------------------------------------
117// DeallocOolite_importerMDImporterPluginType
118// -----------------------------------------------------------------------------
119// Utility function that deallocates the instance when
120// the refCount goes to zero.
121// In the current implementation importer interfaces are never deallocated
122// but implement this as this might change in the future
123//
125{
126 CFUUIDRef theFactoryID;
127
128 theFactoryID = thisInstance->factoryID;
129 free(thisInstance);
130 if (theFactoryID){
131 CFPlugInRemoveInstanceForFactory(theFactoryID);
132 CFRelease(theFactoryID);
133 }
134}
135
136// -----------------------------------------------------------------------------
137// MetadataImporterQueryInterface
138// -----------------------------------------------------------------------------
139// Implementation of the IUnknown QueryInterface function.
140//
141HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv)
142{
143 CFUUIDRef interfaceID;
144
145 interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid);
146
147 if (CFEqual(interfaceID,kMDImporterInterfaceID)){
148 /* If the Right interface was requested, bump the ref count,
149 * set the ppv parameter equal to the instance, and
150 * return good status.
151 */
152 ((MetadataImporterPluginType*)thisInstance)->conduitInterface->AddRef(thisInstance);
153 *ppv = thisInstance;
154 CFRelease(interfaceID);
155 return S_OK;
156 }else{
157 if (CFEqual(interfaceID,IUnknownUUID)){
158 /* If the IUnknown interface was requested, same as above. */
159 ((MetadataImporterPluginType*)thisInstance )->conduitInterface->AddRef(thisInstance);
160 *ppv = thisInstance;
161 CFRelease(interfaceID);
162 return S_OK;
163 }else{
164 /* Requested interface unknown, bail with error. */
165 *ppv = NULL;
166 CFRelease(interfaceID);
167 return E_NOINTERFACE;
168 }
169 }
170}
171
172// -----------------------------------------------------------------------------
173// MetadataImporterPluginAddRef
174// -----------------------------------------------------------------------------
175// Implementation of reference counting for this type. Whenever an interface
176// is requested, bump the refCount for the instance. NOTE: returning the
177// refcount is a convention but is not required so don't rely on it.
178//
179ULONG MetadataImporterPluginAddRef(void *thisInstance)
180{
181 ((MetadataImporterPluginType *)thisInstance )->refCount += 1;
182 return ((MetadataImporterPluginType*) thisInstance)->refCount;
183}
184
185// -----------------------------------------------------------------------------
186// SampleCMPluginRelease
187// -----------------------------------------------------------------------------
188// When an interface is released, decrement the refCount.
189// If the refCount goes to zero, deallocate the instance.
190//
191ULONG MetadataImporterPluginRelease(void *thisInstance)
192{
193 ((MetadataImporterPluginType*)thisInstance)->refCount -= 1;
194 if (((MetadataImporterPluginType*)thisInstance)->refCount == 0){
196 return 0;
197 }else{
198 return ((MetadataImporterPluginType*) thisInstance )->refCount;
199 }
200}
201
202// -----------------------------------------------------------------------------
203// Oolite_importerMDImporterPluginFactory
204// -----------------------------------------------------------------------------
205// Implementation of the factory function for this type.
206//
207__attribute__((visibility("default")))
208void *MetadataImporterPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID)
209{
211 CFUUIDRef uuid;
212
213 /* If correct type is being requested, allocate an
214 * instance of TestType and return the IUnknown interface.
215 */
216 if (CFEqual(typeID,kMDImporterTypeID)){
217 uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID));
218 result = AllocMetadataImporterPluginType(uuid);
219 CFRelease(uuid);
220 return result;
221 }
222 /* If the requested type is incorrect, return NULL. */
223 return NULL;
224}
225
void * MetadataImporterPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID)
void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance)
Definition main.c:124
MetadataImporterPluginType * AllocMetadataImporterPluginType(CFUUIDRef inFactoryID)
Definition main.c:97
Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attributes, CFStringRef contentTypeUTI, CFStringRef pathToFile)
static MDImporterInterfaceStruct testInterfaceFtbl
Definition main.c:81
struct __MetadataImporterPluginType MetadataImporterPluginType
ULONG MetadataImporterPluginRelease(void *thisInstance)
Definition main.c:191
#define PLUGIN_ID
Definition main.c:35
HRESULT MetadataImporterQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv)
Definition main.c:141
__attribute__((visibility("default")))
Definition main.c:207
ULONG MetadataImporterPluginAddRef(void *thisInstance)
Definition main.c:179
MDImporterInterfaceStruct * conduitInterface
Definition main.c:58