diff Plugins/OrthancCPlugin/OrthancCPlugin.h @ 899:bb0a51561016 plugins

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Jun 2014 13:29:09 +0200
parents 7000fc86fe62
children 1b92ce45cc8d
line wrap: on
line diff
--- a/Plugins/OrthancCPlugin/OrthancCPlugin.h	Wed Jun 18 09:18:28 2014 +0200
+++ b/Plugins/OrthancCPlugin/OrthancCPlugin.h	Wed Jun 18 13:29:09 2014 +0200
@@ -110,18 +110,35 @@
 
   typedef enum 
   {
+    /* Generic services */
     OrthancPluginService_LogInfo = 1,
     OrthancPluginService_LogWarning = 2,
-    OrthancPluginService_LogError = 3
+    OrthancPluginService_LogError = 3,
+
+    /* Registration of callbacks */
+    OrthancPluginService_RegisterRestCallback = 1000,
+
+    /* Sending answers to REST calls */
+    OrthancPluginService_AnswerBuffer = 2000
   } OrthancPluginService;
 
+  typedef struct
+  {
+    OrthancPluginHttpMethod method;
+
+    /* For GET requests */
+    const char* const*      getKeys;
+    const char* const*      getValues;
+    uint32_t                getCount;
+
+    /* For POST and PUT requests */
+    const char*             body;
+    uint32_t                bodySize;
+  } OrthancPluginHttpRequest;
+
   typedef int32_t (*OrthancPluginRestCallback) (OrthancPluginRestOutput* output,
-                                                OrthancPluginHttpMethod method,
                                                 const char* url,
-                                                const char* const* getKeys,
-                                                const char* const* getValues,
-                                                uint32_t getSize,
-                                                const char* body, uint32_t bodySize);
+                                                const OrthancPluginHttpRequest* request);
 
   typedef struct OrthancPluginContext_t
   {
@@ -131,18 +148,24 @@
     void (*FreeBuffer) (void* buffer);
     int32_t (*InvokeService) (struct OrthancPluginContext_t* context,
                               OrthancPluginService service,
-                              const void* parameters);
+                              const void* params);
+  } OrthancPluginContext;
+
 
-    /* REST API */
-    void (*RegisterRestCallback) (const struct OrthancPluginContext_t* context,
-                                  const char* pathRegularExpression, 
-                                  OrthancPluginRestCallback callback);
+  typedef struct
+  {
+    const char* pathRegularExpression;
+    OrthancPluginRestCallback callback;
+  } OrthancPluginRestCallbackParams;
+
 
-    void (*AnswerBuffer) (OrthancPluginRestOutput* output,
-                          const char* answer,
-                          uint32_t answerSize,
-                          const char* mimeType);
-  } OrthancPluginContext;
+  typedef struct
+  {
+    OrthancPluginRestOutput* output;
+    const char*              answer;
+    uint32_t                 answerSize;
+    const char*              mimeType;
+  } OrthancPluginAnswerBufferParams;
 
 
   ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(OrthancPluginContext* context,
@@ -166,6 +189,32 @@
   }
 
 
+  ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback(OrthancPluginContext* context,
+                                                               const char* pathRegularExpression,
+                                                               OrthancPluginRestCallback callback)
+  {
+    OrthancPluginRestCallbackParams params;
+    params.pathRegularExpression = pathRegularExpression;
+    params.callback = callback;
+    context->InvokeService(context, OrthancPluginService_RegisterRestCallback, &params);
+  }
+
+
+  ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer(OrthancPluginContext*    context,
+                                                       OrthancPluginRestOutput* output,
+                                                       const char*              answer,
+                                                       uint32_t                 answerSize,
+                                                       const char*              mimeType)
+  {
+    OrthancPluginAnswerBufferParams params;
+    params.output = output;
+    params.answer = answer;
+    params.answerSize = answerSize;
+    params.mimeType = mimeType;
+    context->InvokeService(context, OrthancPluginService_AnswerBuffer, &params);
+  }
+
+
 
   /**
      Each plugin must define 4 functions, whose signature are: