Mercurial > hg > orthanc-webviewer
comparison Plugin/ViewerToolbox.cpp @ 33:d7bd116777eb
Use of OrthancPluginGetConfiguration
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Jun 2015 15:33:08 +0200 |
parents | a6492d20b2a8 |
children | abdde1dfb3eb |
comparison
equal
deleted
inserted
replaced
32:c6ac4deb303b | 33:d7bd116777eb |
---|---|
25 | 25 |
26 #include <json/reader.h> | 26 #include <json/reader.h> |
27 #include <zlib.h> | 27 #include <zlib.h> |
28 #include <stdexcept> | 28 #include <stdexcept> |
29 #include <boost/lexical_cast.hpp> | 29 #include <boost/lexical_cast.hpp> |
30 #include <fstream> | |
31 #include <sys/stat.h> | 30 #include <sys/stat.h> |
32 | 31 |
33 namespace OrthancPlugins | 32 namespace OrthancPlugins |
34 { | 33 { |
35 bool GetStringFromOrthanc(std::string& content, | 34 bool GetStringFromOrthanc(std::string& content, |
214 | 213 |
215 | 214 |
216 bool ReadConfiguration(Json::Value& configuration, | 215 bool ReadConfiguration(Json::Value& configuration, |
217 OrthancPluginContext* context) | 216 OrthancPluginContext* context) |
218 { | 217 { |
219 std::string path; | 218 std::string s; |
220 | 219 |
221 { | 220 { |
222 char* pathTmp = OrthancPluginGetConfigurationPath(context); | 221 char* tmp = OrthancPluginGetConfiguration(context); |
223 if (pathTmp == NULL) | 222 if (tmp == NULL) |
224 { | 223 { |
225 OrthancPluginLogError(context, "No configuration file is provided"); | 224 OrthancPluginLogError(context, "Error while retrieving the configuration from Orthanc"); |
226 return false; | 225 return false; |
227 } | 226 } |
228 | 227 |
229 path = std::string(pathTmp); | 228 s.assign(tmp); |
230 | 229 OrthancPluginFreeString(context, tmp); |
231 OrthancPluginFreeString(context, pathTmp); | 230 } |
232 } | |
233 | |
234 std::ifstream f(path.c_str()); | |
235 | 231 |
236 Json::Reader reader; | 232 Json::Reader reader; |
237 if (!reader.parse(f, configuration) || | 233 if (reader.parse(s, configuration)) |
238 configuration.type() != Json::objectValue) | 234 { |
239 { | 235 return true; |
240 std::string s = "Unable to parse the configuration file: " + std::string(path); | 236 } |
241 OrthancPluginLogError(context, s.c_str()); | 237 else |
242 return false; | 238 { |
243 } | 239 OrthancPluginLogError(context, "Unable to parse the configuration"); |
244 | 240 return false; |
245 return true; | 241 } |
246 } | 242 } |
247 | 243 |
248 | 244 |
249 std::string GetStringValue(const Json::Value& configuration, | 245 std::string GetStringValue(const Json::Value& configuration, |
250 const std::string& key, | 246 const std::string& key, |