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