# HG changeset patch # User Sebastien Jodogne # Date 1440671529 -7200 # Node ID 235d89817b89baaab62a3c3b8cbf744269cee338 # Parent d73124f6b43900cd90a1fbfd3f796ab1cfe54aa0 OrthancPluginGetErrorDescription diff -r d73124f6b439 -r 235d89817b89 NEWS --- a/NEWS Thu Aug 27 11:35:16 2015 +0200 +++ b/NEWS Thu Aug 27 12:32:09 2015 +0200 @@ -22,6 +22,7 @@ * New function "OrthancPluginBufferCompression()" to (un)compress memory buffers * New function "OrthancPluginReadFile()" to read files from the filesystem * New function "OrthancPluginWriteFile()" to write files to the filesystem +* New function "OrthancPluginGetErrorDescription()" to convert error codes to strings * Plugins have access to explicit error codes Maintenance diff -r d73124f6b439 -r 235d89817b89 Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Thu Aug 27 11:35:16 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu Aug 27 12:32:09 2015 +0200 @@ -1220,6 +1220,14 @@ return true; } + case _OrthancPluginService_GetErrorDescription: + { + const _OrthancPluginGetErrorDescription& p = + *reinterpret_cast(parameters); + *(p.target) = EnumerationToString(static_cast(p.error)); + return true; + } + default: // This service is unknown by the Orthanc plugin engine return false; diff -r d73124f6b439 -r 235d89817b89 Plugins/Include/orthanc/OrthancCPlugin.h --- a/Plugins/Include/orthanc/OrthancCPlugin.h Thu Aug 27 11:35:16 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Thu Aug 27 12:32:09 2015 +0200 @@ -354,6 +354,7 @@ _OrthancPluginService_BufferCompression = 14, _OrthancPluginService_ReadFile = 15, _OrthancPluginService_WriteFile = 16, + _OrthancPluginService_GetErrorDescription = 17, /* Registration of callbacks */ _OrthancPluginService_RegisterRestCallback = 1000, @@ -372,6 +373,7 @@ _OrthancPluginService_SetHttpHeader = 2007, _OrthancPluginService_StartMultipartAnswer = 2008, _OrthancPluginService_SendMultipartItem = 2009, + _OrthancPluginService_SendHttpStatus = 2010, /* Access to the Orthanc database and API */ _OrthancPluginService_GetDicomForInstance = 3000, @@ -2452,6 +2454,45 @@ } + + typedef struct + { + const char** target; + OrthancPluginErrorCode error; + } _OrthancPluginGetErrorDescription; + + /** + * @brief Get the description of a given error code. + * + * This function returns the description of a given error code. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param code The error code of interest. + * @return The error description. This is a statically-allocated + * string, do not free it. + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription( + OrthancPluginContext* context, + OrthancPluginErrorCode error) + { + const char* result = NULL; + + _OrthancPluginGetErrorDescription params; + params.target = &result; + params.error = error; + + if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, ¶ms) || + result == NULL) + { + return "Unknown error code"; + } + else + { + return result; + } + } + + #ifdef __cplusplus } #endif