diff options
Diffstat (limited to 'XMPFilesPlugins/api/source')
-rw-r--r-- | XMPFilesPlugins/api/source/HostAPI.h | 106 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/HostAPIAccess.cpp | 156 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/HostAPIAccess.h | 68 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/PluginAPIImpl.cpp | 125 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/PluginBase.cpp | 82 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/PluginBase.h | 88 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/PluginHandler.h | 58 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/PluginRegistry.cpp | 6 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/PluginRegistry.h | 19 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/PluginUtils.cpp | 57 | ||||
-rw-r--r-- | XMPFilesPlugins/api/source/PluginUtils.h | 44 |
11 files changed, 777 insertions, 32 deletions
diff --git a/XMPFilesPlugins/api/source/HostAPI.h b/XMPFilesPlugins/api/source/HostAPI.h index d94aae0..e1e8ce5 100644 --- a/XMPFilesPlugins/api/source/HostAPI.h +++ b/XMPFilesPlugins/api/source/HostAPI.h @@ -315,6 +315,112 @@ struct StandardHandler_API_V2 */ typedef XMPErrorID (*GetXMPStandardHandler)( SessionRef session, XMP_FileFormat format, StringPtr path, XMP_StringPtr* xmpStr, XMP_Bool * containsXMP, WXMP_Error* wError ); GetXMPStandardHandler mGetXMPStandardHandler; + + StandardHandler_API_V2( CheckFormatStandardHandler checkFormatStandardHandler, GetXMPStandardHandler getXMPStandardHandler) + : mCheckFormatStandardHandler( checkFormatStandardHandler ) + , mGetXMPStandardHandler( getXMPStandardHandler ) {} +}; + +typedef void (* SetClientStringVectorProc) ( void * clientPtr, XMP_StringPtr * arrayPtr, XMP_Uns32 stringCount ); +typedef void * ClientStringVectorRef; + +struct StandardHandler_API_V3 : public StandardHandler_API_V2 +{ + + /** @brief Get XMP from standard file handler + * + * Call the standard file handler in order to retrieve XMP from it. + * + * @param session File handler session (referring to replacement handler) + * @param format The file format identifier + * @param path Path to the file that should be proceeded + * @param xmpStr Will on success contain serialized XMP Packet from the standard Handler + * @param containsXMP Returns true if the standard handler detected XMP + * @param wError WXMP_Error structure which will be filled by the API if any error occurs + * @param flags OpenFlags passed during opening if present + * @param packet Returns XMP packet already present in the file, if available + * @param packetInfo Returns already present XMP packet information in the file, if available + * @param errorCallback Points to error callback information + * @param progCBInfoPtr Points to the progress callback information + * @return kXMPErr_NoError on success otherwise error id of the failure. + */ + typedef XMPErrorID (*GetXMPwithPacketStandardHandlerWOptions)( SessionRef session, XMP_FileFormat format, StringPtr path, XMP_StringPtr* xmpStr, XMP_Bool * containsXMP, WXMP_Error* wError, XMP_OptionBits flags, XMP_StringPtr *packet, XMP_PacketInfo *packetInfo, ErrorCallbackBox * errorCallback, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr ); + GetXMPwithPacketStandardHandlerWOptions mGetXMPwithPacketStandardHandlerWOptions; + + /** @brief Put XMP into standard file handler + * + * Call the standard file handler in order to put XMP into it. + * + * @param session File handler session (referring to replacement handler) + * @param format The file format identifier + * @param path Path to the file that should be proceeded + * @param xmpStr Contains serialized XMP Packet present into the standard Handler + * @param wError WXMP_Error structure which will be filled by the API if any error occurs. + * @param flags OpenFlags passed during opening a file + * @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 (*PutXMPStandardHandler)( SessionRef session, XMP_FileFormat format, StringPtr path, const XMP_StringPtr xmpStr, WXMP_Error* wError, XMP_OptionBits flags, ErrorCallbackBox * errorCallback, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr ); + PutXMPStandardHandler mPutXMPStandardHandler; + + /** @brief Getting file modification date from standard file handler + * + * Call the standard file handler in order to retrieve file modification date from it. + * + * @param session File handler session (referring to replacement handler) + * @param format The file format identifier + * @param path Path to the file that should be proceeded + * @param modDate will contain modification date of file obtained from the standard Handler + * @param isSuccess Returns true if the standard handler detected file modification date + * @param wError WXMP_Error structure which will be filled by the API if any error occurs + * @param flags OpenFlags passed to XMPFile while opening a file + * @return kXMPErr_NoError on success otherwise error id of the failure. + */ + typedef XMPErrorID (*GetFileModDateStandardHandler)( SessionRef session, XMP_FileFormat format, StringPtr path, XMP_DateTime * modDate, XMP_Bool * isSuccess, WXMP_Error* wError, XMP_OptionBits flags ); + GetFileModDateStandardHandler mGetFileModDateStandardHandler; + + /** @brief Getting associated resources from standard file handler + * + * Call the standard file handler in order to retrieve all the associated resources with a file + * + * @param session File handler session (referring to replacement handler) + * @param format The file format identifier + * @param path Path to the file that should be proceeded + * @param resourceList will contain resources associated with the file obtained from the standard Handler + * @param SetClientStringVector pointer to the plugin provided function of setting vector of strings + * @param wError WXMP_Error structure which will be filled by the API if any error occurs + * @param flags OpenFlags passed during opening a file + * @return kXMPErr_NoError on success otherwise error id of the failure. + */ + typedef XMPErrorID( *GetAssociatedResourcesStandardHandler )( SessionRef session, XMP_FileFormat format, StringPtr path, ClientStringVectorRef resourceList, SetClientStringVectorProc SetClientStringVector, WXMP_Error* wError, XMP_OptionBits flags ); + GetAssociatedResourcesStandardHandler mGetAssociatedResourcesStandardHandler; + + /** @brief Checking whether metadata is writable or not into the file from standard file handler + * + * Call the standard file handler in order to check whether the metadata is writable or not into the file. + * + * @param session File handler session (referring to replacement handler) + * @param format The file format identifier + * @param path Path to the file that should be proceeded + * @param isWritable Returns true if the standard handler can write on the file. + * @param wError WXMP_Error structure which will be filled by the API if any error occurs + * @param flags OpenFlags passed during opening a file + * @return kXMPErr_NoError on success otherwise error id of the failure. + */ + typedef XMPErrorID (*IsMetadataWritableStandardHandler)( SessionRef session, XMP_FileFormat format, StringPtr path, XMP_Bool * isWritable, WXMP_Error* wError, XMP_OptionBits flags ); + IsMetadataWritableStandardHandler mIsMetadataWritableStandardHandler; + + StandardHandler_API_V3( CheckFormatStandardHandler checkFormatStandardHandler, GetXMPStandardHandler getXMPStandardHandler, + GetXMPwithPacketStandardHandlerWOptions getXMPwithPacketStandardHandlerWOptions, PutXMPStandardHandler putXMPStandardHandler, + GetFileModDateStandardHandler getFileModDateStandardHandler, GetAssociatedResourcesStandardHandler getAssociatedResourcesStandardHandler, + IsMetadataWritableStandardHandler isMetadataWritableStandardHandler ) + : StandardHandler_API_V2( checkFormatStandardHandler, getXMPStandardHandler ) + , mGetXMPwithPacketStandardHandlerWOptions( getXMPwithPacketStandardHandlerWOptions ) + , mPutXMPStandardHandler( putXMPStandardHandler ) + , mGetFileModDateStandardHandler( getFileModDateStandardHandler ) + , mGetAssociatedResourcesStandardHandler( getAssociatedResourcesStandardHandler ) + , mIsMetadataWritableStandardHandler( isMetadataWritableStandardHandler ) { } }; diff --git a/XMPFilesPlugins/api/source/HostAPIAccess.cpp b/XMPFilesPlugins/api/source/HostAPIAccess.cpp index 4215b99..2a0cf78 100644 --- a/XMPFilesPlugins/api/source/HostAPIAccess.cpp +++ b/XMPFilesPlugins/api/source/HostAPIAccess.cpp @@ -8,10 +8,12 @@ // ================================================================================================= #include "HostAPIAccess.h" +#include "PluginUtils.h" #include <cstring> #include <string> #define TXMP_STRING_TYPE std::string #include "XMP.hpp" +#include "source/XMP_LibUtils.hpp" namespace XMP_PLUGIN { @@ -24,7 +26,15 @@ namespace XMP_PLUGIN static HostAPIRef sHostAPI = NULL; static XMP_Uns32 sHostAPIVersion = 0; -StandardHandler_API_V2* sStandardHandler_V2 = NULL; +StandardHandler_API_V3* sStandardHandler_V3 = NULL; + +// No need to call it externally as would have already called during intialising a plugin +bool SetStandardHandlerAPIAccess() +{ + if ( sStandardHandler_V3 == NULL ) + sStandardHandler_V3 = (StandardHandler_API_V3 *) RequestAPISuite( "StandardHandler", 3 ) ; + return sStandardHandler_V3 != NULL; +} // ============================================================================ @@ -228,16 +238,15 @@ bool CheckAbort( SessionRef session ) // Standard file handler access // - bool CheckFormatStandard( SessionRef session, XMP_FileFormat format, const StringPtr path ) { WXMP_Error error; XMP_Bool ret = true; - if ( sStandardHandler_V2 == NULL ) + if ( sStandardHandler_V3 == NULL ) { throw XMP_Error( kXMPErr_Unavailable, "StandardHandler suite unavailable" ); } - sStandardHandler_V2->mCheckFormatStandardHandler( session, format, path, ret, &error ); + sStandardHandler_V3->mCheckFormatStandardHandler( session, format, path, ret, &error ); if( error.mErrorID != kXMPErr_NoError ) { @@ -249,17 +258,22 @@ bool CheckFormatStandard( SessionRef session, XMP_FileFormat format, const Strin // ============================================================================ -bool GetXMPStandard( SessionRef session, XMP_FileFormat format, const StringPtr path, std::string& xmpStr, bool* containsXMP ) +bool GetXMPStandard( SessionRef session, XMP_FileFormat format, const StringPtr path, std::string& xmpStr, bool* containsXMP , XMP_OptionBits flags /*= NULL*/, std::string *packet /*= NULL*/ , XMP_PacketInfo *packetInfo /*= NULL*/, ErrorCallbackInfo * errorCallback /*= NULL*/, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr /*= NULL*/ ) { WXMP_Error error; bool ret = true; XMP_StringPtr outXmp= NULL; XMP_Bool cXMP = kXMP_Bool_False; - if ( sStandardHandler_V2 == NULL ) + if ( sStandardHandler_V3 == NULL ) { throw XMP_Error( kXMPErr_Unavailable, "StandardHandler suite unavailable" ); } - sStandardHandler_V2->mGetXMPStandardHandler( session, format, path, &outXmp, &cXMP, &error ); + + XMP_StringPtr inXMP = NULL; + ErrorCallbackBox * errorCallbackBox = NULL; + if( errorCallback != NULL && errorCallback->wrapperProc != 0 ) + errorCallbackBox = new ErrorCallbackBox( errorCallback->wrapperProc, errorCallback->clientProc, errorCallback->context, errorCallback->limit ); + sStandardHandler_V3->mGetXMPwithPacketStandardHandlerWOptions( session, format, path, &outXmp, &cXMP, &error, flags, &inXMP, packetInfo, errorCallbackBox, progCBInfoPtr ); *containsXMP = ConvertXMP_BoolToBool( cXMP ); if( error.mErrorID == kXMPErr_NoFileHandler || error.mErrorID == kXMPErr_BadFileFormat) @@ -270,8 +284,133 @@ bool GetXMPStandard( SessionRef session, XMP_FileFormat format, const StringPtr { throw XMP_Error( error.mErrorID, error.mErrorMsg ); } - xmpStr=outXmp; + xmpStr = outXmp; HostStringReleaseBuffer( (StringPtr)outXmp ) ; + + if ( inXMP != NULL ) + { + if ( packet != NULL ) + packet->assign(inXMP); + HostStringReleaseBuffer( (StringPtr)inXMP ) ; + } + if ( errorCallbackBox != NULL ) + delete errorCallbackBox ; + return ret; +} + +// ============================================================================ + +bool PutXMPStandard( SessionRef session, XMP_FileFormat format, const StringPtr path, const XMP_StringPtr xmpStr, XMP_OptionBits flags /*= NULL */, ErrorCallbackInfo * errorCallback /*= NULL */, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr /*= NULL*/ ) +{ + WXMP_Error error; + bool ret = true; + + if ( sStandardHandler_V3 == NULL ) + { + throw XMP_Error( kXMPErr_Unavailable, "StandardHandler suite unavailable" ); + } + + ErrorCallbackBox * errorCallbackBox = NULL; + if( errorCallback != NULL && errorCallback->wrapperProc != 0 ) + errorCallbackBox = new ErrorCallbackBox( errorCallback->wrapperProc, errorCallback->clientProc, errorCallback->context, errorCallback->limit ); + sStandardHandler_V3->mPutXMPStandardHandler( session, format, path, xmpStr, &error, flags, errorCallbackBox, progCBInfoPtr ); + + if( error.mErrorID == kXMPErr_NoFileHandler || error.mErrorID == kXMPErr_BadFileFormat) + { + ret = false; + } + else if( error.mErrorID != kXMPErr_NoError ) + { + throw XMP_Error( error.mErrorID, error.mErrorMsg ); + } + if ( errorCallbackBox != NULL ) + delete errorCallbackBox ; + return ret; +} + +// ============================================================================ + +bool GetFileModDateStandardHandler( SessionRef session, XMP_FileFormat format, StringPtr path, XMP_DateTime * modDate, XMP_Bool * isSuccess, XMP_OptionBits flags /*= NULL*/ ) +{ + WXMP_Error error; + bool ret = true; + + if ( sStandardHandler_V3 == NULL ) + { + throw XMP_Error( kXMPErr_Unavailable, "StandardHandler suite unavailable" ); + } + + sStandardHandler_V3->mGetFileModDateStandardHandler( session, format, path, modDate, isSuccess, &error, flags ); + + if( error.mErrorID == kXMPErr_NoFileHandler || error.mErrorID == kXMPErr_BadFileFormat) + { + ret = false; + } + else if( error.mErrorID != kXMPErr_NoError ) + { + throw XMP_Error( error.mErrorID, error.mErrorMsg ); + } + return ret; +} + +// ============================================================================ + +static void SetClientStringVector ( void * clientPtr, XMP_StringPtr * arrayPtr, XMP_Uns32 stringCount ) +{ + std::vector<std::string> * vecPtr = (std::vector<std::string> *) (clientPtr); + vecPtr->clear(); + vecPtr->reserve( stringCount ); + for ( XMP_Uns32 i = 0; i < stringCount; i++ ) + { + vecPtr->push_back( arrayPtr[i] ); + } +} + +// ============================================================================ + +bool GetAssociatedResourcesStandardHandler( SessionRef session, XMP_FileFormat format, StringPtr path, std::vector<std::string> * resourceList, XMP_OptionBits flags /*= NULL*/ ) +{ + WXMP_Error error; + bool ret = true; + + if ( sStandardHandler_V3 == NULL ) + { + throw XMP_Error( kXMPErr_Unavailable, "StandardHandler suite unavailable" ); + } + sStandardHandler_V3->mGetAssociatedResourcesStandardHandler( session, format, path, resourceList, SetClientStringVector, &error, flags ); + + if( error.mErrorID == kXMPErr_NoFileHandler || error.mErrorID == kXMPErr_BadFileFormat) + { + ret = false; + } + else if( error.mErrorID != kXMPErr_NoError ) + { + throw XMP_Error( error.mErrorID, error.mErrorMsg ); + } + return ret; +} + +// ============================================================================ + +bool IsMetadataWritableStandardHandler( SessionRef session, XMP_FileFormat format, StringPtr path, XMP_Bool * isWritable, XMP_OptionBits flags /*= NULL*/ ) +{ + WXMP_Error error; + bool ret = true; + + if ( sStandardHandler_V3 == NULL ) + { + throw XMP_Error( kXMPErr_Unavailable, "StandardHandler suite unavailable" ); + } + sStandardHandler_V3->mIsMetadataWritableStandardHandler( session, format, path, isWritable, &error, flags ); + + if( error.mErrorID == kXMPErr_NoFileHandler || error.mErrorID == kXMPErr_BadFileFormat) + { + ret = false; + } + else if( error.mErrorID != kXMPErr_NoError ) + { + throw XMP_Error( error.mErrorID, error.mErrorMsg ); + } return ret; } @@ -297,5 +436,6 @@ void* RequestAPISuite( const char* apiName, XMP_Uns32 apiVersion ) return suite; } +// ============================================================================ } //namespace XMP_PLUGIN diff --git a/XMPFilesPlugins/api/source/HostAPIAccess.h b/XMPFilesPlugins/api/source/HostAPIAccess.h index baae239..cc2a53a 100644 --- a/XMPFilesPlugins/api/source/HostAPIAccess.h +++ b/XMPFilesPlugins/api/source/HostAPIAccess.h @@ -179,14 +179,74 @@ bool CheckFormatStandard( SessionRef session, XMP_FileFormat format, const Strin * This call expects that session refers to a replacement file handler. Otherwise * this call fails with an exception. * - * @param session File handler session (should refer to replacement handler) + * @param session File handler session (should refer to replacement handler) + * @param format The file format identifier + * @param path Path to the file that should be proceeded + * @param xmpStr Reference to serialized XMP packet. Will be populated with the XMP Packet as read by the standard file handler + * @param containsXMP Returns true if the standard handler detected XMP + * @param flags OpenFlags passed during opening a file + * @param packet Returns XMP packet already present in the file, if available + * @param packetInfo Returns already present XMP packet information in the file, if available + * @param errorCallback Points to plugin error callback information + * @param progCBInfoPtr Points to the progress callback information + * @return true on success + */ +bool GetXMPStandard( SessionRef session, XMP_FileFormat format, const StringPtr path, std::string& xmpStr, bool* containsXMP, XMP_OptionBits flags = NULL, std::string *packet = NULL, XMP_PacketInfo *packetInfo = NULL, ErrorCallbackInfo * errorCallback = NULL, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr = NULL ); + +/** @brief Put XMP into standard file handler + * + * Call the standard file handler in order to put XMP into it. + * + * @param session File handler session (should refer to replacement handler) + * @param format The file format identifier + * @param path Path to the file that should be proceeded + * @param xmpStr Contains serialized XMP Packet to be embedded into the standard Handler + * @param flags OpenFlags passed during opening a file + * @param errorCallback Points to plugin error callback information + * @param progCBInfoPtr Points to the progress callback information + * @return true on success + */ +bool PutXMPStandard( SessionRef session, XMP_FileFormat format, const StringPtr path, const XMP_StringPtr xmpStr, XMP_OptionBits flags = NULL, ErrorCallbackInfo * errorCallback = NULL, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr = NULL ); + +/** @brief Getting file modification date from standard file handler + * + * Call the standard file handler in order to retrieve file modification date from it. + * + * @param session File handler session (referring to replacement handler) + * @param format The file format identifier + * @param path Path to the file that should be proceeded + * @param modDate will contain modification date of file obtained from the standard Handler + * @param isSuccess Returns true if the standard handler detected file modification date + * @param flags OpenFlags passed during opening a file + * @return true on success + */ +bool GetFileModDateStandardHandler( SessionRef session, XMP_FileFormat format, StringPtr path, XMP_DateTime * modDate, XMP_Bool * isSuccess, XMP_OptionBits flags = NULL ); + +/** @brief Getting associated resources from standard file handler + * + * Call the standard file handler in order to retrieve all the associated resources with a file + * + * @param session File handler session (referring to replacement handler) + * @param format The file format identifier + * @param path Path to the file that should be proceeded + * @param resourceList will contain resources associated with the file obtained from the standard Handler + * @param flags OpenFlags passed during opening a file + * @return true on success + */ +bool GetAssociatedResourcesStandardHandler( SessionRef session, XMP_FileFormat format, StringPtr path, std::vector<std::string> * resourceList, XMP_OptionBits flags = NULL ); + +/** @brief Checking whether metadata is writable or not into the file from standard file handler + * + * Call the standard file handler in order to check whether the metadata is writable or not into the file. + * + * @param session File handler session (referring to replacement handler) * @param format The file format identifier * @param path Path to the file that should be proceeded - * @param xmpStr Reference to serialized XMP packet. Will be populated with the XMP Packet as read by the standard file handler - * @param containsXMP Returns true if the standard handler detected XMP + * @param isWritable Returns true if the standard handler can write on the file. + * @param flags OpenFlags passed during opening a file * @return true on success */ -bool GetXMPStandard( SessionRef session, XMP_FileFormat format, const StringPtr path, std::string& xmpStr, bool* containsXMP ); +bool IsMetadataWritableStandardHandler( SessionRef session, XMP_FileFormat format, StringPtr path, XMP_Bool * isWritable, XMP_OptionBits flags = NULL ); /** @brief Request additional API suite from the host. * diff --git a/XMPFilesPlugins/api/source/PluginAPIImpl.cpp b/XMPFilesPlugins/api/source/PluginAPIImpl.cpp index ec22cee..e72d711 100644 --- a/XMPFilesPlugins/api/source/PluginAPIImpl.cpp +++ b/XMPFilesPlugins/api/source/PluginAPIImpl.cpp @@ -110,6 +110,32 @@ static XMPErrorID Static_InitializeSession( XMP_StringPtr uid, XMP_StringPtr fil // ============================================================================ +static XMPErrorID Static_InitializeSessionV2( 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 ) +{ + if( wError == NULL ) return kXMPErr_BadParam; + + wError->mErrorID = kXMPErr_PluginSessionInit; + + try + { + *session = PluginRegistry::create(uid, filePath, openFlags, format, handlerFlags, &errorCallbackBox, progCBInfo ); + + if( *session != NULL ) + { + wError->mErrorID = kXMPErr_NoError; + } + } + catch( ... ) + { + HandleException( wError ); + } + + return wError->mErrorID; +} + +// ============================================================================ + static XMPErrorID Static_TerminateSession( SessionRef session, WXMP_Error * wError ) { if( wError == NULL ) return kXMPErr_BadParam; @@ -188,7 +214,7 @@ static XMPErrorID Static_GetFileModDate ( SessionRef session, XMP_Bool * ok, XMP *ok = thiz->getFileModDate ( modDate ); wError->mErrorID = kXMPErr_NoError; } - catch ( ... ) + catch( ... ) { HandleException( wError ); } @@ -211,8 +237,17 @@ static XMPErrorID Static_CacheFileData( SessionRef session, XMP_IORef fileRef, X wError->mErrorID = kXMPErr_NoError; } } - catch( ... ) - { + catch( XMP_Error& error ) { + if ( error.GetID() == kXMPErr_FilePermission ) + { + wError->mErrorID = kXMPErr_FilePermission; + wError->mErrorMsg = "Open, file permission error"; + } + if ( error.GetID() == kXMPErr_BadFileFormat ) + { + wError->mErrorID = kXMPErr_BadFileFormat; + wError->mErrorMsg = "Ill-formed QuickTime file"; + } HandleException( wError ); } @@ -418,6 +453,81 @@ static XMPErrorID Static_IsMetadataWritable( SessionRef session, XMP_Bool * resu } // ============================================================================ +static XMPErrorID Static_ImportToXMPStringWithPacket( SessionRef session, XMP_StringPtr* xmpStr, WXMP_Error * wError, XMP_StringPtr* packetPtr, XMP_PacketInfo * packetInfo ) +{ + if( wError == NULL ) return kXMPErr_BadParam; + + wError->mErrorID = kXMPErr_PluginImportToXMP; + + PluginBase* thiz = (PluginBase*) session; + try + { + if(thiz) + { + thiz->importToXMP( xmpStr, packetPtr, packetInfo ); + wError->mErrorID = kXMPErr_NoError; + } + } + catch( ... ) + { + HandleException( wError ); + } + + return wError->mErrorID; +} + +// ============================================================================ + +static XMPErrorID Static_SetErrorCallback ( SessionRef session, ErrorCallbackBox errorCallbackBox, WXMP_Error * wError ) +{ + if( wError == NULL ) return kXMPErr_BadParam; + + wError->mErrorID = kXMPErr_PluginImportToXMP; + + PluginBase* thiz = (PluginBase*) session; + try + { + if(thiz) + { + thiz->SetErrorCallback( errorCallbackBox.wrapperProc, errorCallbackBox.clientProc, errorCallbackBox.context, errorCallbackBox.limit ); + wError->mErrorID = kXMPErr_NoError; + } + } + catch( ... ) + { + HandleException( wError ); + } + + return wError->mErrorID; +} + +// ============================================================================ + +static XMPErrorID Static_SetProgressCallback ( SessionRef session, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr, WXMP_Error * wError ) +{ + if( wError == NULL ) return kXMPErr_BadParam; + + wError->mErrorID = kXMPErr_PluginImportToXMP; + + PluginBase* thiz = (PluginBase*) session; + try + { + if(thiz) + { + thiz->SetProgressCallback( progCBInfoPtr ); + wError->mErrorID = kXMPErr_NoError; + } + } + catch( ... ) + { + HandleException( wError ); + } + + return wError->mErrorID; +} + +// ============================================================================ + XMPErrorID InitializePlugin( XMP_StringPtr moduleID, PluginAPIRef pluginAPI, WXMP_Error * wError ) { if( wError == NULL ) return kXMPErr_BadParam; @@ -484,6 +594,15 @@ XMPErrorID InitializePlugin( XMP_StringPtr moduleID, PluginAPIRef pluginAPI, WXM pluginAPI->mIsMetadataWritableProc = Static_IsMetadataWritable; } + // version 4 + if( pluginAPI->mSize > offsetof( PluginAPI, mImportToXMPStringWithPacketProc ) ) + { + pluginAPI->mImportToXMPStringWithPacketProc = Static_ImportToXMPStringWithPacket; + pluginAPI->mSetErrorCallbackproc = Static_SetErrorCallback; + pluginAPI->mInitializeSessionV2Proc = Static_InitializeSessionV2; + pluginAPI->mSetProgressCallbackproc = Static_SetProgressCallback; + } + // Compatibility hack for CS6 (plugin version 1): // set mVersion to 1 if pluginAPI is for version 1 // because in CS6 plugin version is used to determine the hostAPI version. diff --git a/XMPFilesPlugins/api/source/PluginBase.cpp b/XMPFilesPlugins/api/source/PluginBase.cpp index 06c53ae..4cf1d05 100644 --- a/XMPFilesPlugins/api/source/PluginBase.cpp +++ b/XMPFilesPlugins/api/source/PluginBase.cpp @@ -8,7 +8,7 @@ // ================================================================================================= #include "PluginBase.h" -#include "source/XMP_LibUtils.hpp" +#include "PluginUtils.h" #include "source/Host_IO.hpp" #include "XMP.incl_cpp" @@ -82,7 +82,7 @@ void PluginBase::FillMetadataFiles( StringVectorRef metadataFiles, SetStringVect for ( size_t i = 0; i < fileCount; ++i ) { ptrArray.push_back ( fileList[i].c_str() ); } - (*SetStringVector) ( metadataFiles, ptrArray.data(), fileCount ); + (*SetStringVector) ( metadataFiles, ptrArray.data(), (XMP_Uns32)fileCount ); } } @@ -114,7 +114,7 @@ void PluginBase::FillAssociatedResources( StringVectorRef resourceList, SetStrin for ( size_t i = 0; i < fileCount; ++i ) { ptrArray.push_back ( resList[i].c_str() ); } - (*SetStringVector) ( resourceList, ptrArray.data(), fileCount ); + (*SetStringVector) ( resourceList, ptrArray.data(), (XMP_Uns32)fileCount ); } } @@ -134,6 +134,12 @@ void PluginBase::FillAssociatedResources( std::vector<std::string> * resourceLis // ============================================================================ // ============================================================================ +void PluginBase::importToXMP( XMP_StringPtr* xmpStr, XMP_StringPtr* packetPtr , XMP_PacketInfo * packetInfo ) +{ + this->importToXMP( xmpStr ); +} + +// ============================================================================ void PluginBase::importToXMP( XMP_StringPtr* xmpStr ) { @@ -235,6 +241,76 @@ bool PluginBase::getXMPStandard( std::string& xmpStr, const std::string* path /* // ============================================================================ +bool PluginBase::getXMPStandard( std::string& xmpStr, XMP_OptionBits flags, const std::string* path /*= NULL*/, bool* containsXMP /*= NULL*/, std::string *packet /*= NULL*/, XMP_PacketInfo *packetInfo /*= NULL*/, ErrorCallbackInfo * errorCallback /*= NULL*/, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr /*= NULL*/ ) +{ + const StringPtr _path = (const StringPtr)( path == NULL ? this->getPath().c_str() : path->c_str() ); + + bool ret = GetXMPStandard( this, this->getFormat(), _path, xmpStr, containsXMP, flags, packet, packetInfo, errorCallback, progCBInfoPtr ); + + return ret; +} + +// ============================================================================ + +bool PluginBase::putXMPStandard( const XMP_StringPtr xmpStr, XMP_OptionBits flags /*= NULL */, const std::string* path /*= NULL*/, ErrorCallbackInfo * errorCallback /*= NULL*/ , XMP_ProgressTracker::CallbackInfo * progCBInfoPtr /*= NULL*/ ) +{ + const StringPtr _path = (const StringPtr)( path == NULL ? this->getPath().c_str() : path->c_str() ); + + bool ret = PutXMPStandard( this, this->getFormat(), _path, xmpStr, flags, errorCallback, progCBInfoPtr ); + + return ret; +} + +// ============================================================================ + +bool PluginBase::getFileModDateStandardHandler( XMP_DateTime * modDate, XMP_Bool * isSuccess, XMP_OptionBits flags /*= NULL */, const std::string* path /*= NULL*/ ) +{ + const StringPtr _path = (const StringPtr)( path == NULL ? this->getPath().c_str() : path->c_str() ); + + bool ret = GetFileModDateStandardHandler( this, this->getFormat(), _path, modDate, isSuccess, flags ); + + return ret; +} + +// ============================================================================ + +bool PluginBase::getAssociatedResourcesStandardHandler( std::vector<std::string> * resourceList, XMP_OptionBits flags /*= NULL */, const std::string* path /*= NULL*/ ) +{ + const StringPtr _path = (const StringPtr)( path == NULL ? this->getPath().c_str() : path->c_str() ); + + bool ret = GetAssociatedResourcesStandardHandler( this, this->getFormat(), _path, resourceList, flags ); + + return ret; +} + +// ============================================================================ + +bool PluginBase::isMetadataWritableStandardHandler( XMP_Bool * isWritable, XMP_OptionBits flags /*= NULL */, const std::string* path /*= NULL*/ ) +{ + const StringPtr _path = (const StringPtr)( path == NULL ? this->getPath().c_str() : path->c_str() ); + + bool ret = IsMetadataWritableStandardHandler( this, this->getFormat(), _path, isWritable, flags ); + + return ret; +} + +// ============================================================================ + +void PluginBase::SetErrorCallback ( XMPFiles_ErrorCallbackWrapper wrapperProc, + XMPFiles_ErrorCallbackProc clientProc, + void * context, + XMP_Uns32 limit ) +{ + this->mErrorCallback.Clear(); + this->mErrorCallback.wrapperProc = wrapperProc; + this->mErrorCallback.clientProc = clientProc; + this->mErrorCallback.context = context; + this->mErrorCallback.limit = limit; + this->mErrorCallback.filePath = mPath; +} + +// ============================================================================ + #if XMP_WinBuild static bool GetModifyDate ( const char* filePath, XMP_DateTime* modifyDate ) diff --git a/XMPFilesPlugins/api/source/PluginBase.h b/XMPFilesPlugins/api/source/PluginBase.h index a827687..dba3105 100644 --- a/XMPFilesPlugins/api/source/PluginBase.h +++ b/XMPFilesPlugins/api/source/PluginBase.h @@ -24,8 +24,10 @@ #include <vector> #include <string> #include "HostAPIAccess.h" +#include "PluginUtils.h" #define TXMP_STRING_TYPE std::string #include "XMP.hpp" +#include "source/XMP_ProgressTracker.hpp" namespace XMP_PLUGIN { @@ -36,7 +38,7 @@ namespace XMP_PLUGIN virtual void cacheFileData( const IOAdapter& file, std::string& xmpStr ); virtual void updateFile( const IOAdapter& file, bool doSafeUpdate, const std::string& xmpStr ); virtual void writeTempFile( const IOAdapter& srcFile, const IOAdapter& tmpFile, const std::string& xmpStr ) ; - virtual void importToXMP( XMP_StringPtr* xmpStr ); + virtual void importToXMP( XMP_StringPtr* xmpStr, XMP_StringPtr* oldPtr = 0, XMP_PacketInfo * packetInfo = 0 ); virtual void exportFromXMP( XMP_StringPtr xmpStr ); First two functions are pure virtual functions so these should be implemented for sure. @@ -64,8 +66,9 @@ namespace XMP_PLUGIN class PluginBase { public: + PluginBase( const std::string& filePath, XMP_Uns32 openFlags, XMP_Uns32 format = 0, XMP_Uns32 handlerFlags = 0 ) - : mPath( filePath ),mHandlerFlags(handlerFlags), mOpenFlags( openFlags ), mFormat( format ) {} + : mPath( filePath ),mHandlerFlags(handlerFlags), mOpenFlags( openFlags ), mFormat( format ), mErrorCallback() {} virtual ~PluginBase(){}; /** @brief Delegator functions which will eventually call the corresponding virtual function. @@ -102,6 +105,77 @@ public: */ bool getXMPStandard( std::string& xmpStr, const std::string* path = NULL, bool* containsXMP = NULL ); + /** @brief Get metadata from standard file handler + * + * Call the standard file handler in order to retrieve XMP from it. + * This call expects that session refers to a replacement file handler. Otherwise + * this call fails with an exception. + * Calls checkFormatStandard internally before calling the actual standard handler. + * + * @param xmpStr Serialized to XMP packet. Will be populated with XMP read from standard handler. + * @param flags OpenFlags passed during opening a file + * @param path Pointer to the path string of the file to be checked. Pass NULL to check the + * file passed in during initialization (see PluginBase::getPath() ) + * @param containsXMP Returns true if the standard handler detected XMP + * @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 + * @param errorCallback Contains pointer to ErrorCallbackInfo + * @param progCBInfoPtr Contains pointer to the CallbackInfo provided by user if any + * @return true on success + */ + bool getXMPStandard( std::string& xmpStr, XMP_OptionBits flags, const std::string* path = NULL, bool* containsXMP = NULL, std::string *packet = NULL, XMP_PacketInfo* packetInfo = NULL, ErrorCallbackInfo * errorCallback = NULL, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr = NULL ); + + /** @brief Putting metadata into file using standard file handler + * + * Call the standard file handler in order to put XMP into it. + * This call expects that session refers to a replacement file handler. Otherwise + * this call fails with an exception. + * Calls checkFormatStandard internally before calling the actual standard handler. + * + * @param xmpStr Serialized to XMP packet. Will be put into file using standard handler. + * @param flags OpenFlags passed during opening a file + * @param path Pointer to the path string of the file to be checked. Pass NULL to check the + * file passed in during initialization (see PluginBase::getPath() ) + * @param errorCallback Contains pointer to ErrorCallbackInfo + * @param progCBInfoPtr Contains pointer to the CallbackInfo provided by user if any + * @return true on success + */ + bool putXMPStandard( const XMP_StringPtr xmpStr, XMP_OptionBits flags = NULL, const std::string* path = NULL, ErrorCallbackInfo * errorCallback = NULL, XMP_ProgressTracker::CallbackInfo * progCBInfoPtr = NULL ); + + /** @brief Getting file modification date from standard file handler + * + * Call the standard file handler in order to retrieve file modification date from it. + * + * @param modDate will contain modification date of file obtained from the standard Handler + * @param isSuccess Returns true if the standard handler detected file modification date + * @param flags OpenFlags passed during opening a file + * @param path Path to the file that should be proceeded + * @return true on success + */ + bool getFileModDateStandardHandler( XMP_DateTime * modDate, XMP_Bool * isSuccess, XMP_OptionBits flags = NULL, const std::string* path = NULL ); + + /** @brief Getting associated resources from standard file handler + * + * Call the standard file handler in order to retrieve file associated resources from it. + * + * @param resourceList will contain resources associated with the file obtained from the standard Handler + * @param flags OpenFlags passed during opening a file + * @param path Path to the file that should be proceeded + * @return true on success + */ + bool getAssociatedResourcesStandardHandler( std::vector<std::string> * resourceList, XMP_OptionBits flags = NULL, const std::string* path = NULL ); + + /** @brief Checking whether metadata is writable or not into the file from standard file handler + * + * Call the standard file handler in order to check whether the metadata is writable or not into the file. + * + * @param isWritable Returns true if the standard handler can write on the file. + * @param flags OpenFlags passed during opening a file + * @param path Path to the file that should be proceeded + * @return true on success + */ + bool isMetadataWritableStandardHandler( XMP_Bool * isWritable, XMP_OptionBits flags = NULL, const std::string* path = NULL ); + /** @brief Get file format * * Get the file format of this handler. @@ -116,7 +190,6 @@ public: */ inline XMP_OptionBits getHandlerFlags() const { return mHandlerFlags; } - /** @brief Return the path to the input file/folder * * Return the path to the input file/folder. Empty if the data source is neither @@ -132,6 +205,8 @@ public: */ inline XMP_OptionBits getOpenFlags() const { return mOpenFlags; } + inline ErrorCallbackInfo * getErrorCallbackInfo() { return &mErrorCallback; } + /** @brief Ask XMPFiles if current operation should be aborted. * * @param doAbort If true and the operation should be aborted then @@ -195,13 +270,18 @@ public: virtual void cacheFileData( const IOAdapter& file, std::string& xmpStr ) = 0; virtual void updateFile( const IOAdapter& file, bool doSafeUpdate, const std::string& xmpStr ) = 0; virtual void writeTempFile( const IOAdapter& srcFile, const IOAdapter& tmpFile, const std::string& xmpStr ) {} - virtual void importToXMP( XMP_StringPtr* xmpStr ); + virtual void importToXMP( XMP_StringPtr* xmpStr, XMP_StringPtr* oldPtr , XMP_PacketInfo * packetInfo ); virtual void exportFromXMP( XMP_StringPtr xmpStr ); + virtual void importToXMP( XMP_StringPtr* xmpStr ); + virtual void SetErrorCallback( XMPFiles_ErrorCallbackWrapper wrapperProc, XMPFiles_ErrorCallbackProc clientProc, void * context, XMP_Uns32 limit ); + virtual void SetProgressCallback( XMP_ProgressTracker::CallbackInfo * progCBInfoPtr ) {} + private: std::string mPath; XMP_OptionBits mHandlerFlags; XMP_OptionBits mOpenFlags; XMP_FileFormat mFormat; + ErrorCallbackInfo mErrorCallback; }; diff --git a/XMPFilesPlugins/api/source/PluginHandler.h b/XMPFilesPlugins/api/source/PluginHandler.h index 21c3d43..d13dcec 100644 --- a/XMPFilesPlugins/api/source/PluginHandler.h +++ b/XMPFilesPlugins/api/source/PluginHandler.h @@ -19,13 +19,16 @@ #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_3 +#define XMP_PLUGIN_VERSION XMP_PLUGIN_VERSION_4 namespace XMP_PLUGIN { @@ -99,6 +102,23 @@ typedef XMPErrorID (*SetHostAPIProc)( HostAPIRef hostAPI, WXMP_Error * wError ); 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. * @@ -246,6 +266,19 @@ typedef XMPErrorID (*FillAssociatedResourcesProc)( SessionRef session, StringVec 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. @@ -267,6 +300,23 @@ typedef XMPErrorID (*ExportFromXMPStringProc)( SessionRef session, XMP_StringPtr */ 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. @@ -312,6 +362,12 @@ struct PluginAPI // version 3 IsMetadataWritableProc mIsMetadataWritableProc; + + // version 4 + ImportToXMPStringWithPacketProc mImportToXMPStringWithPacketProc; + SetErrorCallbackproc mSetErrorCallbackproc; + InitializeSessionV2Proc mInitializeSessionV2Proc; + SetProgressCallbackproc mSetProgressCallbackproc; }; diff --git a/XMPFilesPlugins/api/source/PluginRegistry.cpp b/XMPFilesPlugins/api/source/PluginRegistry.cpp index 1f7c340..4831eff 100644 --- a/XMPFilesPlugins/api/source/PluginRegistry.cpp +++ b/XMPFilesPlugins/api/source/PluginRegistry.cpp @@ -42,13 +42,13 @@ void PluginRegistry::registerHandler( const PluginCreatorBase* inCreator ) // ============================================================================ /*static*/ -PluginBase* PluginRegistry::create( const std::string& uid, const std::string& filePath, XMP_Uns32 openFlags, XMP_Uns32 format, XMP_Uns32 handlerFlags ) +PluginBase* PluginRegistry::create( const std::string& uid, const std::string& filePath, XMP_Uns32 openFlags, XMP_Uns32 format, XMP_Uns32 handlerFlags, ErrorCallbackBox * errorCallbackbox /* = 0*/, XMP_ProgressTracker::CallbackInfo * progCBInfo /*= 0*/ ) { if( msRegistry != NULL ) { - RegistryEntryMap::const_iterator iter = msRegistry->mRegistryEntries.find(uid); + RegistryEntryMap::const_iterator iter = msRegistry->mRegistryEntries.find( uid ); if( iter != msRegistry->mRegistryEntries.end() ) - return iter->second->create(filePath, openFlags, format, handlerFlags); + return iter->second->create( filePath, openFlags, format, handlerFlags, errorCallbackbox, progCBInfo ); } return NULL; diff --git a/XMPFilesPlugins/api/source/PluginRegistry.h b/XMPFilesPlugins/api/source/PluginRegistry.h index acfe3bf..f694d08 100644 --- a/XMPFilesPlugins/api/source/PluginRegistry.h +++ b/XMPFilesPlugins/api/source/PluginRegistry.h @@ -52,9 +52,11 @@ public: * @param format File format id the class is created for * @param handlerFlags According handler flags * @param filePath FilePath of the file which is to be opened. + * @param errorCallbackbox Pointer to error callback info + * @param progCBInfo Points to the progress callback notification information * @return Pointer to file Handler instance. */ - static PluginBase* create( const std::string& uid, const std::string& filePath, XMP_Uns32 openFlags, XMP_Uns32 format, XMP_Uns32 handlerFlags ); + static PluginBase* create( const std::string& uid, const std::string& filePath, XMP_Uns32 openFlags, XMP_Uns32 format, XMP_Uns32 handlerFlags, ErrorCallbackBox * errorCallbackbox = 0, XMP_ProgressTracker::CallbackInfo * progCBInfo = 0 ); /** @brief Check whether the input file /a filePath is supported by the file handler with uid /a uid. * @param uid Unique identifier string (uid) of the file handler. @@ -98,8 +100,8 @@ public: PluginCreatorBase() {} virtual ~PluginCreatorBase() {} - virtual PluginBase* create( const std::string& filePath, XMP_Uns32 openFlags, XMP_Uns32 format, XMP_Uns32 handlerFlags ) const = 0; - + virtual PluginBase* create( const std::string& filePath, XMP_Uns32 openFlags, XMP_Uns32 format, XMP_Uns32 handlerFlags, ErrorCallbackBox * errorCallbackbox = 0, XMP_ProgressTracker::CallbackInfo * progCBInfo = 0 ) const = 0; + /** A File handler should provide either checkFileFormat if it is OwningHandler or NormalHandler * OR it should provide checkFolderFormat if it is FolderHandler. Default implementation returns false * which mean the handler does not support the file format. @@ -146,13 +148,18 @@ public: * @param openFlags Flags that describe the desired access. * @param format File format id the class is created for * @param handlerFlags According handler flags + * @param errorCallbackbox Pointer to error callback info + * @param progCBInfo Points to the progress callback notification information * @return Pointer to file Handler instance. */ - inline PluginBase* create( const std::string& filePath, XMP_Uns32 openFlags, XMP_Uns32 format, XMP_Uns32 handlerFlags ) const + inline PluginBase* create( const std::string& filePath, XMP_Uns32 openFlags, XMP_Uns32 format, XMP_Uns32 handlerFlags, ErrorCallbackBox * errorCallbackBox = 0, XMP_ProgressTracker::CallbackInfo * progCBInfo = 0 ) const { - TFileHandler* instance = new TFileHandler(filePath, openFlags, format, handlerFlags); + TFileHandler* instance = new TFileHandler(filePath, openFlags, format, handlerFlags ); PluginBase* handler = dynamic_cast<PluginBase*>(instance); - + if ( errorCallbackBox != 0 && errorCallbackBox->wrapperProc != 0 ) + handler->SetErrorCallback( errorCallbackBox->wrapperProc, errorCallbackBox->clientProc, errorCallbackBox->context, errorCallbackBox->limit ); + if( progCBInfo != 0 ) + handler->SetProgressCallback( progCBInfo ); return handler; } diff --git a/XMPFilesPlugins/api/source/PluginUtils.cpp b/XMPFilesPlugins/api/source/PluginUtils.cpp new file mode 100644 index 0000000..cdae5aa --- /dev/null +++ b/XMPFilesPlugins/api/source/PluginUtils.cpp @@ -0,0 +1,57 @@ +// ================================================================================================= +// ADOBE SYSTEMS INCORPORATED +// Copyright 2014 Adobe Systems Incorporated +// 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. +// ================================================================================================= + +#include "XMP_Const.h" +#include "source/XMP_LibUtils.hpp" +#include "PluginUtils.h" + +namespace XMP_PLUGIN +{ + // ================================================================================================= + // ErrorCallbackInfo::CanNotify() + // ==================================== + bool ErrorCallbackInfo::CanNotify() const + { + XMP_Assert ( (this->clientProc == 0) || (this->wrapperProc != 0) ); + return ( this->clientProc != 0 ); + } // ErrorCallbackInfo::CanNotify() + + // ================================================================================================= + // ErrorCallbackInfo::ClientCallbackWrapper() + // ==================================== + bool ErrorCallbackInfo::ClientCallbackWrapper ( XMP_StringPtr filePath, + XMP_ErrorSeverity severity, + XMP_Int32 cause, + XMP_StringPtr messsage ) const + { + + XMP_StringPtr filePathPtr = filePath; + if ( filePathPtr == 0 ) { + filePathPtr = this->filePath.c_str(); + } + + XMP_Bool retValue = (*this->wrapperProc) ( this->clientProc, this->context, filePathPtr, severity, cause, messsage ); + return ConvertXMP_BoolToBool(retValue); + } // ErrorCallbackInfo::ClientCallbackWrapper() + + // ================================================================================================= + // ErrorNotifyClient + // =================================== + // Plugin method to throw exception + void ErrorNotifyClient( GenericErrorCallback * errCBptr, XMP_ErrorSeverity severity, XMP_Error & error ) + { + if (errCBptr) + errCBptr->NotifyClient( severity, error ); + else { + if ( severity != kXMPErrSev_Recoverable ) + throw error; + } + } // ErrorNotifyClient() + +} // namespace XMP_PLUGIN
\ No newline at end of file diff --git a/XMPFilesPlugins/api/source/PluginUtils.h b/XMPFilesPlugins/api/source/PluginUtils.h new file mode 100644 index 0000000..287167e --- /dev/null +++ b/XMPFilesPlugins/api/source/PluginUtils.h @@ -0,0 +1,44 @@ +#ifndef __PLUGIN_UTILS_H__ +#define __PLUGIN_UTILS_H__ 1 + +// ================================================================================================= +// ADOBE SYSTEMS INCORPORATED +// Copyright 2014 Adobe Systems Incorporated +// 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. +// ================================================================================================= + +#include "XMP_Const.h" +#include "source/XMP_LibUtils.hpp" + +namespace XMP_PLUGIN +{ + class ErrorCallbackInfo : public GenericErrorCallback { + public: + XMPFiles_ErrorCallbackWrapper wrapperProc; + XMPFiles_ErrorCallbackProc clientProc; + void * context; + std::string filePath; + + ErrorCallbackInfo(): wrapperProc(0), clientProc(0), context(0) {}; + + void Clear() { + this->wrapperProc = 0; this->clientProc = 0; this->context = 0; + GenericErrorCallback::Clear(); + }; + + bool CanNotify() const; + + bool ClientCallbackWrapper( + XMP_StringPtr filePath, + XMP_ErrorSeverity severity, + XMP_Int32 cause, + XMP_StringPtr messsage) const; + }; + + void ErrorNotifyClient( GenericErrorCallback * errCBptr, XMP_ErrorSeverity severity, XMP_Error & error); +} + +#endif // __PLUGIN_UTILS_H__ |