changeset 3668:adb6d8b49283 storage-commitment

integration mainline->storage-commitment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 13 Feb 2020 18:44:53 +0100
parents 6e5b3ae8825c (current diff) c8d8c3b5f47c (diff)
children e64432336055
files Core/Enumerations.h Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Plugins/Samples/Common/OrthancPluginCppWrapper.h
diffstat 3 files changed, 91 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Enumerations.h	Thu Feb 13 11:34:00 2020 +0100
+++ b/Core/Enumerations.h	Thu Feb 13 18:44:53 2020 +0100
@@ -314,7 +314,7 @@
 
     /**
      * {summary}{Graylevel, unsigned 64bpp image.}
-     * {description}{The image is graylevel. Each pixel is unsigned and stored in 4 bytes.}
+     * {description}{The image is graylevel. Each pixel is unsigned and stored in 8 bytes.}
      **/
     PixelFormat_Grayscale64 = 10
   };
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Thu Feb 13 11:34:00 2020 +0100
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Thu Feb 13 18:44:53 2020 +0100
@@ -2159,6 +2159,89 @@
     }
   }
 
+
+  void OrthancJob::SubmitFromRestApiPost(OrthancPluginRestOutput* output,
+                                         const Json::Value& body,
+                                         OrthancJob* job)
+  {
+    static const char* KEY_SYNCHRONOUS = "Synchronous";
+    static const char* KEY_ASYNCHRONOUS = "Asynchronous";
+    static const char* KEY_PRIORITY = "Priority";
+
+    std::auto_ptr<OrthancJob> protection(job);
+  
+    if (body.type() != Json::objectValue)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
+                                      "Expected a JSON object in the body");
+    }
+
+    bool synchronous = true;
+  
+    if (body.isMember(KEY_SYNCHRONOUS))
+    {
+      if (body[KEY_SYNCHRONOUS].type() != Json::booleanValue)
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
+                                        "Option \"" + std::string(KEY_SYNCHRONOUS) +
+                                        "\" must be Boolean");
+      }
+      else
+      {
+        synchronous = body[KEY_SYNCHRONOUS].asBool();
+      }
+    }
+
+    if (body.isMember(KEY_ASYNCHRONOUS))
+    {
+      if (body[KEY_ASYNCHRONOUS].type() != Json::booleanValue)
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
+                                        "Option \"" + std::string(KEY_ASYNCHRONOUS) +
+                                        "\" must be Boolean");
+      }
+      else
+      {
+        synchronous = !body[KEY_ASYNCHRONOUS].asBool();
+      }
+    }
+
+    int priority = 0;
+
+    if (body.isMember(KEY_PRIORITY))
+    {
+      if (body[KEY_PRIORITY].type() != Json::booleanValue)
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
+                                        "Option \"" + std::string(KEY_PRIORITY) +
+                                        "\" must be an integer");
+      }
+      else
+      {
+        priority = !body[KEY_PRIORITY].asInt();
+      }
+    }
+  
+    Json::Value result;
+
+    if (synchronous)
+    {
+      OrthancPlugins::OrthancJob::SubmitAndWait(result, protection.release(), priority);
+    }
+    else
+    {
+      std::string id = OrthancPlugins::OrthancJob::Submit(protection.release(), priority);
+
+      result = Json::objectValue;
+      result["ID"] = id;
+      result["Path"] = "/jobs/" + id;
+    }
+
+    std::string s = result.toStyledString();
+    OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(),
+                              s.size(), "application/json");
+  }
+
 #endif
 
 
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Thu Feb 13 11:34:00 2020 +0100
+++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Thu Feb 13 18:44:53 2020 +0100
@@ -784,6 +784,13 @@
     static void SubmitAndWait(Json::Value& result,
                               OrthancJob* job /* takes ownership */,
                               int priority);
+
+    // Submit a job from a POST on the REST API with the same
+    // conventions as in the Orthanc core (according to the
+    // "Synchronous" and "Priority" options)
+    static void SubmitFromRestApiPost(OrthancPluginRestOutput* output,
+                                      const Json::Value& body,
+                                      OrthancJob* job);
   };
 #endif