summaryrefslogtreecommitdiff
path: root/XMPFilesPlugins/api/source/PluginHandler.h
blob: eb647915d9eab23955d1cdb8b0654fb2f66a62b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
// =================================================================================================
// Copyright Adobe
// Copyright 2011 Adobe
// All Rights Reserved
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it. If you have received this file from a source other 
// than Adobe, then your use, modification, or distribution of it requires the prior written permission
// of Adobe.
// =================================================================================================

/**************************************************************************
* @file Plugin_Handler.h
* @brief Function prototypes for the XMP Plugin.
*
* This contains the prototype for the plug-in based File Handlers. Plug-in need 
* to implement exported function InitializePlugin.
* 
***************************************************************************/

#ifndef __Plugin_Handler_hpp__
#define __Plugin_Handler_hpp__	1
#include "PluginConst.h"
#include "PluginUtils.h"
#include "source/XMP_ProgressTracker.hpp"

// versioning
#define XMP_PLUGIN_VERSION_1	1	// CS6
#define XMP_PLUGIN_VERSION_2	2	//
#define XMP_PLUGIN_VERSION_3	3	// CS7
#define XMP_PLUGIN_VERSION_4	4

#define XMP_PLUGIN_VERSION		XMP_PLUGIN_VERSION_4

namespace XMP_PLUGIN
{

#ifdef __cplusplus
extern "C" {
#endif

#if defined(__GNUC__)
	#define DllExport		__attribute__((visibility("default")))
#else
	#define DllExport		__declspec( dllexport )
#endif

struct PluginAPI;
struct HostAPI;

typedef PluginAPI*		PluginAPIRef;
typedef HostAPI*		HostAPIRef;
typedef void*			SessionRef;
typedef void*			XMP_IORef;
typedef int				XMPErrorID;

/** @struct WXMP_Error
 *
 *  This is used to pass error number and error message by the host(the XMPFiles) and the plugin.
 *  All plugin APIs and host APIs return kXMPErr_NoError on success otherwise return error id.
 *  All such APIs also take 'WXMP_Error wError' as the last argument. This structure will be filled
 *  by the error id and message if any error is encountered. The return value and wError->mErrorID
 *  contains the same number.
 */
struct WXMP_Error
{
   XMPErrorID		mErrorID;
   XMP_StringPtr	mErrorMsg;
   WXMP_Error() : mErrorID( kXMPErr_NoError ), mErrorMsg( NULL ) {}
};


/** 
 *  Function pointer to the function TerminatePlugin which will be called
 *  at the time of unloading of the plugin.
 *
 *  @param wError	WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return			kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*TerminatePluginProc)( WXMP_Error * wError );

/** 
 *  Function pointer to the function SetHostAPIProc which will be called to 
 *  set the hostAPI. These host APIs will be used in the plugin to use the Host(the XMPFiles) functionality.
 *
 *  @param hostAPI		An API that is provided by the host (the XMPFiles) that can be used by a plugin implementaion.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*SetHostAPIProc)( HostAPIRef hostAPI, WXMP_Error * wError );

/** 
 *  Function pointer to the function InitializeSession which will be called
 *  at the time of creating instance of the file handler with /param uid for file /param filePath.
 *
 *  @param uid				Unique identifier string (uid) of the file handler whose instance is to be created.
 *  @param filePath			FilePath of the file which is to be opened.
 *  @param format			File format id for the session
 *	@param handlerFlags		Handler flags as defined in the plugin manifest
 *  @param openFlags		Flags that describe the desired access.
 *  @param session			Pointer to a file Handler instance.
 *  @return					kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*InitializeSessionProc)( XMP_StringPtr uid, XMP_StringPtr filePath, XMP_Uns32 format, XMP_Uns32 handlerFlags, XMP_Uns32 openFlags, SessionRef * session, WXMP_Error * wError );

/** 
 *  Function pointer to the function InitializeSession which will be called
 *  at the time of creating instance of the file handler with /param uid for file /param filePath.
 *
 *  @param uid				Unique identifier string (uid) of the file handler whose instance is to be created.
 *  @param filePath			FilePath of the file which is to be opened.
 *  @param format			File format id for the session
 *	@param handlerFlags		Handler flags as defined in the plugin manifest
 *  @param openFlags		Flags that describe the desired access.
 *  @param session			Pointer to a file Handler instance.
 *  @param errorCallback	Pointer to error callback info
 *  @param progCBInfoPtr	Points to the progress callback notification information
 *  @return					kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*InitializeSessionV2Proc)( XMP_StringPtr uid, XMP_StringPtr filePath, XMP_Uns32 format, XMP_Uns32 handlerFlags, XMP_Uns32 openFlags, SessionRef * session, WXMP_Error * wError,
											  ErrorCallbackBox errorCallbackBox, XMP_ProgressTracker::CallbackInfo * progCBInfo );

/** 
 *  Function pointer to the function TerminateSession which will be called
 *  at the time of terminating instance of the file handler.
 *
 *  @param session		File Handler instance.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*TerminateSessionProc)( SessionRef session, WXMP_Error * wError );

/** 
 *  Function pointer to the function CheckFileFormat which will be called to
 *  check whether the input file /param filePath is supported by the file handler with /param uid.
 *
 *  @param uid			Unique identifier string (uid) of the file handler.
 *  @param filePath		FilePath of the file which is to be opened.
 *  @para fileRef		File reference to the input file.
 *  @param result		[out] pointer to a boolean which will be true if /param filePath is supported by the file handler.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*CheckSessionFileFormatProc)( XMP_StringPtr uid, XMP_StringPtr filePath, XMP_IORef fileRef, XMP_Bool * result, WXMP_Error * wError );

/** 
 *  Function pointer to the function CheckFolderFormat which will be called to
 *  check whether the input folder name is supported by the file handler with /param uid.
 *
 *  @param uid Unique identifier string (uid) of the file handler.
 *  @param rootPath
 *  @param gpName
 *  @param parentName
 *  @param leafName
 *  @param result		[out] pointer to a boolen which will be true if it is supported by the file handler.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*CheckSessionFolderFormatProc)( XMP_StringPtr uid, XMP_StringPtr rootPath, XMP_StringPtr gpName, XMP_StringPtr parentName, XMP_StringPtr leafName, XMP_Bool * result, WXMP_Error * wError );

/**
 * Function type for GetFileModDate. Returns the most recent file modification date for any file
 * associated with the path that is read to obtain metadata. A static routine in XMPFiles.
 *
 *  @param session		File Handler instance.
 *	@param ok			A pointer to a XMP_Bool for the eventual public API function result.
 *	@param modDate		A pointer to the date to be returned.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 */
typedef XMPErrorID (*GetSessionFileModDateProc) ( SessionRef session, XMP_Bool * ok, XMP_DateTime * modDate, WXMP_Error * wError );

/** 
 *  Function pointer to the function CacheFileData which will be called to
 *  cache xmpData from the file format of the session.
 *
 *  @param session		File Handler instance.
 *  @param fileRef		File reference of the file format which may be needed to read the data.
 *  @param xmpStr		A pointer to a buffer where xmpData will be stored.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*CacheFileDataProc)( SessionRef session, XMP_IORef fileRef, XMP_StringPtr* xmpStr, WXMP_Error * wError );

/** 
 *  Function pointer to the function UpdateFileData which will be called to
 *  update the file format of the session with the /param xmpPacket.
 *
 *  @param session		File Handler instance.
 *  @param fileRef		File reference of the file format which may be needed to read the data.
 *  @param doSafeUpdate If true, file is saved in safe mode that means it write into a temporary file then swap for crash safety.
 *  @param xmpStr		A pointer to a buffer which contain the xmpData.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*UpdateFileProc)( SessionRef session, XMP_IORef fileRef, XMP_Bool doSafeUpdate, XMP_StringPtr xmpStr, WXMP_Error * wError );

/** 
 *  Function pointer to the function WriteTempFile. It write the entire file format into a
 *  temporary file /param fileRef.
 *
 *  @param session		File Handler instance.
 *  @param orgFileRef	File reference to the original source file.
 *  @param fileRef		File reference to a temporary file where file format will be written into.
 *  @param xmpStr		A pointer to a buffer which contain the xmpData.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*WriteTempFileProc)( SessionRef session, XMP_IORef orgFileRef, XMP_IORef fileRef, XMP_StringPtr xmpStr, WXMP_Error * wError );

/** 
 *  Function pointer to the function ImportToXMP. Any non metadata from a file that is supposed 
 *  to be mapped into a XMP namespace should be added to the XMP packet using this function.
 *
 *  @param session		File Handler instance.
 *  @param xmp			XMPMeta reference which will be filled by the function.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*ImportToXMPProc)( SessionRef session, XMPMetaRef xmp, WXMP_Error * wError );

/** 
 *  Function pointer to the function ExportFromXMP. The XMP packet is supposed to be 
 *  written to the file. If the packet contains any data that should be mapped back to
 *  native (non-XMP) metadata values then that should happen here.
 *
 *  @param session		File Handler instance.
 *  @param xmp			XMPMeta reference where the xmpData will be picked from.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*ExportFromXMPProc)( SessionRef session, XMPMetaRef xmp, WXMP_Error * wError );

/** 
 *  Function pointer to the function FillMetadataFiles. This function returns the list of file paths
 *  associated with storing the metadata information.
 *
 *  @param session					File Handler instance.
 *  @param metadataFiles			pointer of std::vector of std::string
 *  @param SetClientStringVector	pointer to client provided function to fill the vector with strings.
 *  @param wError					WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return							kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*FillMetadataFilesProc)( SessionRef session, StringVectorRef metadataFiles,
	SetStringVectorProc SetClientStringVector, WXMP_Error * wError );

/** 
 *  Function pointer to the function FillAssociatedResources. This function returns the list of all file paths
 *  associated to the opened session 
 *
 *  @param session					File Handler instance.
 *  @param resourceList			    pointer of std::vector of std::string
 *  @param SetClientStringVector	pointer to client provided function to fill the vector with strings.
 *  @param wError					WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return							kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*FillAssociatedResourcesProc)( SessionRef session, StringVectorRef resourceList,
	SetStringVectorProc SetClientStringVector, WXMP_Error * wError );

/** 
 *  Function pointer to the function ImportToXMP. Any non metadata from a file that is supposed 
 *  to be mapped into a XMP namespace should be added to the XMP packet using this function.
 *
 *  @param session		File Handler instance.
 *  @param xmpStr		A pointer to a buffer which contain the xmpData.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*ImportToXMPStringProc)( SessionRef session, XMP_StringPtr* xmpStr , WXMP_Error * wError );

/** 
 *  Function pointer to the function ImportToXMP. Any non metadata from a file that is supposed 
 *  to be mapped into a XMP namespace should be added to the XMP packet using this function.
 *
 *  @param session		File Handler instance.
 *  @param xmpStr		A pointer to a buffer which contain the xmpData.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @param packet		Returns existed XMP packet present in the file, if available
 *  @param packetInfo	Returns packet information of existed XMP packet in the file, if available
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*ImportToXMPStringWithPacketProc)( SessionRef session, XMP_StringPtr* xmpStr , WXMP_Error * wError, XMP_StringPtr* packet, XMP_PacketInfo * packetInfo );

/** 
 *  Function pointer to the function ExportFromXMP. The XMP packet is supposed to be 
 *  written to the file. If the packet contains any data that should be mapped back to
 *  native (non-XMP) metadata values then that should happen here.
 *
 *  @param session		File Handler instance.
 *  @param xmpStr		A pointer to a buffer which contain the xmpData.
 *  @param wError		WXMP_Error structure which will be filled by the API if any error occurs.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*ExportFromXMPStringProc)( SessionRef session, XMP_StringPtr xmpStr, WXMP_Error * wError );

/** 
 *  Function pointer to the function IsMetadataWritable. This function returns if the metadata can be updated  
 *  for the opened session 
 *
 *  @param session					File Handler instance.
 *  @param result					[out] pointer to a boolen which will be true if the metadata can be updated.
 *  @return							kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*IsMetadataWritableProc)( SessionRef session, XMP_Bool * result, WXMP_Error * wError );

/** 
 *  Function pointer to the function SetErrorCallback. This function will set ErrorCallbackNotification for the plugins 
 *
 *  @param session					File Handler instance.
 *  @param errorCallback			Pointer to Error Callback notification.
 *  @return							kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*SetErrorCallbackproc)( SessionRef session, ErrorCallbackBox errorCallbackBox, WXMP_Error * wError );

/** 
 *  Function pointer to the function SetProgressCallback. This function will set ProgressCallback for the plugins. This needs to be set by plugin 
 *
 *  @param session					File Handler instance.
 *  @param progCBInfoPtr			Pointer to Progress Callback information.
 *  @return							kXMPErr_NoError on success otherwise error id of the failure.
 */
typedef XMPErrorID (*SetProgressCallbackproc)( SessionRef session, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr, WXMP_Error * wError );

/** @struct PluginAPI
 *  @brief This is a Plugin API structure.
 *
 *  This will consists of init/term of the plugin, init/term of a file handler session,
 *  read from fie and update file.
 */
struct PluginAPI
{
	/** 
	 *  Size of the PluginAPI structure.
	 */
	XMP_Uns32						mSize;
   
	/** 
	 *  Version number of the plugin.
	 */
	XMP_Uns32						mVersion;
	
	// version 1
	TerminatePluginProc				mTerminatePluginProc;
	SetHostAPIProc					mSetHostAPIProc;
	
	InitializeSessionProc			mInitializeSessionProc;
	TerminateSessionProc			mTerminateSessionProc;
	
	CheckSessionFileFormatProc		mCheckFileFormatProc;
	CheckSessionFolderFormatProc	mCheckFolderFormatProc;
	GetSessionFileModDateProc		mGetFileModDateProc;

	CacheFileDataProc				mCacheFileDataProc;
	UpdateFileProc					mUpdateFileProc;
	WriteTempFileProc				mWriteTempFileProc;
	
	ImportToXMPProc					mImportToXMPProc;			// deprecated in version 2 in favour of mImportToXMPStringProc
	ExportFromXMPProc				mExportFromXMPProc;			// deprecated in version 2 in favour of mExportFromXMPStringProc

	// version 2
	FillMetadataFilesProc			mFillMetadataFilesProc;
	ImportToXMPStringProc			mImportToXMPStringProc;
	ExportFromXMPStringProc			mExportFromXMPStringProc;
	FillAssociatedResourcesProc     mFillAssociatedResourcesProc;

	// version 3
	IsMetadataWritableProc			mIsMetadataWritableProc;

	// version 4
	ImportToXMPStringWithPacketProc mImportToXMPStringWithPacketProc;
	SetErrorCallbackproc			mSetErrorCallbackproc;
	InitializeSessionV2Proc			mInitializeSessionV2Proc;
	SetProgressCallbackproc			mSetProgressCallbackproc;
};


/** @brief Plugin Entry point (legacy).
 *
 *  This is the legacy entry point for the plugin. It will fill \param pluginAPI inside the plugin.
 * 
 *  @param moduleID		It is the module identifier string which is present in plugin's resource 
 *						file 'MODULE_IDENTIFIER.txt". It should be same as the one which is present in plugin's library.
 *  @param pluginAPI	structure pointer to PluginAPI which will be filled by the plugin.
 *  @param wError		structure pointer to WXMP_Error which will be filled in case of an error.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
DllExport XMPErrorID InitializePlugin( XMP_StringPtr moduleID, PluginAPIRef pluginAPI, WXMP_Error * wError );
typedef XMPErrorID (*InitializePluginProc)( XMP_StringPtr moduleID, PluginAPIRef pluginAPI, WXMP_Error * wError );

/** @brief Plugin Entry point.
 *
 *  This is the entry point for the plugin. It will fill \param pluginAPI inside the plugin.
 * 
 *  @param moduleID		It is the module identifier string which is present in plugin's resource 
 *						file 'MODULE_IDENTIFIER.txt". It should be same as the one which is present in plugin's library.
 *  @param hostAPI		structure pointer to HostAPI which will be stored by the plugin.
 *  @param pluginAPI	structure pointer to PluginAPI which will be filled by the plugin.
 *  @param wError		structure pointer to WXMP_Error which will be filled in case of an error.
 *  @return				kXMPErr_NoError on success otherwise error id of the failure.
 */
DllExport XMPErrorID InitializePlugin2( XMP_StringPtr moduleID, HostAPIRef hostAPI, PluginAPIRef pluginAPI, WXMP_Error * wError );
typedef XMPErrorID (*InitializePlugin2Proc)( XMP_StringPtr moduleID, HostAPIRef hostAPI, PluginAPIRef pluginAPI, WXMP_Error * wError );

#ifdef __cplusplus
}
#endif

} //namespace XMP_PLUGIN
#endif // __Plugin_Handler_hpp__