changeset 1528:c815ad10a10f

RtViewerPlugin : added detection of web-viewer plugin
author Benjamin Golinvaux <bgo@osimis.io>
date Sun, 02 Aug 2020 15:38:02 +0200
parents 4c4b267e4004
children c1d991462c7b
files OrthancStone/Samples/RtViewerPlugin/Plugin.cpp
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Samples/RtViewerPlugin/Plugin.cpp	Sun Aug 02 15:13:58 2020 +0200
+++ b/OrthancStone/Samples/RtViewerPlugin/Plugin.cpp	Sun Aug 02 15:38:02 2020 +0200
@@ -26,6 +26,32 @@
 #include <SystemToolbox.h>
 #include <Toolbox.h>
 
+OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
+                                        OrthancPluginResourceType resourceType,
+                                        const char* resourceId)
+{
+  try
+  {
+    if (changeType == OrthancPluginChangeType_OrthancStarted)
+    {
+      Json::Value info;
+      if (!OrthancPlugins::RestApiGet(info, "/plugins/web-viewer", false))
+      {
+        throw Orthanc::OrthancException(
+          Orthanc::ErrorCode_InternalError,
+          "The Stone MPR RT viewer requires the Web Viewer plugin to be installed");
+      }
+    }
+  }
+  catch (Orthanc::OrthancException& e)
+  {
+    LOG(ERROR) << "Exception: " << e.What();
+    return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
+  }
+
+  return OrthancPluginErrorCode_Success;
+}
+
 template <enum Orthanc::EmbeddedResources::DirectoryResourceId folder>
 void ServeEmbeddedFolder(OrthancPluginRestOutput* output,
                          const char* url,
@@ -128,6 +154,8 @@
       OrthancPlugins::RegisterRestCallback
         <ServeEmbeddedFile<Orthanc::EmbeddedResources::RT_VIEWER_INDEX_HTML> >
         ("/stone-rtviewer/index.html", true);
+
+      OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
     }
     catch (...)
     {