comparison OrthancServer/OrthancConfiguration.h @ 2933:4a38d7d4f0e0

new class: OrthancConfiguration
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Nov 2018 17:08:48 +0100
parents
children 4767d36679ed
comparison
equal deleted inserted replaced
2931:89f2c302fc37 2933:4a38d7d4f0e0
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * In addition, as a special exception, the copyright holders of this
13 * program give permission to link the code of its release with the
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
15 * that use the same license as the "OpenSSL" library), and distribute
16 * the linked executables. You must obey the GNU General Public License
17 * in all respects for all of the code used other than "OpenSSL". If you
18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/
32
33
34 #pragma once
35
36 #include "../Core/Images/FontRegistry.h"
37 #include "../Core/WebServiceParameters.h"
38 #include "../Core/DicomNetworking/RemoteModalityParameters.h"
39
40 #include <EmbeddedResources.h>
41
42 #include <boost/filesystem.hpp>
43 #include <boost/thread/shared_mutex.hpp>
44
45 namespace Orthanc
46 {
47 class MongooseServer;
48
49 class OrthancConfiguration : public boost::noncopyable
50 {
51 private:
52 boost::shared_mutex mutex_;
53 Json::Value json_;
54 boost::filesystem::path defaultDirectory_;
55 std::string configurationAbsolutePath_;
56 FontRegistry fontRegistry_;
57 const char* configurationFileArg_;
58
59 OrthancConfiguration() :
60 configurationFileArg_(NULL)
61 {
62 }
63
64 void ValidateConfiguration() const;
65
66 static OrthancConfiguration& GetInstance();
67
68 public:
69 class Reader : public boost::noncopyable
70 {
71 private:
72 OrthancConfiguration& configuration_;
73 boost::shared_lock<boost::shared_mutex> lock_;
74
75 public:
76 Reader() :
77 configuration_(GetInstance()),
78 lock_(configuration_.mutex_)
79 {
80 }
81
82 const OrthancConfiguration& GetConfiguration() const
83 {
84 return configuration_;
85 }
86
87 const Json::Value& GetJson() const
88 {
89 return configuration_.json_;
90 }
91 };
92
93
94 class Writer : public boost::noncopyable
95 {
96 private:
97 OrthancConfiguration& configuration_;
98 boost::unique_lock<boost::shared_mutex> lock_;
99
100 public:
101 Writer() :
102 configuration_(GetInstance()),
103 lock_(configuration_.mutex_)
104 {
105 }
106
107 OrthancConfiguration& GetConfiguration()
108 {
109 return configuration_;
110 }
111
112 const OrthancConfiguration& GetConfiguration() const
113 {
114 return configuration_;
115 }
116
117 const Json::Value& GetJson() const
118 {
119 return configuration_.json_;
120 }
121 };
122
123
124 const Json::Value& GetContent() const
125 {
126 return json_;
127 }
128
129 const std::string& GetConfigurationAbsolutePath() const
130 {
131 return configurationAbsolutePath_;
132 }
133
134 const FontRegistry& GetFontRegistry() const
135 {
136 return fontRegistry_;
137 }
138
139 void Read(const char* configurationFile);
140
141 void RegisterFont(EmbeddedResources::FileResourceId resource)
142 {
143 fontRegistry_.AddFromResource(resource);
144 }
145
146 std::string GetStringParameter(const std::string& parameter,
147 const std::string& defaultValue) const;
148
149 int GetIntegerParameter(const std::string& parameter,
150 int defaultValue) const;
151
152 unsigned int GetUnsignedIntegerParameter(const std::string& parameter,
153 unsigned int defaultValue) const;
154
155 bool GetBooleanParameter(const std::string& parameter,
156 bool defaultValue) const;
157
158 void GetDicomModalityUsingSymbolicName(RemoteModalityParameters& modality,
159 const std::string& name) const;
160
161 bool GetOrthancPeer(WebServiceParameters& peer,
162 const std::string& name) const;
163
164 bool ReadKeys(std::set<std::string>& target,
165 const char* parameter,
166 bool onlyAlphanumeric) const;
167
168 void GetListOfDicomModalities(std::set<std::string>& target) const;
169
170 void GetListOfOrthancPeers(std::set<std::string>& target) const;
171
172 void SetupRegisteredUsers(MongooseServer& httpServer) const;
173
174 std::string InterpretStringParameterAsPath(const std::string& parameter) const;
175
176 void GetGlobalListOfStringsParameter(std::list<std::string>& target,
177 const std::string& key) const;
178
179 bool IsSameAETitle(const std::string& aet1,
180 const std::string& aet2) const;
181
182 bool LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality,
183 const std::string& aet) const;
184
185 bool IsKnownAETitle(const std::string& aet,
186 const std::string& ip) const;
187
188 RemoteModalityParameters GetModalityUsingSymbolicName(const std::string& name) const;
189
190 RemoteModalityParameters GetModalityUsingAet(const std::string& aet) const;
191
192 void UpdateModality(const std::string& symbolicName,
193 const RemoteModalityParameters& modality);
194
195 void RemoveModality(const std::string& symbolicName);
196
197 void UpdatePeer(const std::string& symbolicName,
198 const WebServiceParameters& peer);
199
200 void RemovePeer(const std::string& symbolicName);
201
202
203 void Format(std::string& result) const;
204
205 void SetDefaultEncoding(Encoding encoding);
206
207 bool HasConfigurationChanged() const;
208 };
209 }