diff Plugins/Include/orthanc/OrthancCPlugin.h @ 2815:925d8dc03a23

unserialization of jobs from plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Sep 2018 16:34:21 +0200
parents 7d1d3136f6cf
children a47938d99dfa
line wrap: on
line diff
--- a/Plugins/Include/orthanc/OrthancCPlugin.h	Fri Sep 07 10:09:17 2018 +0200
+++ b/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Sep 11 16:34:21 2018 +0200
@@ -423,7 +423,6 @@
     _OrthancPluginService_CallHttpClient2 = 27,
     _OrthancPluginService_GenerateUuid = 28,
     _OrthancPluginService_RegisterPrivateDictionaryTag = 29,
-    _OrthancPluginService_SubmitJob = 30,
 
     /* Registration of callbacks */
     _OrthancPluginService_RegisterRestCallback = 1000,
@@ -437,7 +436,6 @@
     _OrthancPluginService_RegisterFindCallback = 1008,
     _OrthancPluginService_RegisterMoveCallback = 1009,
     _OrthancPluginService_RegisterIncomingHttpRequestFilter2 = 1010,
-    _OrthancPluginService_RegisterJobsUnserializer = 1011,
 
     /* Sending answers to REST calls */
     _OrthancPluginService_AnswerBuffer = 2000,
@@ -529,6 +527,12 @@
     _OrthancPluginService_GetPeerName = 8004,
     _OrthancPluginService_GetPeerUrl = 8005,
     _OrthancPluginService_CallPeerApi = 8006,
+
+    /* Primitives for handling jobs (new in 1.4.2) */
+    _OrthancPluginService_CreateJob = 9000,
+    _OrthancPluginService_FreeJob = 9001,
+    _OrthancPluginService_SubmitJob = 9002,
+    _OrthancPluginService_RegisterJobsUnserializer = 9003,
     
     _OrthancPluginService_INTERNAL = 0x7fffffff
   } _OrthancPluginService;
@@ -1272,7 +1276,10 @@
 
 
 
-  typedef void (*OrthancPluginJobFree) (void* job);
+
+  
+  typedef struct _OrthancPluginJob_t OrthancPluginJob;
+  typedef void (*OrthancPluginJobFinalize) (void* job);
   typedef float (*OrthancPluginJobGetProgress) (void* job);
   typedef const char* (*OrthancPluginJobGetContent) (void* job);
   typedef const char* (*OrthancPluginJobGetSerialized) (void* job);
@@ -1280,8 +1287,8 @@
   typedef OrthancPluginErrorCode (*OrthancPluginJobStop) (void* job, 
                                                           OrthancPluginJobStopReason reason);
   typedef OrthancPluginErrorCode (*OrthancPluginJobReset) (void* job);
-  typedef OrthancPluginErrorCode (*OrthancPluginJobsUnserializer) (const char* jobType,
-                                                                   const char* serialized);
+  typedef OrthancPluginJob* (*OrthancPluginJobsUnserializer) (const char* jobType,
+                                                              const char* serialized);
   
 
 
@@ -6041,12 +6048,13 @@
 
 
 
+
+
   typedef struct
   {
-    char**                          resultId;
+    OrthancPluginJob**              target;
     void                           *job;
-    OrthancPluginJobFree            freeJob;
-    int                             priority;
+    OrthancPluginJobFinalize        finalize;
     const char                     *type;
     OrthancPluginJobGetProgress     getProgress;
     OrthancPluginJobGetContent      getContent;
@@ -6054,13 +6062,12 @@
     OrthancPluginJobStep            step;
     OrthancPluginJobStop            stop;
     OrthancPluginJobReset           reset;
-  } _OrthancPluginSubmitJob;
-
-  ORTHANC_PLUGIN_INLINE char *OrthancPluginSubmitJob(
+  } _OrthancPluginCreateJob;
+
+  ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob(
     OrthancPluginContext           *context,
     void                           *job,
-    OrthancPluginJobFree            freeJob,
-    int                             priority,
+    OrthancPluginJobFinalize        finalize,
     const char                     *type,
     OrthancPluginJobGetProgress     getProgress,
     OrthancPluginJobGetContent      getContent,
@@ -6069,6 +6076,65 @@
     OrthancPluginJobStop            stop,
     OrthancPluginJobReset           reset)
   {
+    OrthancPluginJob* target = NULL;
+
+    _OrthancPluginCreateJob params;
+    memset(&params, 0, sizeof(params));
+
+    params.target = &target;
+    params.job = job;
+    params.finalize = finalize;
+    params.type = type;
+    params.getProgress = getProgress;
+    params.getContent = getContent;
+    params.getSerialized = getSerialized;
+    params.step = step;
+    params.stop = stop;
+    params.reset = reset;
+
+    if (context->InvokeService(context, _OrthancPluginService_CreateJob, &params) != OrthancPluginErrorCode_Success ||
+        target == NULL)
+    {
+      /* Error */
+      return NULL;
+    }
+    else
+    {
+      return target;
+    }
+  }
+
+
+  typedef struct
+  {
+    OrthancPluginJob*   job;
+  } _OrthancPluginFreeJob;
+
+  ORTHANC_PLUGIN_INLINE void  OrthancPluginFreeJob(
+    OrthancPluginContext* context, 
+    OrthancPluginJob*     job)
+  {
+    _OrthancPluginFreeJob params;
+    params.job = job;
+
+    context->InvokeService(context, _OrthancPluginService_FreeJob, &params);
+  }
+
+
+  
+
+  typedef struct
+  {
+    char**             resultId;
+    OrthancPluginJob  *job;
+    int                priority;
+  } _OrthancPluginSubmitJob;
+
+  ORTHANC_PLUGIN_INLINE char *OrthancPluginSubmitJob(
+    OrthancPluginContext   *context,
+    OrthancPluginJob       *job,
+    int                     priority)
+  {
     char* resultId = NULL;
 
     _OrthancPluginSubmitJob params;
@@ -6076,15 +6142,7 @@
 
     params.resultId = &resultId;
     params.job = job;
-    params.freeJob = freeJob;
     params.priority = priority;
-    params.type = type;
-    params.getProgress = getProgress;
-    params.getContent = getContent;
-    params.getSerialized = getSerialized;
-    params.step = step;
-    params.stop = stop;
-    params.reset = reset;
 
     if (context->InvokeService(context, _OrthancPluginService_SubmitJob, &params) != OrthancPluginErrorCode_Success ||
         resultId == NULL)