Mercurial > hg > orthanc-stone
comparison Applications/StoneWebViewer/Plugin/Plugin.cpp @ 1700:f1bd464dc3e1
the plugin uses the Orthanc configuration instead of the default configuration
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Nov 2020 10:55:21 +0100 |
parents | 1ed2af7332a2 |
children | 2931f5e15320 |
comparison
equal
deleted
inserted
replaced
1699:0598c87e1e88 | 1700:f1bd464dc3e1 |
---|---|
158 OrthancPluginAnswerBuffer(context, output, resource, s.size(), mime); | 158 OrthancPluginAnswerBuffer(context, output, resource, s.size(), mime); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 void ServeConfiguration(OrthancPluginRestOutput* output, | |
164 const char* url, | |
165 const OrthancPluginHttpRequest* request) | |
166 { | |
167 OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); | |
168 | |
169 if (request->method != OrthancPluginHttpMethod_Get) | |
170 { | |
171 OrthancPluginSendMethodNotAllowed(context, output, "GET"); | |
172 } | |
173 else | |
174 { | |
175 static const char* CONFIG_SECTION = "StoneWebViewer"; | |
176 | |
177 std::string config; | |
178 | |
179 OrthancPlugins::OrthancConfiguration orthanc; | |
180 if (orthanc.IsSection(CONFIG_SECTION)) | |
181 { | |
182 OrthancPlugins::OrthancConfiguration section(false); | |
183 orthanc.GetSection(section, CONFIG_SECTION); | |
184 | |
185 Json::Value wrapper = Json::objectValue; | |
186 wrapper[CONFIG_SECTION] = section.GetJson(); | |
187 config = wrapper.toStyledString(); | |
188 } | |
189 else | |
190 { | |
191 LOG(WARNING) << "The Orthanc configuration file doesn't contain a section \"" | |
192 << CONFIG_SECTION << "\" to configure the Stone Web viewer: " | |
193 << "Will use default settings"; | |
194 Orthanc::EmbeddedResources::GetDirectoryResource( | |
195 config, Orthanc::EmbeddedResources::WEB_APPLICATION, "/configuration.json"); | |
196 } | |
197 | |
198 OrthancPluginAnswerBuffer(context, output, config.c_str(), config.size(), "application/json"); | |
199 } | |
200 } | |
201 | |
202 | |
163 extern "C" | 203 extern "C" |
164 { | 204 { |
165 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | 205 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) |
166 { | 206 { |
167 OrthancPlugins::SetGlobalContext(context); | 207 OrthancPlugins::SetGlobalContext(context); |
190 std::string explorer; | 230 std::string explorer; |
191 Orthanc::EmbeddedResources::GetFileResource( | 231 Orthanc::EmbeddedResources::GetFileResource( |
192 explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER); | 232 explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER); |
193 OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str()); | 233 OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str()); |
194 | 234 |
235 OrthancPlugins::RegisterRestCallback<ServeConfiguration> | |
236 ("/stone-webviewer/configuration.json", true); | |
237 | |
195 OrthancPlugins::RegisterRestCallback | 238 OrthancPlugins::RegisterRestCallback |
196 <ServeEmbeddedFile<Orthanc::EmbeddedResources::STONE_WEB_VIEWER_WASM> > | 239 <ServeEmbeddedFile<Orthanc::EmbeddedResources::STONE_WEB_VIEWER_WASM> > |
197 ("/stone-webviewer/StoneWebViewer.wasm", true); | 240 ("/stone-webviewer/StoneWebViewer.wasm", true); |
198 | 241 |
199 OrthancPlugins::RegisterRestCallback | 242 OrthancPlugins::RegisterRestCallback |