1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 // Created by Florian Heckl on 10.07.07.
25 //==============================================================================
27 // DO NOT MODIFY THE CONTENTS OF THIS FILE
29 // This file contains the generic CFPlug-in code necessary for your importer
30 // To complete your importer implement the function in GetMetadataForFile.c
32 //==============================================================================
34 #include <CoreFoundation/CoreFoundation.h>
35 #include <CoreFoundation/CFPlugInCOM.h>
36 #include <CoreServices/CoreServices.h>
38 #include "GetMetadataForFile.h"
43 #define PLUGIN_ID "A3FCC88D-B9A6-4364-8B93-92123C8A2D18"
46 // Below is the generic glue code for all plug-ins.
48 // You should not have to modify this code aside from changing
49 // names if you decide to change the names defined in the Info.plist
55 // The layout for an instance of MetaDataImporterPlugIn
58 MDImporterInterfaceStruct *conduitInterface;
61 } MetadataImporterPluginType;
64 // Forward declaration for the IUnknown implementation.
67 static MetadataImporterPluginType *AllocMetadataImporterPluginType(CFUUIDRef inFactoryID);
68 static void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance);
69 static HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv);
70 static ULONG MetadataImporterPluginAddRef(void *thisInstance);
71 static ULONG MetadataImporterPluginRelease(void *thisInstance);
72 // testInterfaceFtbl definition
73 // The TestInterface function table.
76 static MDImporterInterfaceStruct testInterfaceFtbl = {
78 MetadataImporterQueryInterface,
79 MetadataImporterPluginAddRef,
80 MetadataImporterPluginRelease,
85 // AllocMetadataImporterPluginType
86 // Utility function that allocates a new instance.
87 // You can do some initial setup for the importer here if you wish
88 // like allocating globals etc...
90 MetadataImporterPluginType *AllocMetadataImporterPluginType(CFUUIDRef inFactoryID)
92 MetadataImporterPluginType *theNewInstance;
94 theNewInstance = (MetadataImporterPluginType *)malloc(sizeof(MetadataImporterPluginType));
95 memset(theNewInstance,0,sizeof(MetadataImporterPluginType));
97 /* Point to the function table */
98 theNewInstance->conduitInterface = &testInterfaceFtbl;
100 /* Retain and keep an open instance refcount for each factory. */
101 theNewInstance->factoryID = CFRetain(inFactoryID);
102 CFPlugInAddInstanceForFactory(inFactoryID);
104 /* This function returns the IUnknown interface so set the refCount to one. */
105 theNewInstance->refCount = 1;
106 return theNewInstance;
109 // DeallocSpotlightTesterMDImporterPluginType
110 // Utility function that deallocates the instance when
111 // the refCount goes to zero.
112 // In the current implementation importer interfaces are never deallocated
113 // but implement this as this might change in the future
115 void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance)
117 CFUUIDRef theFactoryID;
119 theFactoryID = thisInstance->factoryID;
122 CFPlugInRemoveInstanceForFactory(theFactoryID);
123 CFRelease(theFactoryID);
127 // MetadataImporterQueryInterface
128 // Implementation of the IUnknown QueryInterface function.
130 HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv)
132 CFUUIDRef interfaceID;
134 interfaceID = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault,iid);
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.
141 ((MetadataImporterPluginType*)thisInstance)->conduitInterface->AddRef(thisInstance);
143 CFRelease(interfaceID);
146 if (CFEqual(interfaceID,IUnknownUUID)){
147 /* If the IUnknown interface was requested, same as above. */
148 ((MetadataImporterPluginType*)thisInstance )->conduitInterface->AddRef(thisInstance);
150 CFRelease(interfaceID);
153 /* Requested interface unknown, bail with error. */
155 CFRelease(interfaceID);
156 return E_NOINTERFACE;
161 // MetadataImporterPluginAddRef
162 // Implementation of reference counting for this type. Whenever an interface
163 // is requested, bump the refCount for the instance. NOTE: returning the
164 // refcount is a convention but is not required so don't rely on it.
166 ULONG MetadataImporterPluginAddRef(void *thisInstance)
168 ((MetadataImporterPluginType *)thisInstance )->refCount += 1;
169 return ((MetadataImporterPluginType*) thisInstance)->refCount;
172 // SampleCMPluginRelease
173 // When an interface is released, decrement the refCount.
174 // If the refCount goes to zero, deallocate the instance.
176 ULONG MetadataImporterPluginRelease(void *thisInstance)
178 ((MetadataImporterPluginType*)thisInstance)->refCount -= 1;
179 if (((MetadataImporterPluginType*)thisInstance)->refCount == 0){
180 DeallocMetadataImporterPluginType((MetadataImporterPluginType*)thisInstance );
183 return ((MetadataImporterPluginType*) thisInstance )->refCount;
187 // SpotlightTesterMDImporterPluginFactory
188 // Implementation of the factory function for this type.
190 __attribute__ ((visibility("default")))
192 MetadataImporterPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID)
194 (void) allocator; /* unused */
195 MetadataImporterPluginType *result;
198 /* If correct type is being requested, allocate an
199 * instance of TestType and return the IUnknown interface.
201 if (CFEqual(typeID,kMDImporterTypeID)){
202 uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID));
203 result = AllocMetadataImporterPluginType(uuid);
207 /* If the requested type is incorrect, return NULL. */
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */