Mercurial > hg > orthanc
annotate OrthancServer/main.cpp @ 140:4d863c7b2f44
message queues
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Oct 2012 18:20:04 +0200 |
parents | 0e97abc7b950 |
children | 00604c758004 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
0 | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
62 | 33 #include "OrthancRestApi.h" |
0 | 34 |
35 #include <stdio.h> | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
36 #include <glog/logging.h> |
112 | 37 #include <boost/algorithm/string/predicate.hpp> |
0 | 38 |
39 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" | |
40 #include "../Core/HttpServer/FilesystemHttpHandler.h" | |
41 #include "../Core/HttpServer/MongooseServer.h" | |
42 #include "DicomProtocol/DicomServer.h" | |
62 | 43 #include "OrthancInitialization.h" |
0 | 44 |
45 | |
62 | 46 using namespace Orthanc; |
0 | 47 |
48 | |
49 class MyDicomStore : public IStoreRequestHandler | |
50 { | |
51 private: | |
52 ServerIndex& index_; | |
53 FileStorage storage_; | |
54 | |
55 public: | |
56 MyDicomStore(ServerIndex& index, | |
57 const std::string& path) : | |
58 index_(index), | |
59 storage_(path) | |
60 { | |
61 } | |
62 | |
63 virtual void Handle(const std::vector<uint8_t>& dicomFile, | |
64 const DicomMap& dicomSummary, | |
65 const Json::Value& dicomJson, | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
66 const std::string& remoteAet) |
0 | 67 { |
68 std::string instanceUuid; | |
69 if (dicomFile.size() > 0) | |
70 { | |
71 index_.Store(instanceUuid, storage_, | |
72 reinterpret_cast<const char*>(&dicomFile[0]), dicomFile.size(), | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
73 dicomSummary, dicomJson, remoteAet); |
0 | 74 } |
75 } | |
76 }; | |
77 | |
78 | |
79 class MyDicomStoreFactory : public IStoreRequestHandlerFactory | |
80 { | |
81 private: | |
82 ServerIndex& index_; | |
83 std::string path_; | |
84 | |
85 public: | |
86 MyDicomStoreFactory(ServerIndex& index, | |
87 const std::string& path) : | |
88 index_(index), | |
89 path_(path) | |
90 { | |
91 } | |
92 | |
93 virtual IStoreRequestHandler* ConstructStoreRequestHandler() | |
94 { | |
95 return new MyDicomStore(index_, path_); | |
96 } | |
97 | |
98 void Done() | |
99 { | |
100 //index_.db().Execute("DELETE FROM Studies"); | |
101 } | |
102 }; | |
103 | |
104 | |
133 | 105 void PrintHelp(char* path) |
106 { | |
107 std::cout | |
108 << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl | |
109 << "Start Orthanc, a lightweight, RESTful DICOM server for healthcare and medical research." << std::endl | |
110 << std::endl | |
111 << "If no configuration file is given on the command line, a set of default parameters " << std::endl | |
112 << "is used. Please refer to the Orthanc homepage for the full instructions about how to use Orthanc " << std::endl | |
113 << "<https://code.google.com/p/orthanc/wiki/OrthancCookbook>." << std::endl | |
114 << std::endl | |
115 << "Command-line options:" << std::endl | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
116 << " --verbose\t\tbe verbose in logs" << std::endl |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
117 << " --trace\t\thighest verbosity in logs (for debug)" << std::endl |
133 | 118 << " --help\t\tdisplay this help and exit" << std::endl |
119 << " --version\t\toutput version information and exit" << std::endl | |
120 << " --logdir=[dir]\tdirectory where to store the log files" << std::endl | |
121 << "\t\t\t(if not used, the logs are dumped to stderr)" << std::endl | |
122 << std::endl | |
123 << "Exit status:" << std::endl | |
124 << " 0 if OK," << std::endl | |
125 << " -1 if error (have a look at the logs)." << std::endl | |
126 << std::endl; | |
127 } | |
0 | 128 |
129 | |
133 | 130 void PrintVersion(char* path) |
131 { | |
132 std::cout | |
133 << path << " " << ORTHANC_VERSION << std::endl | |
134 << "Copyright (C) 2012 Medical Physics Department, CHU of Liege (Belgium) " << std::endl | |
135 << "Licensing GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>, with OpenSSL exception." << std::endl | |
136 << "This is free software: you are free to change and redistribute it." << std::endl | |
137 << "There is NO WARRANTY, to the extent permitted by law." << std::endl | |
138 << std::endl | |
139 << "Written by Sebastien Jodogne <s.jodogne@gmail.com>" << std::endl; | |
140 } | |
141 | |
0 | 142 |
143 int main(int argc, char* argv[]) | |
144 { | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
145 // Initialize Google's logging library. |
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
146 FLAGS_logtostderr = true; |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
147 FLAGS_minloglevel = 1; |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
148 FLAGS_v = 0; |
133 | 149 |
112 | 150 for (int i = 1; i < argc; i++) |
151 { | |
133 | 152 if (std::string(argv[i]) == "--help") |
153 { | |
154 PrintHelp(argv[0]); | |
155 return 0; | |
156 } | |
157 | |
158 if (std::string(argv[i]) == "--version") | |
159 { | |
160 PrintVersion(argv[0]); | |
161 return 0; | |
162 } | |
163 | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
164 if (std::string(argv[i]) == "--verbose") |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
165 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
166 FLAGS_minloglevel = 0; |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
167 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
168 |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
169 if (std::string(argv[i]) == "--trace") |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
170 { |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
171 FLAGS_minloglevel = 0; |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
172 FLAGS_v = 1; |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
173 } |
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
174 |
112 | 175 if (boost::starts_with(argv[i], "--logdir=")) |
176 { | |
177 FLAGS_logtostderr = false; | |
178 FLAGS_log_dir = std::string(argv[i]).substr(9); | |
179 } | |
180 } | |
181 | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
182 google::InitGoogleLogging("Orthanc"); |
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
183 |
112 | 184 |
0 | 185 try |
186 { | |
112 | 187 bool isInitialized = false; |
26 | 188 if (argc >= 2) |
189 { | |
112 | 190 for (int i = 1; i < argc; i++) |
191 { | |
192 // Use the first argument that does not start with a "-" as | |
193 // the configuration file | |
194 if (argv[i][0] != '-') | |
195 { | |
196 OrthancInitialize(argv[i]); | |
197 isInitialized = true; | |
198 } | |
199 } | |
26 | 200 } |
112 | 201 |
202 if (!isInitialized) | |
26 | 203 { |
62 | 204 OrthancInitialize(); |
26 | 205 } |
206 | |
62 | 207 std::string storageDirectory = GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); |
12 | 208 ServerIndex index(storageDirectory); |
209 MyDicomStoreFactory storeScp(index, storageDirectory); | |
0 | 210 |
211 { | |
212 // DICOM server | |
213 DicomServer dicomServer; | |
55 | 214 dicomServer.SetCalledApplicationEntityTitleCheck(GetGlobalBoolParameter("DicomCheckCalledAet", false)); |
0 | 215 dicomServer.SetStoreRequestHandlerFactory(storeScp); |
128 | 216 dicomServer.SetPortNumber(GetGlobalIntegerParameter("DicomPort", 4242)); |
62 | 217 dicomServer.SetApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); |
0 | 218 |
219 // HTTP server | |
220 MongooseServer httpServer; | |
128 | 221 httpServer.SetPortNumber(GetGlobalIntegerParameter("HttpPort", 8000)); |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
27
diff
changeset
|
222 httpServer.SetRemoteAccessAllowed(GetGlobalBoolParameter("RemoteAccessAllowed", false)); |
0 | 223 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
224 httpServer.SetAuthenticationEnabled(GetGlobalBoolParameter("AuthenticationEnabled", false)); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
225 SetupRegisteredUsers(httpServer); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
226 |
23 | 227 if (GetGlobalBoolParameter("SslEnabled", false)) |
228 { | |
229 std::string certificate = GetGlobalStringParameter("SslCertificate", "certificate.pem"); | |
230 httpServer.SetSslEnabled(true); | |
231 httpServer.SetSslCertificate(certificate.c_str()); | |
232 } | |
233 else | |
234 { | |
235 httpServer.SetSslEnabled(false); | |
236 } | |
237 | |
128 | 238 LOG(INFO) << "DICOM server listening on port: " << dicomServer.GetPortNumber(); |
239 LOG(INFO) << "HTTP server listening on port: " << httpServer.GetPortNumber(); | |
125 | 240 |
62 | 241 #if ORTHANC_STANDALONE == 1 |
242 httpServer.RegisterHandler(new EmbeddedResourceHttpHandler("/app", EmbeddedResources::ORTHANC_EXPLORER)); | |
0 | 243 #else |
62 | 244 httpServer.RegisterHandler(new FilesystemHttpHandler("/app", ORTHANC_PATH "/OrthancExplorer")); |
0 | 245 #endif |
246 | |
62 | 247 httpServer.RegisterHandler(new OrthancRestApi(index, storageDirectory)); |
0 | 248 |
249 // GO !!! | |
250 httpServer.Start(); | |
251 dicomServer.Start(); | |
252 | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
253 LOG(WARNING) << "Orthanc has started"; |
0 | 254 Toolbox::ServerBarrier(); |
255 | |
256 // Stop | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
257 LOG(WARNING) << "Orthanc is stopping"; |
0 | 258 } |
259 | |
260 storeScp.Done(); | |
261 } | |
62 | 262 catch (OrthancException& e) |
0 | 263 { |
108 | 264 LOG(ERROR) << "EXCEPTION [" << e.What() << "]"; |
133 | 265 return -1; |
0 | 266 } |
267 | |
62 | 268 OrthancFinalize(); |
27 | 269 |
0 | 270 return 0; |
271 } |