comparison OrthancStone/Samples/RtViewerPlugin/Plugin.cpp @ 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 3eca4f9c2827
comparison
equal deleted inserted replaced
1527:4c4b267e4004 1528:c815ad10a10f
23 23
24 #include <EmbeddedResources.h> 24 #include <EmbeddedResources.h>
25 25
26 #include <SystemToolbox.h> 26 #include <SystemToolbox.h>
27 #include <Toolbox.h> 27 #include <Toolbox.h>
28
29 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
30 OrthancPluginResourceType resourceType,
31 const char* resourceId)
32 {
33 try
34 {
35 if (changeType == OrthancPluginChangeType_OrthancStarted)
36 {
37 Json::Value info;
38 if (!OrthancPlugins::RestApiGet(info, "/plugins/web-viewer", false))
39 {
40 throw Orthanc::OrthancException(
41 Orthanc::ErrorCode_InternalError,
42 "The Stone MPR RT viewer requires the Web Viewer plugin to be installed");
43 }
44 }
45 }
46 catch (Orthanc::OrthancException& e)
47 {
48 LOG(ERROR) << "Exception: " << e.What();
49 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
50 }
51
52 return OrthancPluginErrorCode_Success;
53 }
28 54
29 template <enum Orthanc::EmbeddedResources::DirectoryResourceId folder> 55 template <enum Orthanc::EmbeddedResources::DirectoryResourceId folder>
30 void ServeEmbeddedFolder(OrthancPluginRestOutput* output, 56 void ServeEmbeddedFolder(OrthancPluginRestOutput* output,
31 const char* url, 57 const char* url,
32 const OrthancPluginHttpRequest* request) 58 const OrthancPluginHttpRequest* request)
126 ("/stone-rtviewer/RtViewerWasmApp.js", true); 152 ("/stone-rtviewer/RtViewerWasmApp.js", true);
127 153
128 OrthancPlugins::RegisterRestCallback 154 OrthancPlugins::RegisterRestCallback
129 <ServeEmbeddedFile<Orthanc::EmbeddedResources::RT_VIEWER_INDEX_HTML> > 155 <ServeEmbeddedFile<Orthanc::EmbeddedResources::RT_VIEWER_INDEX_HTML> >
130 ("/stone-rtviewer/index.html", true); 156 ("/stone-rtviewer/index.html", true);
157
158 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
131 } 159 }
132 catch (...) 160 catch (...)
133 { 161 {
134 OrthancPlugins::LogError("Exception while initializing the Stone Web viewer plugin"); 162 OrthancPlugins::LogError("Exception while initializing the Stone Web viewer plugin");
135 return -1; 163 return -1;