git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

QuickLook/main.c

      1 /* This is an Apple-provided "bootstrap" code for Quick Look generators, nothing intersting here. */
      2 
      3 #include <CoreFoundation/CoreFoundation.h>
      4 #include <CoreFoundation/CFPlugInCOM.h>
      5 #include <CoreServices/CoreServices.h>
      6 #include <QuickLook/QuickLook.h>
      7 
      8 // -----------------------------------------------------------------------------
      9 //	constants
     10 // -----------------------------------------------------------------------------
     11 
     12 // Don't modify this line
     13 #define PLUGIN_ID "48BC750C-2BB9-49B1-AE80-786E22B3DEB4"
     14 
     15 //
     16 // Below is the generic glue code for all plug-ins.
     17 //
     18 // You should not have to modify this code aside from changing
     19 // names if you decide to change the names defined in the Info.plist
     20 //
     21 
     22 
     23 // -----------------------------------------------------------------------------
     24 //	typedefs
     25 // -----------------------------------------------------------------------------
     26 
     27 OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thumbnail, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options, CGSize maxSize);
     28 OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options);
     29 
     30 // The layout for an instance of QuickLookGeneratorPlugIn
     31 typedef struct __QuickLookGeneratorPluginType
     32 {
     33     void        *conduitInterface;
     34     CFUUIDRef    factoryID;
     35     UInt32       refCount;
     36 } QuickLookGeneratorPluginType;
     37 
     38 // -----------------------------------------------------------------------------
     39 //	prototypes
     40 // -----------------------------------------------------------------------------
     41 //	Forward declaration for the IUnknown implementation.
     42 //
     43 
     44 static QuickLookGeneratorPluginType  *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID);
     45 static void                         DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance);
     46 static HRESULT                      QuickLookGeneratorQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv);
     47 extern void                        *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID);
     48 static ULONG                        QuickLookGeneratorPluginAddRef(void *thisInstance);
     49 static ULONG                        QuickLookGeneratorPluginRelease(void *thisInstance);
     50 
     51 // -----------------------------------------------------------------------------
     52 //	myInterfaceFtbl	definition
     53 // -----------------------------------------------------------------------------
     54 //	The QLGeneratorInterfaceStruct function table.
     55 //
     56 static QLGeneratorInterfaceStruct myInterfaceFtbl = {
     57     NULL,
     58     QuickLookGeneratorQueryInterface,
     59     QuickLookGeneratorPluginAddRef,
     60     QuickLookGeneratorPluginRelease,
     61     NULL,
     62     NULL,
     63     NULL,
     64     NULL
     65 };
     66 
     67 
     68 // -----------------------------------------------------------------------------
     69 //	AllocQuickLookGeneratorPluginType
     70 // -----------------------------------------------------------------------------
     71 //	Utility function that allocates a new instance.
     72 //      You can do some initial setup for the generator here if you wish
     73 //      like allocating globals etc...
     74 //
     75 QuickLookGeneratorPluginType *AllocQuickLookGeneratorPluginType(CFUUIDRef inFactoryID)
     76 {
     77     QuickLookGeneratorPluginType *theNewInstance;
     78 
     79     theNewInstance = (QuickLookGeneratorPluginType *)malloc(sizeof(QuickLookGeneratorPluginType));
     80     memset(theNewInstance, 0, sizeof(QuickLookGeneratorPluginType));
     81 
     82         /* Point to the function table Malloc enough to store the stuff and copy the filler from myInterfaceFtbl over */
     83     theNewInstance->conduitInterface = malloc(sizeof(QLGeneratorInterfaceStruct));
     84     memcpy(theNewInstance->conduitInterface,&myInterfaceFtbl, sizeof(QLGeneratorInterfaceStruct));
     85 
     86         /*  Retain and keep an open instance refcount for each factory. */
     87     theNewInstance->factoryID = CFRetain(inFactoryID);
     88     CFPlugInAddInstanceForFactory(inFactoryID);
     89 
     90         /* This function returns the IUnknown interface so set the refCount to one. */
     91     theNewInstance->refCount = 1;
     92     return theNewInstance;
     93 }
     94 
     95 // -----------------------------------------------------------------------------
     96 //	DeallocQuickLookGeneratorPluginType
     97 // -----------------------------------------------------------------------------
     98 //	Utility function that deallocates the instance when
     99 //	the refCount goes to zero.
    100 //      In the current implementation generator interfaces are never deallocated
    101 //      but implement this as this might change in the future
    102 //
    103 void DeallocQuickLookGeneratorPluginType(QuickLookGeneratorPluginType *thisInstance)
    104 {
    105     CFUUIDRef theFactoryID;
    106 
    107     theFactoryID = thisInstance->factoryID;
    108         /* Free the conduitInterface table up */
    109     free(thisInstance->conduitInterface);
    110 
    111         /* Free the instance structure */
    112     free(thisInstance);
    113     if (theFactoryID) {
    114         CFPlugInRemoveInstanceForFactory(theFactoryID);
    115         CFRelease(theFactoryID);
    116     }
    117 }
    118 
    119 // -----------------------------------------------------------------------------
    120 //	QuickLookGeneratorQueryInterface
    121 // -----------------------------------------------------------------------------
    122 //	Implementation of the IUnknown QueryInterface function.
    123 //
    124 HRESULT QuickLookGeneratorQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv)
    125 {
    126     CFUUIDRef interfaceID;
    127 
    128     interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, iid);
    129 
    130     if (CFEqual(interfaceID, kQLGeneratorCallbacksInterfaceID)) {
    131             /* If the Right interface was requested, bump the ref count,
    132              * set the ppv parameter equal to the instance, and
    133              * return good status.
    134              */
    135         ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->GenerateThumbnailForURL = GenerateThumbnailForURL;
    136         ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType *)thisInstance)->conduitInterface)->GeneratePreviewForURL = GeneratePreviewForURL;
    137         ((QLGeneratorInterfaceStruct *)((QuickLookGeneratorPluginType*)thisInstance)->conduitInterface)->AddRef(thisInstance);
    138         *ppv = thisInstance;
    139         CFRelease(interfaceID);
    140         return S_OK;
    141     }
    142     else {
    143         /* Requested interface unknown, bail with error. */
    144         *ppv = NULL;
    145         CFRelease(interfaceID);
    146         return E_NOINTERFACE;
    147     }
    148 }
    149 
    150 // -----------------------------------------------------------------------------
    151 // QuickLookGeneratorPluginAddRef
    152 // -----------------------------------------------------------------------------
    153 //	Implementation of reference counting for this type. Whenever an interface
    154 //	is requested, bump the refCount for the instance. NOTE: returning the
    155 //	refcount is a convention but is not required so don't rely on it.
    156 //
    157 ULONG QuickLookGeneratorPluginAddRef(void *thisInstance)
    158 {
    159     ((QuickLookGeneratorPluginType *)thisInstance )->refCount += 1;
    160     return ((QuickLookGeneratorPluginType*) thisInstance)->refCount;
    161 }
    162 
    163 // -----------------------------------------------------------------------------
    164 // QuickLookGeneratorPluginRelease
    165 // -----------------------------------------------------------------------------
    166 //	When an interface is released, decrement the refCount.
    167 //	If the refCount goes to zero, deallocate the instance.
    168 //
    169 ULONG QuickLookGeneratorPluginRelease(void *thisInstance)
    170 {
    171     ((QuickLookGeneratorPluginType*)thisInstance)->refCount -= 1;
    172     if (((QuickLookGeneratorPluginType*)thisInstance)->refCount == 0) {
    173         DeallocQuickLookGeneratorPluginType((QuickLookGeneratorPluginType*)thisInstance );
    174         return 0;
    175     }
    176     else {
    177         return ((QuickLookGeneratorPluginType*) thisInstance )->refCount;
    178     }
    179 }
    180 
    181 // -----------------------------------------------------------------------------
    182 //  QuickLookGeneratorPluginFactory
    183 // -----------------------------------------------------------------------------
    184 void *QuickLookGeneratorPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID)
    185 {
    186     QuickLookGeneratorPluginType *result;
    187     CFUUIDRef                 uuid;
    188 
    189         /* If correct type is being requested, allocate an
    190          * instance of kQLGeneratorTypeID and return the IUnknown interface.
    191          */
    192     if (CFEqual(typeID, kQLGeneratorTypeID)) {
    193         uuid = CFUUIDCreateFromString(kCFAllocatorDefault, CFSTR(PLUGIN_ID));
    194         result = AllocQuickLookGeneratorPluginType(uuid);
    195         CFRelease(uuid);
    196         return result;
    197     }
    198         /* If the requested type is incorrect, return NULL. */
    199     return NULL;
    200 }
    201 

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.