main.c

Go to the documentation of this file.
00001 //==============================================================================
00002 //
00003 //      DO NO MODIFY THE CONTENT OF THIS FILE
00004 //
00005 //      This file contains the generic CFPlug-in code necessary for your generator
00006 //      To complete your generator implement the function in GenerateThumbnailForURL/GeneratePreviewForURL.c
00007 //
00008 //==============================================================================
00009 
00010 
00011 
00012 
00013 
00014 
00015 #include <CoreFoundation/CoreFoundation.h>
00016 #include <CoreFoundation/CFPlugInCOM.h>
00017 #include <CoreServices/CoreServices.h>
00018 #include <QuickLook/QuickLook.h>
00019 
00020 // -----------------------------------------------------------------------------
00021 //      constants
00022 // -----------------------------------------------------------------------------
00023 
00024 // Don't modify this line
00025 #define PLUGIN_ID "9E28C44E-DE9B-4941-8963-405BD216DD9D"
00026 
00027 //
00028 // Below is the generic glue code for all plug-ins.
00029 //
00030 // You should not have to modify this code aside from changing
00031 // names if you decide to change the names defined in the Info.plist
00032 //
00033 
00034 
00035 // -----------------------------------------------------------------------------
00036 //      typedefs
00037 // -----------------------------------------------------------------------------
00038 
00039 // The thumbnail generation function to be implemented in GenerateThumbnailForURL.c
00040 OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize);
00041 void CancelThumbnailGeneration(void* thisInterface, QLThumbnailRequestRef thumbnail);
00042 
00043 // The preview generation function to be implemented in GeneratePreviewForURL.c
00044 OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options);
00045 void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview);
00046 
00047 // The layout for an instance of QuickLookGeneratorPlugIn
00048 typedef struct __QuickLookGeneratorPluginType
00049 {
00050     void        *conduitInterface;
00051     CFUUIDRef    factoryID;
00052     UInt32       refCount;
00053 } QuickLookGeneratorPluginType;
00054 
00055 // -----------------------------------------------------------------------------
00056 //      prototypes
00057 // -----------------------------------------------------------------------------
00058 //      Forward declaration for the IUnknown implementation.
00059 //
00060 
00061 QuickLookGeneratorPluginType  *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID);
00062 void                         DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance);
00063 HRESULT                      QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv);
00064 void                        *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID);
00065 ULONG                        QuickLookGeneratorPluginAddRef(void *thisInstance);
00066 ULONG                        QuickLookGeneratorPluginRelease(void *thisInstance);
00067 
00068 // -----------------------------------------------------------------------------
00069 //      myInterfaceFtbl definition
00070 // -----------------------------------------------------------------------------
00071 //      The QLGeneratorInterfaceStruct function table.
00072 //
00073 static QLGeneratorInterfaceStruct myInterfaceFtbl = {
00074     NULL,
00075     QuickLookGeneratorQueryInterface,
00076     QuickLookGeneratorPluginAddRef,
00077     QuickLookGeneratorPluginRelease,
00078     NULL,
00079     NULL,
00080     NULL,
00081     NULL
00082 };
00083 
00084 
00085 // -----------------------------------------------------------------------------
00086 //      AllocQuickLookGeneratorPluginType
00087 // -----------------------------------------------------------------------------
00088 //      Utility function that allocates a new instance.
00089 //      You can do some initial setup for the generator here if you wish
00090 //      like allocating globals etc...
00091 //
00092 QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID)
00093 {
00094     QuickLookGeneratorPluginType *theNewInstance;
00095 
00096     theNewInstance = (QuickLookGeneratorPluginType *)malloc(sizeof(QuickLookGeneratorPluginType));
00097     memset(theNewInstance,0,sizeof(QuickLookGeneratorPluginType));
00098 
00099         /* Point to the function table Malloc enough to store the stuff and copy the filler from myInterfaceFtbl over */
00100     theNewInstance->conduitInterface = malloc(sizeof(QLGeneratorInterfaceStruct));
00101     memcpy(theNewInstance->conduitInterface,&myInterfaceFtbl,sizeof(QLGeneratorInterfaceStruct));
00102 
00103         /*  Retain and keep an open instance refcount for each factory. */
00104     theNewInstance->factoryID = CFRetain(inFactoryID);
00105     CFPlugInAddInstanceForFactory(inFactoryID);
00106 
00107         /* This function returns the IUnknown interface so set the refCount to one. */
00108     theNewInstance->refCount = 1;
00109     return theNewInstance;
00110 }
00111 
00112 // -----------------------------------------------------------------------------
00113 //      DeallocQuickLookGeneratorPluginType
00114 // -----------------------------------------------------------------------------
00115 //      Utility function that deallocates the instance when
00116 //      the refCount goes to zero.
00117 //      In the current implementation generator interfaces are never deallocated
00118 //      but implement this as this might change in the future
00119 //
00120 void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance)
00121 {
00122     CFUUIDRef theFactoryID;
00123 
00124     theFactoryID = thisInstance->factoryID;
00125         /* Free the conduitInterface table up */
00126     free(thisInstance->conduitInterface);
00127 
00128         /* Free the instance structure */
00129     free(thisInstance);
00130     if (theFactoryID){
00131         CFPlugInRemoveInstanceForFactory(theFactoryID);
00132         CFRelease(theFactoryID);
00133     }
00134 }
00135 
00136 // -----------------------------------------------------------------------------
00137 //      QuickLookGeneratorQueryInterface
00138 // -----------------------------------------------------------------------------
00139 //      Implementation of the IUnknown QueryInterface function.
00140 //
00141 HRESULT QuickLookGeneratorQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv)
00142 {
00143     CFUUIDRef interfaceID;
00144 
00145     interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid);
00146 
00147     if (CFEqual(interfaceID,kQLGeneratorCallbacksInterfaceID)){
00148             /* If the Right interface was requested, bump the ref count,
00149              * set the ppv parameter equal to the instance, and
00150              * return good status.
00151              */
00152         ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->GenerateThumbnailForURL = GenerateThumbnailForURL;
00153         ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->CancelThumbnailGeneration = CancelThumbnailGeneration;
00154         ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->GeneratePreviewForURL = GeneratePreviewForURL;
00155         ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->CancelPreviewGeneration = CancelPreviewGeneration;
00156         ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType*)thisInstance)->conduitInterface)->AddRef(thisInstance);
00157         *ppv = thisInstance;
00158         CFRelease(interfaceID);
00159         return S_OK;
00160     }else{
00161         /* Requested interface unknown, bail with error. */
00162         *ppv = NULL;
00163         CFRelease(interfaceID);
00164         return E_NOINTERFACE;
00165     }
00166 }
00167 
00168 // -----------------------------------------------------------------------------
00169 // QuickLookGeneratorPluginAddRef
00170 // -----------------------------------------------------------------------------
00171 //      Implementation of reference counting for this type. Whenever an interface
00172 //      is requested, bump the refCount for the instance. NOTE: returning the
00173 //      refcount is a convention but is not required so don't rely on it.
00174 //
00175 ULONG QuickLookGeneratorPluginAddRef(void *thisInstance)
00176 {
00177     ((QuickLookGeneratorPluginType *)thisInstance )->refCount += 1;
00178     return ((QuickLookGeneratorPluginType*) thisInstance)->refCount;
00179 }
00180 
00181 // -----------------------------------------------------------------------------
00182 // QuickLookGeneratorPluginRelease
00183 // -----------------------------------------------------------------------------
00184 //      When an interface is released, decrement the refCount.
00185 //      If the refCount goes to zero, deallocate the instance.
00186 //
00187 ULONG QuickLookGeneratorPluginRelease(void *thisInstance)
00188 {
00189     ((QuickLookGeneratorPluginType*)thisInstance)->refCount -= 1;
00190     if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0){
00191         DeallocQuickLookGeneratorPluginType((QuickLookGeneratorPluginType*)thisInstance );
00192         return 0;
00193     }else{
00194         return ((QuickLookGeneratorPluginType*) thisInstance )->refCount;
00195     }
00196 }
00197 
00198 // -----------------------------------------------------------------------------
00199 //  QuickLookGeneratorPluginFactory
00200 // -----------------------------------------------------------------------------
00201 void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator,CFUUIDRef typeID)
00202 {
00203     QuickLookGeneratorPluginType *result;
00204     CFUUIDRef                 uuid;
00205 
00206         /* If correct type is being requested, allocate an
00207          * instance of kQLGeneratorTypeID and return the IUnknown interface.
00208          */
00209     if (CFEqual(typeID,kQLGeneratorTypeID)){
00210         uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID));
00211         result = AllocQuickLookGeneratorPluginType(uuid);
00212         CFRelease(uuid);
00213         return result;
00214     }
00215         /* If the requested type is incorrect, return NULL. */
00216     return NULL;
00217 }
00218 

Generated on Tue Jul 5 14:10:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1