diff OrthancServer/OrthancInitialization.cpp @ 394:9784f19f7e1b lua-scripting

path relative to configuration path, list of lua scripts
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 02 May 2013 11:02:15 +0200
parents fe180eae201d
children 2d269089078f
line wrap: on
line diff
--- a/OrthancServer/OrthancInitialization.cpp	Tue Apr 30 15:41:07 2013 +0200
+++ b/OrthancServer/OrthancInitialization.cpp	Thu May 02 11:02:15 2013 +0200
@@ -47,6 +47,7 @@
 
   static boost::mutex globalMutex_;
   static std::auto_ptr<Json::Value> configuration_;
+  static boost::filesystem::path defaultDirectory_;
 
 
   static void ReadGlobalConfiguration(const char* configurationFile)
@@ -58,6 +59,7 @@
     if (configurationFile)
     {
       Toolbox::ReadFile(content, configurationFile);
+      defaultDirectory_ = boost::filesystem::path(configurationFile).parent_path();
       LOG(INFO) << "Using the configuration from: " << configurationFile;
     }
     else
@@ -119,6 +121,7 @@
   void OrthancInitialize(const char* configurationFile)
   {
     boost::mutex::scoped_lock lock(globalMutex_);
+    defaultDirectory_ = boost::filesystem::current_path();
     ReadGlobalConfiguration(configurationFile);
     curl_global_init(CURL_GLOBAL_ALL);
   }
@@ -275,4 +278,37 @@
       httpServer.RegisterUser(username.c_str(), password.c_str());
     }
   }
+
+
+  std::string InterpretStringParameterAsPath(const std::string& parameter)
+  {
+    boost::mutex::scoped_lock lock(globalMutex_);
+    return (defaultDirectory_ / parameter).string();
+  }
+
+
+  void GetGlobalListOfStringsParameter(std::list<std::string>& target,
+                                       const std::string& key)
+  {
+    boost::mutex::scoped_lock lock(globalMutex_);
+
+    target.clear();
+  
+    if (!configuration_->isMember(key))
+    {
+      return;
+    }
+
+    const Json::Value& lst = (*configuration_) [key];
+
+    if (lst.type() != Json::arrayValue)
+    {
+      throw OrthancException("Badly formatted list of strings");
+    }
+
+    for (Json::Value::ArrayIndex i = 0; i < lst.size(); i++)
+    {
+      target.push_back(lst[i].asString());
+    }    
+  }
 }