diff OrthancServer/OrthancInitialization.cpp @ 1424:fe384a9d3b51

OrthancPluginGetConfiguration
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Jun 2015 15:32:45 +0200
parents 7b7d597a190c
children d710ea64f0fd
line wrap: on
line diff
--- a/OrthancServer/OrthancInitialization.cpp	Fri Jun 26 14:44:10 2015 +0200
+++ b/OrthancServer/OrthancInitialization.cpp	Fri Jun 26 15:32:45 2015 +0200
@@ -71,25 +71,31 @@
   {
     LOG(WARNING) << "Reading the configuration from: " << path;
 
-    std::string content;
-    Toolbox::ReadFile(content, path.string());
+    Json::Value config;
+
+    {
+      std::string content;
+      Toolbox::ReadFile(content, path.string());
 
-    Json::Value tmp;
-    Json::Reader reader;
-    if (!reader.parse(content, tmp) ||
-        tmp.type() != Json::objectValue)
-    {
-      LOG(ERROR) << "Bad file format for this configuration file: " << path;
-      throw OrthancException(ErrorCode_BadFileFormat);
+      Json::Value tmp;
+      Json::Reader reader;
+      if (!reader.parse(content, tmp) ||
+          tmp.type() != Json::objectValue)
+      {
+        LOG(ERROR) << "Bad file format for this configuration file: " << path;
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
+
+      Toolbox::CopyJsonWithoutComments(config, tmp);
     }
 
     if (configuration_.size() == 0)
     {
-      configuration_ = tmp;
+      configuration_ = config;
     }
     else
     {
-      Json::Value::Members members = tmp.getMemberNames();
+      Json::Value::Members members = config.getMemberNames();
       for (Json::Value::ArrayIndex i = 0; i < members.size(); i++)
       {
         if (configuration_.isMember(members[i]))
@@ -99,7 +105,7 @@
         }
         else
         {
-          configuration_[members[i]] = tmp[members[i]];
+          configuration_[members[i]] = config[members[i]];
         }
       }
     }
@@ -839,4 +845,18 @@
   {
     return CreateFilesystemStorage();
   }  
+
+
+  void Configuration::FormatConfiguration(std::string& result)
+  {
+    Json::Value config;
+
+    {
+      boost::mutex::scoped_lock lock(globalMutex_);
+      config = configuration_;
+    }
+
+    Json::StyledWriter w;
+    result = w.write(config);
+  }
 }