changeset 1730:bc34c69b594a

New URI "/tools/shutdown" to stop Orthanc from the REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 21 Oct 2015 10:34:29 +0200
parents 9d8bb6bc2890
children b6f656a0bf2c
files NEWS OrthancServer/OrthancRestApi/OrthancRestApi.cpp OrthancServer/OrthancRestApi/OrthancRestApi.h OrthancServer/main.cpp
diffstat 4 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Oct 20 11:22:50 2015 +0200
+++ b/NEWS	Wed Oct 21 10:34:29 2015 +0200
@@ -6,6 +6,7 @@
 * "/tools/create-dicom": Support of hierarchical structures (creation of sequences)
 * "/modify" can insert/modify sequences
 * "/series/.../ordered-slices" to order the slices of a 2D+t or 3D image
+* New URI "/tools/shutdown" to stop Orthanc from the REST API
 * New URIs for attachments: ".../compress", ".../uncompress" and ".../is-compressed"
 
 Plugins
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Tue Oct 20 11:22:50 2015 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Wed Oct 21 10:34:29 2015 +0200
@@ -59,11 +59,20 @@
 
   void OrthancRestApi::ResetOrthanc(RestApiPostCall& call)
   {
+    OrthancRestApi::GetApi(call).leaveBarrier_ = true;
     OrthancRestApi::GetApi(call).resetRequestReceived_ = true;
     call.GetOutput().AnswerBuffer("{}", "application/json");
   }
 
 
+  void OrthancRestApi::ShutdownOrthanc(RestApiPostCall& call)
+  {
+    OrthancRestApi::GetApi(call).leaveBarrier_ = true;
+    call.GetOutput().AnswerBuffer("{}", "application/json");
+    LOG(WARNING) << "Shutdown request received";
+  }
+
+
 
 
 
@@ -99,6 +108,7 @@
 
   OrthancRestApi::OrthancRestApi(ServerContext& context) : 
     context_(context),
+    leaveBarrier_(false),
     resetRequestReceived_(false)
   {
     RegisterSystem();
@@ -114,6 +124,7 @@
     // Auto-generated directories
     Register("/tools", RestApi::AutoListChildren);
     Register("/tools/reset", ResetOrthanc);
+    Register("/tools/shutdown", ShutdownOrthanc);
     Register("/instances/{id}/frames/{frame}", RestApi::AutoListChildren);
   }
 
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.h	Tue Oct 20 11:22:50 2015 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestApi.h	Wed Oct 21 10:34:29 2015 +0200
@@ -49,6 +49,7 @@
 
   private:
     ServerContext& context_;
+    bool leaveBarrier_;
     bool resetRequestReceived_;
 
     void RegisterSystem();
@@ -65,10 +66,17 @@
 
     static void ResetOrthanc(RestApiPostCall& call);
 
+    static void ShutdownOrthanc(RestApiPostCall& call);
+
   public:
     OrthancRestApi(ServerContext& context);
 
-    const bool& ResetRequestReceivedFlag() const
+    const bool& LeaveBarrierFlag() const
+    {
+      return leaveBarrier_;
+    }
+
+    bool IsResetRequestReceived() const
     {
       return resetRequestReceived_;
     }
--- a/OrthancServer/main.cpp	Tue Oct 20 11:22:50 2015 +0200
+++ b/OrthancServer/main.cpp	Wed Oct 21 10:34:29 2015 +0200
@@ -476,8 +476,8 @@
 
   context.GetLua().Execute("Initialize");
 
-  Toolbox::ServerBarrier(restApi.ResetRequestReceivedFlag());
-  bool restart = restApi.ResetRequestReceivedFlag();
+  Toolbox::ServerBarrier(restApi.LeaveBarrierFlag());
+  bool restart = restApi.IsResetRequestReceived();
 
   context.GetLua().Execute("Finalize");