comparison OrthancServer/Sources/OrthancConfiguration.h @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents OrthancServer/OrthancConfiguration.h@058b5ade8acd
children 05b8fd21089c
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
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-2020 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 <OrthancServerResources.h>
41
42 #include <boost/filesystem.hpp>
43 #include <boost/thread/shared_mutex.hpp>
44 #include <boost/thread/lock_types.hpp>
45
46 namespace Orthanc
47 {
48 class HttpServer;
49 class ServerIndex;
50 class TemporaryFile;
51
52 class OrthancConfiguration : public boost::noncopyable
53 {
54 private:
55 typedef std::map<std::string, RemoteModalityParameters> Modalities;
56 typedef std::map<std::string, WebServiceParameters> Peers;
57
58 boost::shared_mutex mutex_;
59 Json::Value json_;
60 boost::filesystem::path defaultDirectory_;
61 std::string configurationAbsolutePath_;
62 FontRegistry fontRegistry_;
63 const char* configurationFileArg_;
64 Modalities modalities_;
65 Peers peers_;
66 ServerIndex* serverIndex_;
67
68 OrthancConfiguration() :
69 configurationFileArg_(NULL)
70 {
71 }
72
73 void LoadModalitiesFromJson(const Json::Value& source);
74
75 void LoadPeersFromJson(const Json::Value& source);
76
77 void LoadModalities();
78
79 void LoadPeers();
80
81 void SaveModalitiesToJson(Json::Value& target);
82
83 void SavePeersToJson(Json::Value& target);
84
85 void SaveModalities();
86
87 void SavePeers();
88
89 static OrthancConfiguration& GetInstance();
90
91 public:
92 class ReaderLock : public boost::noncopyable
93 {
94 private:
95 OrthancConfiguration& configuration_;
96 boost::shared_lock<boost::shared_mutex> lock_;
97
98 public:
99 ReaderLock() :
100 configuration_(GetInstance()),
101 lock_(configuration_.mutex_)
102 {
103 }
104
105 const OrthancConfiguration& GetConfiguration() const
106 {
107 return configuration_;
108 }
109
110 const Json::Value& GetJson() const
111 {
112 return configuration_.json_;
113 }
114 };
115
116
117 class WriterLock : public boost::noncopyable
118 {
119 private:
120 OrthancConfiguration& configuration_;
121 boost::unique_lock<boost::shared_mutex> lock_;
122
123 public:
124 WriterLock() :
125 configuration_(GetInstance()),
126 lock_(configuration_.mutex_)
127 {
128 }
129
130 OrthancConfiguration& GetConfiguration()
131 {
132 return configuration_;
133 }
134
135 const OrthancConfiguration& GetConfiguration() const
136 {
137 return configuration_;
138 }
139
140 const Json::Value& GetJson() const
141 {
142 return configuration_.json_;
143 }
144 };
145
146
147 const std::string& GetConfigurationAbsolutePath() const
148 {
149 return configurationAbsolutePath_;
150 }
151
152 const FontRegistry& GetFontRegistry() const
153 {
154 return fontRegistry_;
155 }
156
157 void Read(const char* configurationFile);
158
159 void LoadModalitiesAndPeers();
160
161 void RegisterFont(ServerResources::FileResourceId resource);
162
163 bool LookupStringParameter(std::string& target,
164 const std::string& parameter) const;
165
166 std::string GetStringParameter(const std::string& parameter,
167 const std::string& defaultValue) const;
168
169 int GetIntegerParameter(const std::string& parameter,
170 int defaultValue) const;
171
172 unsigned int GetUnsignedIntegerParameter(const std::string& parameter,
173 unsigned int defaultValue) const;
174
175 bool LookupBooleanParameter(bool& target,
176 const std::string& parameter) const;
177
178 bool GetBooleanParameter(const std::string& parameter,
179 bool defaultValue) const;
180
181 void GetDicomModalityUsingSymbolicName(RemoteModalityParameters& modality,
182 const std::string& name) const;
183
184 bool LookupOrthancPeer(WebServiceParameters& peer,
185 const std::string& name) const;
186
187 void GetListOfDicomModalities(std::set<std::string>& target) const;
188
189 void GetListOfOrthancPeers(std::set<std::string>& target) const;
190
191 // Returns "true" iff. at least one user is registered
192 bool SetupRegisteredUsers(HttpServer& httpServer) const;
193
194 std::string InterpretStringParameterAsPath(const std::string& parameter) const;
195
196 void GetListOfStringsParameter(std::list<std::string>& target,
197 const std::string& key) const;
198
199 bool IsSameAETitle(const std::string& aet1,
200 const std::string& aet2) const;
201
202 bool LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality,
203 const std::string& aet) const;
204
205 bool IsKnownAETitle(const std::string& aet,
206 const std::string& ip) const;
207
208 RemoteModalityParameters GetModalityUsingSymbolicName(const std::string& name) const;
209
210 RemoteModalityParameters GetModalityUsingAet(const std::string& aet) const;
211
212 void UpdateModality(const std::string& symbolicName,
213 const RemoteModalityParameters& modality);
214
215 void RemoveModality(const std::string& symbolicName);
216
217 void UpdatePeer(const std::string& symbolicName,
218 const WebServiceParameters& peer);
219
220 void RemovePeer(const std::string& symbolicName);
221
222
223 void Format(std::string& result) const;
224
225 void SetDefaultEncoding(Encoding encoding);
226
227 bool HasConfigurationChanged() const;
228
229 void SetServerIndex(ServerIndex& index);
230
231 void ResetServerIndex();
232
233 TemporaryFile* CreateTemporaryFile() const;
234
235 std::string GetDefaultPrivateCreator() const;
236 };
237 }