comparison OrthancServer/OrthancInitialization.cpp @ 1145:0479d02c6778

Plugins can retrieve the path to Orthanc and to its configuration file
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Sep 2014 13:06:16 +0200
parents 871c49c9b11d
children b9e2ed59cae4
comparison
equal deleted inserted replaced
1144:fef79a477e09 1145:0479d02c6778
59 namespace Orthanc 59 namespace Orthanc
60 { 60 {
61 static boost::mutex globalMutex_; 61 static boost::mutex globalMutex_;
62 static std::auto_ptr<Json::Value> configuration_; 62 static std::auto_ptr<Json::Value> configuration_;
63 static boost::filesystem::path defaultDirectory_; 63 static boost::filesystem::path defaultDirectory_;
64 static std::string configurationAbsolutePath_;
64 65
65 66
66 static void ReadGlobalConfiguration(const char* configurationFile) 67 static void ReadGlobalConfiguration(const char* configurationFile)
67 { 68 {
68 configuration_.reset(new Json::Value); 69 configuration_.reset(new Json::Value);
72 if (configurationFile) 73 if (configurationFile)
73 { 74 {
74 Toolbox::ReadFile(content, configurationFile); 75 Toolbox::ReadFile(content, configurationFile);
75 defaultDirectory_ = boost::filesystem::path(configurationFile).parent_path(); 76 defaultDirectory_ = boost::filesystem::path(configurationFile).parent_path();
76 LOG(WARNING) << "Using the configuration from: " << configurationFile; 77 LOG(WARNING) << "Using the configuration from: " << configurationFile;
78 configurationAbsolutePath_ = boost::filesystem::absolute(configurationFile).string();
77 } 79 }
78 else 80 else
79 { 81 {
80 #if ORTHANC_STANDALONE == 1 82 #if ORTHANC_STANDALONE == 1
81 // No default path for the standalone configuration 83 // No default path for the standalone configuration
91 boost::filesystem::path p = ORTHANC_PATH; 93 boost::filesystem::path p = ORTHANC_PATH;
92 p /= "Resources"; 94 p /= "Resources";
93 p /= "Configuration.json"; 95 p /= "Configuration.json";
94 Toolbox::ReadFile(content, p.string()); 96 Toolbox::ReadFile(content, p.string());
95 LOG(WARNING) << "Using the configuration from: " << p.string(); 97 LOG(WARNING) << "Using the configuration from: " << p.string();
98 configurationAbsolutePath_ = boost::filesystem::absolute(p).string();
96 } 99 }
97 catch (OrthancException&) 100 catch (OrthancException&)
98 { 101 {
99 // No configuration file found, give up with empty configuration 102 // No configuration file found, give up with empty configuration
100 LOG(WARNING) << "Using the default Orthanc configuration"; 103 LOG(WARNING) << "Using the default Orthanc configuration";
101 return; 104 return;
102 } 105 }
103 #endif 106 #endif
104 } 107 }
108
105 109
106 Json::Reader reader; 110 Json::Reader reader;
107 if (!reader.parse(content, *configuration_)) 111 if (!reader.parse(content, *configuration_))
108 { 112 {
109 throw OrthancException("Unable to read the configuration file"); 113 throw OrthancException("Unable to read the configuration file");
641 throw OrthancException(ErrorCode_BadFileFormat); 645 throw OrthancException(ErrorCode_BadFileFormat);
642 } 646 }
643 647
644 peers.removeMember(symbolicName.c_str()); 648 peers.removeMember(symbolicName.c_str());
645 } 649 }
650
651
652
653 const std::string& Configuration::GetConfigurationAbsolutePath()
654 {
655 return configurationAbsolutePath_;
656 }
646 } 657 }