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