# HG changeset patch # User Sebastien Jodogne # Date 1581615893 -3600 # Node ID adb6d8b49283cd2b26929eda5be3a924ce47ca48 # Parent 6e5b3ae8825ce7e68ba508f0d835e7e596988a6c# Parent c8d8c3b5f47cff18ae55b0e5aa741e783fd5b39a integration mainline->storage-commitment diff -r 6e5b3ae8825c -r adb6d8b49283 Core/Enumerations.h --- 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 }; diff -r 6e5b3ae8825c -r adb6d8b49283 Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- 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 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 diff -r 6e5b3ae8825c -r adb6d8b49283 Plugins/Samples/Common/OrthancPluginCppWrapper.h --- 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