changeset 2801:3ee82c7313e7

New events in change callbacks: "UpdatedPeers" and "UpdatedModalities"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 Aug 2018 13:52:54 +0200
parents dc7330089736
children c48ddc902e3e
files NEWS OrthancServer/OrthancInitialization.cpp OrthancServer/OrthancInitialization.h OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Plugins/Engine/OrthancPlugins.h Plugins/Include/orthanc/OrthancCPlugin.h
diffstat 6 files changed, 133 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Aug 23 13:11:48 2018 +0200
+++ b/NEWS	Thu Aug 23 13:52:54 2018 +0200
@@ -10,7 +10,7 @@
 -------
 
 * New primitives to access Orthanc peers from plugins
-
+* New events in change callbacks: "UpdatedPeers" and "UpdatedModalities"
 
 Maintenance
 -----------
--- a/OrthancServer/OrthancInitialization.cpp	Thu Aug 23 13:11:48 2018 +0200
+++ b/OrthancServer/OrthancInitialization.cpp	Thu Aug 23 13:52:54 2018 +0200
@@ -39,6 +39,7 @@
 #endif
 
 #include "OrthancInitialization.h"
+#include "ServerContext.h"
 
 #include "../Core/HttpClient.h"
 #include "../Core/Logging.h"
@@ -894,100 +895,140 @@
   }
 
 
-  void Configuration::UpdateModality(const std::string& symbolicName,
+  void Configuration::UpdateModality(ServerContext& context,
+                                     const std::string& symbolicName,
                                      const RemoteModalityParameters& modality)
   {
-    boost::recursive_mutex::scoped_lock lock(globalMutex_);
+    {
+      boost::recursive_mutex::scoped_lock lock(globalMutex_);
+
+      if (!configuration_.isMember("DicomModalities"))
+      {
+        configuration_["DicomModalities"] = Json::objectValue;
+      }
 
-    if (!configuration_.isMember("DicomModalities"))
-    {
-      configuration_["DicomModalities"] = Json::objectValue;
+      Json::Value& modalities = configuration_["DicomModalities"];
+      if (modalities.type() != Json::objectValue)
+      {
+        LOG(ERROR) << "Bad file format for modality: " << symbolicName;
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
+
+      modalities.removeMember(symbolicName);
+
+      Json::Value v;
+      modality.ToJson(v);
+      modalities[symbolicName] = v;
     }
 
-    Json::Value& modalities = configuration_["DicomModalities"];
-    if (modalities.type() != Json::objectValue)
+#if ORTHANC_ENABLE_PLUGINS == 1
+    if (context.HasPlugins())
     {
-      LOG(ERROR) << "Bad file format for modality: " << symbolicName;
-      throw OrthancException(ErrorCode_BadFileFormat);
+      context.GetPlugins().SignalUpdatedModalities();
     }
-
-    modalities.removeMember(symbolicName);
-
-    Json::Value v;
-    modality.ToJson(v);
-    modalities[symbolicName] = v;
+#endif
   }
   
 
-  void Configuration::RemoveModality(const std::string& symbolicName)
+  void Configuration::RemoveModality(ServerContext& context,
+                                     const std::string& symbolicName)
   {
-    boost::recursive_mutex::scoped_lock lock(globalMutex_);
+    {
+      boost::recursive_mutex::scoped_lock lock(globalMutex_);
 
-    if (!configuration_.isMember("DicomModalities"))
-    {
-      LOG(ERROR) << "No modality with symbolic name: " << symbolicName;
-      throw OrthancException(ErrorCode_BadFileFormat);
+      if (!configuration_.isMember("DicomModalities"))
+      {
+        LOG(ERROR) << "No modality with symbolic name: " << symbolicName;
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
+
+      Json::Value& modalities = configuration_["DicomModalities"];
+      if (modalities.type() != Json::objectValue)
+      {
+        LOG(ERROR) << "Bad file format for the \"DicomModalities\" configuration section";
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
+
+      modalities.removeMember(symbolicName.c_str());
     }
 
-    Json::Value& modalities = configuration_["DicomModalities"];
-    if (modalities.type() != Json::objectValue)
+#if ORTHANC_ENABLE_PLUGINS == 1
+    if (context.HasPlugins())
     {
-      LOG(ERROR) << "Bad file format for the \"DicomModalities\" configuration section";
-      throw OrthancException(ErrorCode_BadFileFormat);
+      context.GetPlugins().SignalUpdatedModalities();
     }
-
-    modalities.removeMember(symbolicName.c_str());
+#endif
   }
 
 
-  void Configuration::UpdatePeer(const std::string& symbolicName,
+  void Configuration::UpdatePeer(ServerContext& context,
+                                 const std::string& symbolicName,
                                  const WebServiceParameters& peer)
   {
     peer.CheckClientCertificate();
 
-    boost::recursive_mutex::scoped_lock lock(globalMutex_);
+    {
+      boost::recursive_mutex::scoped_lock lock(globalMutex_);
+
+      if (!configuration_.isMember("OrthancPeers"))
+      {
+        LOG(ERROR) << "No peer with symbolic name: " << symbolicName;
+        configuration_["OrthancPeers"] = Json::objectValue;
+      }
 
-    if (!configuration_.isMember("OrthancPeers"))
-    {
-      LOG(ERROR) << "No peer with symbolic name: " << symbolicName;
-      configuration_["OrthancPeers"] = Json::objectValue;
+      Json::Value& peers = configuration_["OrthancPeers"];
+      if (peers.type() != Json::objectValue)
+      {
+        LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section";
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
+
+      peers.removeMember(symbolicName);
+
+      Json::Value v;
+      peer.Serialize(v, 
+                     false /* use simple format if possible */, 
+                     true  /* include passwords */);
+      peers[symbolicName] = v;
     }
 
-    Json::Value& peers = configuration_["OrthancPeers"];
-    if (peers.type() != Json::objectValue)
+#if ORTHANC_ENABLE_PLUGINS == 1
+    if (context.HasPlugins())
     {
-      LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section";
-      throw OrthancException(ErrorCode_BadFileFormat);
+      context.GetPlugins().SignalUpdatedPeers();
     }
-
-    peers.removeMember(symbolicName);
-
-    Json::Value v;
-    peer.Serialize(v, 
-                   false /* use simple format if possible */, 
-                   true  /* include passwords */);
-    peers[symbolicName] = v;
+#endif
   }
   
 
-  void Configuration::RemovePeer(const std::string& symbolicName)
+  void Configuration::RemovePeer(ServerContext& context,
+                                 const std::string& symbolicName)
   {
-    boost::recursive_mutex::scoped_lock lock(globalMutex_);
+    {
+      boost::recursive_mutex::scoped_lock lock(globalMutex_);
 
-    if (!configuration_.isMember("OrthancPeers"))
-    {
-      LOG(ERROR) << "No peer with symbolic name: " << symbolicName;
-      throw OrthancException(ErrorCode_BadFileFormat);
+      if (!configuration_.isMember("OrthancPeers"))
+      {
+        LOG(ERROR) << "No peer with symbolic name: " << symbolicName;
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
+
+      Json::Value& peers = configuration_["OrthancPeers"];
+      if (peers.type() != Json::objectValue)
+      {
+        LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section";
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
+
+      peers.removeMember(symbolicName.c_str());
     }
 
-    Json::Value& peers = configuration_["OrthancPeers"];
-    if (peers.type() != Json::objectValue)
+#if ORTHANC_ENABLE_PLUGINS == 1
+    if (context.HasPlugins())
     {
-      LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section";
-      throw OrthancException(ErrorCode_BadFileFormat);
+      context.GetPlugins().SignalUpdatedPeers();
     }
-
-    peers.removeMember(symbolicName.c_str());
+#endif
   }
 
 
--- a/OrthancServer/OrthancInitialization.h	Thu Aug 23 13:11:48 2018 +0200
+++ b/OrthancServer/OrthancInitialization.h	Thu Aug 23 13:52:54 2018 +0200
@@ -50,6 +50,8 @@
 
 namespace Orthanc
 {
+  class ServerContext;
+
   void OrthancInitialize(const char* configurationFile = NULL);
 
   void OrthancFinalize();
@@ -105,15 +107,19 @@
 
     static RemoteModalityParameters GetModalityUsingAet(const std::string& aet);
 
-    static void UpdateModality(const std::string& symbolicName,
+    static void UpdateModality(ServerContext& context,
+                               const std::string& symbolicName,
                                const RemoteModalityParameters& modality);
 
-    static void RemoveModality(const std::string& symbolicName);
+    static void RemoveModality(ServerContext& context,
+                               const std::string& symbolicName);
 
-    static void UpdatePeer(const std::string& symbolicName,
+    static void UpdatePeer(ServerContext& context,
+                           const std::string& symbolicName,
                            const WebServiceParameters& peer);
 
-    static void RemovePeer(const std::string& symbolicName);
+    static void RemovePeer(ServerContext& context,
+                           const std::string& symbolicName);
 
     static const std::string& GetConfigurationAbsolutePath();
 
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Thu Aug 23 13:11:48 2018 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Thu Aug 23 13:52:54 2018 +0200
@@ -957,13 +957,15 @@
 
   static void UpdateModality(RestApiPutCall& call)
   {
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
     Json::Value json;
     Json::Reader reader;
     if (reader.parse(call.GetBodyData(), call.GetBodyData() + call.GetBodySize(), json))
     {
       RemoteModalityParameters modality;
       modality.FromJson(json);
-      Configuration::UpdateModality(call.GetUriComponent("id", ""), modality);
+      Configuration::UpdateModality(context, call.GetUriComponent("id", ""), modality);
       call.GetOutput().AnswerBuffer("", "text/plain");
     }
   }
@@ -971,20 +973,24 @@
 
   static void DeleteModality(RestApiDeleteCall& call)
   {
-    Configuration::RemoveModality(call.GetUriComponent("id", ""));
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
+    Configuration::RemoveModality(context, call.GetUriComponent("id", ""));
     call.GetOutput().AnswerBuffer("", "text/plain");
   }
 
 
   static void UpdatePeer(RestApiPutCall& call)
   {
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
     Json::Value json;
     Json::Reader reader;
     if (reader.parse(call.GetBodyData(), call.GetBodyData() + call.GetBodySize(), json))
     {
       WebServiceParameters peer;
       peer.Unserialize(json);
-      Configuration::UpdatePeer(call.GetUriComponent("id", ""), peer);
+      Configuration::UpdatePeer(context, call.GetUriComponent("id", ""), peer);
       call.GetOutput().AnswerBuffer("", "text/plain");
     }
   }
@@ -992,7 +998,9 @@
 
   static void DeletePeer(RestApiDeleteCall& call)
   {
-    Configuration::RemovePeer(call.GetUriComponent("id", ""));
+    ServerContext& context = OrthancRestApi::GetContext(call);
+
+    Configuration::RemovePeer(context, call.GetUriComponent("id", ""));
     call.GetOutput().AnswerBuffer("", "text/plain");
   }
 
--- a/Plugins/Engine/OrthancPlugins.h	Thu Aug 23 13:11:48 2018 +0200
+++ b/Plugins/Engine/OrthancPlugins.h	Thu Aug 23 13:52:54 2018 +0200
@@ -264,6 +264,16 @@
       SignalChangeInternal(OrthancPluginChangeType_OrthancStopped, OrthancPluginResourceType_None, NULL);
     }
 
+    void SignalUpdatedPeers()
+    {
+      SignalChangeInternal(OrthancPluginChangeType_UpdatedPeers, OrthancPluginResourceType_None, NULL);
+    }
+
+    void SignalUpdatedModalities()
+    {
+      SignalChangeInternal(OrthancPluginChangeType_UpdatedModalities, OrthancPluginResourceType_None, NULL);
+    }
+
     bool HasWorklistHandler();
 
     virtual IWorklistRequestHandler* ConstructWorklistRequestHandler();
--- a/Plugins/Include/orthanc/OrthancCPlugin.h	Thu Aug 23 13:11:48 2018 +0200
+++ b/Plugins/Include/orthanc/OrthancCPlugin.h	Thu Aug 23 13:52:54 2018 +0200
@@ -685,6 +685,8 @@
     OrthancPluginChangeType_OrthancStopped = 11,    /*!< Orthanc is stopping */
     OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */
     OrthancPluginChangeType_UpdatedMetadata = 13,   /*!< Some user-defined metadata has changed for this resource */
+    OrthancPluginChangeType_UpdatedPeers = 14,      /*!< The list of Orthanc peers has changed */
+    OrthancPluginChangeType_UpdatedModalities = 15, /*!< The list of DICOM modalities has changed */
 
     _OrthancPluginChangeType_INTERNAL = 0x7fffffff
   } OrthancPluginChangeType;