changeset 1593:235d89817b89

OrthancPluginGetErrorDescription
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Aug 2015 12:32:09 +0200
parents d73124f6b439
children 2bac60a4f584
files NEWS Plugins/Engine/OrthancPlugins.cpp Plugins/Include/orthanc/OrthancCPlugin.h
diffstat 3 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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<const _OrthancPluginGetErrorDescription*>(parameters);
+        *(p.target) = EnumerationToString(static_cast<ErrorCode>(p.error));
+        return true;
+      }
+
       default:
         // This service is unknown by the Orthanc plugin engine
         return false;
--- 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, &params) ||
+        result == NULL)
+    {
+      return "Unknown error code";
+    }
+    else
+    {
+      return result;
+    }
+  }
+
+
 #ifdef  __cplusplus
 }
 #endif