diff options
Diffstat (limited to 'XMPFilesPlugins/api/source/HostAPIAccess.cpp')
-rw-r--r-- | XMPFilesPlugins/api/source/HostAPIAccess.cpp | 156 |
1 files changed, 148 insertions, 8 deletions
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 |