LibreOffice Module extensions (master) 1
main.m
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19//
20// main.m
21// SpotlightTester
22//
23// Created by Florian Heckl on 10.07.07.
24//
25//==============================================================================
26//
27// DO NOT MODIFY THE CONTENTS OF THIS FILE
28//
29// This file contains the generic CFPlug-in code necessary for your importer
30// To complete your importer implement the function in GetMetadataForFile.c
31//
32//==============================================================================
33
34#include <CoreFoundation/CoreFoundation.h>
35#include <CoreFoundation/CFPlugInCOM.h>
36#include <CoreServices/CoreServices.h>
37
38#include "GetMetadataForFile.h"
39
40// constants
41
42
43#define PLUGIN_ID "A3FCC88D-B9A6-4364-8B93-92123C8A2D18"
44
45//
46// Below is the generic glue code for all plug-ins.
47//
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
50//
51
52
53// typedefs
54
55// The layout for an instance of MetaDataImporterPlugIn
56typedef struct
57{
58 MDImporterInterfaceStruct *conduitInterface;
59 CFUUIDRef factoryID;
60 UInt32 refCount;
62
63// prototypes
64// Forward declaration for the IUnknown implementation.
65//
66
69static HRESULT MetadataImporterQueryInterface(void *thisInstance,REFIID iid,LPVOID *ppv);
70static ULONG MetadataImporterPluginAddRef(void *thisInstance);
71static ULONG MetadataImporterPluginRelease(void *thisInstance);
72// testInterfaceFtbl definition
73// The TestInterface function table.
74//
75
76static MDImporterInterfaceStruct testInterfaceFtbl = {
77 NULL,
82};
83
84
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...
89//
91{
92 MetadataImporterPluginType *theNewInstance;
93
94 theNewInstance = (MetadataImporterPluginType *)malloc(sizeof(MetadataImporterPluginType));
95 memset(theNewInstance,0,sizeof(MetadataImporterPluginType));
96
97 /* Point to the function table */
98 theNewInstance->conduitInterface = &testInterfaceFtbl;
99
100 /* Retain and keep an open instance refcount for each factory. */
101 theNewInstance->factoryID = CFRetain(inFactoryID);
102 CFPlugInAddInstanceForFactory(inFactoryID);
103
104 /* This function returns the IUnknown interface so set the refCount to one. */
105 theNewInstance->refCount = 1;
106 return theNewInstance;
107}
108
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
114//
116{
117 CFUUIDRef theFactoryID;
118
119 theFactoryID = thisInstance->factoryID;
120 free(thisInstance);
121 if (theFactoryID){
122 CFPlugInRemoveInstanceForFactory(theFactoryID);
123 CFRelease(theFactoryID);
124 }
125}
126
127// MetadataImporterQueryInterface
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// 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.
165//
166ULONG MetadataImporterPluginAddRef(void *thisInstance)
167{
168 ((MetadataImporterPluginType *)thisInstance )->refCount += 1;
169 return ((MetadataImporterPluginType*) thisInstance)->refCount;
170}
171
172// SampleCMPluginRelease
173// When an interface is released, decrement the refCount.
174// If the refCount goes to zero, deallocate the instance.
175//
176ULONG MetadataImporterPluginRelease(void *thisInstance)
177{
178 ((MetadataImporterPluginType*)thisInstance)->refCount -= 1;
179 if (((MetadataImporterPluginType*)thisInstance)->refCount == 0){
181 return 0;
182 }else{
183 return ((MetadataImporterPluginType*) thisInstance )->refCount;
184 }
185}
186
187// SpotlightTesterMDImporterPluginFactory
188// Implementation of the factory function for this type.
189//
190__attribute__ ((visibility("default")))
191void *
192MetadataImporterPluginFactory(CFAllocatorRef allocator, CFUUIDRef typeID)
193{
194 (void) allocator; /* unused */
196 CFUUIDRef uuid;
197
198 /* If correct type is being requested, allocate an
199 * instance of TestType and return the IUnknown interface.
200 */
201 if (CFEqual(typeID,kMDImporterTypeID)){
202 uuid = CFUUIDCreateFromString(kCFAllocatorDefault,CFSTR(PLUGIN_ID));
204 CFRelease(uuid);
205 return result;
206 }
207 /* If the requested type is incorrect, return NULL. */
208 return NULL;
209}
210
211/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Boolean GetMetadataForFile(void *thisInterface, CFMutableDictionaryRef attributes, CFStringRef contentTypeUTI, CFStringRef pathToFile)
__attribute__((visibility("default"))) void *MetadataImporterPluginFactory(CFAllocatorRef allocator
static void DeallocMetadataImporterPluginType(MetadataImporterPluginType *thisInstance)
Definition: main.m:115
return NULL
Definition: main.m:208
static MetadataImporterPluginType * AllocMetadataImporterPluginType(CFUUIDRef inFactoryID)
Definition: main.m:90
CFUUIDRef uuid
Definition: main.m:196
static MDImporterInterfaceStruct testInterfaceFtbl
Definition: main.m:76
static ULONG MetadataImporterPluginRelease(void *thisInstance)
Definition: main.m:176
#define PLUGIN_ID
Definition: main.m:43
static HRESULT MetadataImporterQueryInterface(void *thisInstance, REFIID iid, LPVOID *ppv)
Definition: main.m:130
MetadataImporterPluginType * result
Definition: main.m:195
CFUUIDRef typeID
Definition: main.m:193
static ULONG MetadataImporterPluginAddRef(void *thisInstance)
Definition: main.m:166
CFUUIDRef factoryID
Definition: main.m:59
MDImporterInterfaceStruct * conduitInterface
Definition: main.m:58