Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
main.c File Reference
#include <CoreFoundation/CoreFoundation.h>
#include <CoreFoundation/CFPlugInCOM.h>
#include <CoreServices/CoreServices.h>

Go to the source code of this file.

Classes

Defines

#define PLUGIN_ID   "37401ADE-1058-42DB-BBE5-F2AAB9D7C13E"

Typedefs

typedef struct
__MetadataImporterPluginType 
MetadataImporterPluginType

Functions

Boolean GetMetadataForFile (void *thisInterface, CFMutableDictionaryRef attributes, CFStringRef contentTypeUTI, CFStringRef pathToFile)
MetadataImporterPluginTypeAllocMetadataImporterPluginType (CFUUIDRef inFactoryID)
void DeallocMetadataImporterPluginType (MetadataImporterPluginType *thisInstance)
HRESULT MetadataImporterQueryInterface (void *thisInstance, REFIID iid, LPVOID *ppv)
voidMetadataImporterPluginFactory (CFAllocatorRef allocator, CFUUIDRef typeID)
ULONG MetadataImporterPluginAddRef (void *thisInstance)
ULONG MetadataImporterPluginRelease (void *thisInstance)

Variables

static MDImporterInterfaceStruct testInterfaceFtbl

Class Documentation

struct __MetadataImporterPluginType

Definition at line 82 of file main.c.

Class Members
MDImporterInterfaceStruct * conduitInterface
CFUUIDRef factoryID
UInt32 refCount

Define Documentation

#define PLUGIN_ID   "37401ADE-1058-42DB-BBE5-F2AAB9D7C13E"

Definition at line 61 of file main.c.


Typedef Documentation


Function Documentation

Definition at line 123 of file main.c.

{
    MetadataImporterPluginType *theNewInstance;

    theNewInstance = (MetadataImporterPluginType *)malloc(sizeof(MetadataImporterPluginType));
    memset(theNewInstance,0,sizeof(MetadataImporterPluginType));

        /* Point to the function table */
    theNewInstance->conduitInterface = &testInterfaceFtbl;

        /*  Retain and keep an open instance refcount for each factory. */
    theNewInstance->factoryID = CFRetain(inFactoryID);
    CFPlugInAddInstanceForFactory(inFactoryID);

        /* This function returns the IUnknown interface so set the refCount to one. */
    theNewInstance->refCount = 1;
    return theNewInstance;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 150 of file main.c.

{
    CFUUIDRef theFactoryID;

    theFactoryID = thisInstance->factoryID;
    free(thisInstance);
    if (theFactoryID){
        CFPlugInRemoveInstanceForFactory(theFactoryID);
        CFRelease(theFactoryID);
    }
}

Here is the caller graph for this function:

Boolean GetMetadataForFile ( void thisInterface,
CFMutableDictionaryRef  attributes,
CFStringRef  contentTypeUTI,
CFStringRef  pathToFile 
)

Definition at line 51 of file GetMetadataForFile.c.

{
    /* Pull any available metadata from the file at the specified path */
    /* Return the attribute keys and attribute values in the dict */
    /* Return TRUE if successful, FALSE if there was no data provided */
  Boolean success;
  CFURLRef fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, pathToFile, kCFURLPOSIXPathStyle, false);
  CFReadStreamRef stream = CFReadStreamCreateWithFile(kCFAllocatorDefault, fileURL);
  CFReadStreamOpen(stream);

  CFPropertyListFormat format;
  CFStringRef errorString = NULL;
  CFPropertyListRef ticket = CFPropertyListCreateFromStream(kCFAllocatorDefault,
                             stream,
                             /*streamLength*/ 0,
                             kCFPropertyListImmutable,
                              &format,
                             &errorString
                             );
  if (errorString)
  {
    printf("failed creating property list from stream\n");
    printf("error = %s\n", (const char*) errorString);
    success = FALSE;
  } 
  else
  {
    CFTypeRef value;
    value = CFDictionaryGetValue(ticket, kMDItemTitle);
     if (value)
     {
       CFDictionarySetValue(attributes, kMDItemTitle, value);
     }
     value = CFDictionaryGetValue(ticket, kMDItemTextContent);
     if (value)
     {
       CFDictionarySetValue(attributes, kMDItemTextContent, value);
       
     }
     value = CFDictionaryGetValue(ticket, kMDItemDisplayName);
     if (value)
       CFDictionarySetValue(attributes, kMDItemDisplayName, value);
        
     CFDateFormatterRef dateFormatter = CFDateFormatterCreate(NULL, NULL, kCFDateFormatterLongStyle, kCFDateFormatterLongStyle);
                                              
     value = CFDictionaryGetValue(ticket, kMDItemLastUsedDate);

     if (value && dateFormatter)
     {
       printf("trying to parse date \n");
       CFDateRef curDate = CFDateFormatterCreateDateFromString(NULL, dateFormatter, value, NULL);
       printf("got cur date\n");
       if (curDate)
         CFDictionarySetValue(attributes, kMDItemLastUsedDate, curDate);
     }
                                                   
     success = TRUE;
  }
  // contents are kMDItemTextContent
  
  CFReadStreamClose(stream);
  CFRelease(stream);
  CFRelease(fileURL);
  return success;    
}

Here is the call graph for this function:

Definition at line 205 of file main.c.

{
    ((MetadataImporterPluginType *)thisInstance )->refCount += 1;
    return ((MetadataImporterPluginType*) thisInstance)->refCount;
}
void * MetadataImporterPluginFactory ( CFAllocatorRef  allocator,
CFUUIDRef  typeID 
)

Definition at line 233 of file main.c.

{
    MetadataImporterPluginType *result;
    CFUUIDRef                 uuid;

        /* If correct type is being requested, allocate an
         * instance of TestType and return the IUnknown interface.
         */
    if (CFEqual(typeID,kMDImporterTypeID)){
        uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID));
        result = AllocMetadataImporterPluginType(uuid);
        CFRelease(uuid);
        return result;
    }
        /* If the requested type is incorrect, return NULL. */
    return NULL;
}

Here is the call graph for this function:

Definition at line 217 of file main.c.

{
    ((MetadataImporterPluginType*)thisInstance)->refCount -= 1;
    if (((MetadataImporterPluginType*)thisInstance)->refCount == 0){
        DeallocMetadataImporterPluginType((MetadataImporterPluginType*)thisInstance );
        return 0;
    }else{
        return ((MetadataImporterPluginType*) thisInstance )->refCount;
    }
}

Here is the call graph for this function:

HRESULT MetadataImporterQueryInterface ( void thisInstance,
REFIID  iid,
LPVOID ppv 
)

Definition at line 167 of file main.c.

{
    CFUUIDRef interfaceID;

    interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid);

    if (CFEqual(interfaceID,kMDImporterInterfaceID)){
            /* If the Right interface was requested, bump the ref count,
             * set the ppv parameter equal to the instance, and
             * return good status.
             */
        ((MetadataImporterPluginType*)thisInstance)->conduitInterface->AddRef(thisInstance);
        *ppv = thisInstance;
        CFRelease(interfaceID);
        return S_OK;
    }else{
        if (CFEqual(interfaceID,IUnknownUUID)){
                /* If the IUnknown interface was requested, same as above. */
            ((MetadataImporterPluginType*)thisInstance )->conduitInterface->AddRef(thisInstance);
            *ppv = thisInstance;
            CFRelease(interfaceID);
            return S_OK;
        }else{
                /* Requested interface unknown, bail with error. */
            *ppv = NULL;
            CFRelease(interfaceID);
            return E_NOINTERFACE;
        }
    }
}

Variable Documentation

MDImporterInterfaceStruct testInterfaceFtbl [static]