Mercurial > hg > orthanc
annotate OrthancServer/DicomProtocol/DicomServer.cpp @ 1755:39c37a994b2f db-changes
handling of DICOM_TAG_MODALITIES_IN_STUDY
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Oct 2015 12:02:15 +0100 |
parents | 6414043df7d8 |
children | 164d78911382 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
0 | 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 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "../PrecompiledHeadersServer.h" |
0 | 34 #include "DicomServer.h" |
35 | |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1454
diff
changeset
|
36 #include "../../Core/Logging.h" |
62 | 37 #include "../../Core/OrthancException.h" |
0 | 38 #include "../../Core/Toolbox.h" |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
39 #include "../../Core/Uuid.h" |
0 | 40 #include "../Internals/CommandDispatcher.h" |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
41 #include "../OrthancInitialization.h" |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
42 #include "EmbeddedResources.h" |
1681
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
43 #include "../../Core/MultiThreading/RunnableWorkersPool.h" |
0 | 44 |
45 #include <boost/thread.hpp> | |
46 | |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
47 #if defined(__linux) |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
48 #include <cstdlib> |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
49 #endif |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
50 |
0 | 51 |
62 | 52 namespace Orthanc |
0 | 53 { |
54 struct DicomServer::PImpl | |
55 { | |
1681
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
56 boost::thread thread_; |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
57 T_ASC_Network *network_; |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
58 std::auto_ptr<RunnableWorkersPool> workers_; |
0 | 59 }; |
60 | |
61 | |
1681
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
62 void DicomServer::ServerThread(DicomServer* server) |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
63 { |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
64 LOG(INFO) << "DICOM server started"; |
0 | 65 |
66 while (server->continue_) | |
67 { | |
68 /* receive an association and acknowledge or reject it. If the association was */ | |
69 /* acknowledged, offer corresponding services and invoke one or more if required. */ | |
1681
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
70 std::auto_ptr<Internals::CommandDispatcher> dispatcher(Internals::AcceptAssociation(*server, server->pimpl_->network_)); |
0 | 71 |
1680 | 72 try |
0 | 73 { |
1680 | 74 if (dispatcher.get() != NULL) |
0 | 75 { |
1681
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
76 server->pimpl_->workers_->Add(dispatcher.release()); |
0 | 77 } |
1680 | 78 } |
79 catch (OrthancException& e) | |
80 { | |
81 LOG(ERROR) << "Exception in the DICOM server thread: " << e.What(); | |
0 | 82 } |
83 } | |
84 | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
85 LOG(INFO) << "DICOM server stopping"; |
1680 | 86 } |
0 | 87 |
88 | |
656 | 89 DicomServer::DicomServer() : |
90 pimpl_(new PImpl), | |
91 aet_("ANY-SCP") | |
0 | 92 { |
93 port_ = 104; | |
94 findRequestHandlerFactory_ = NULL; | |
95 moveRequestHandlerFactory_ = NULL; | |
96 storeRequestHandlerFactory_ = NULL; | |
97 applicationEntityFilter_ = NULL; | |
98 checkCalledAet_ = true; | |
99 clientTimeout_ = 30; | |
1681
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
100 continue_ = false; |
0 | 101 } |
102 | |
103 DicomServer::~DicomServer() | |
104 { | |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
105 if (continue_) |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
106 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
107 LOG(ERROR) << "INTERNAL ERROR: DicomServer::Stop() should be invoked manually to avoid mess in the destruction order!"; |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
108 Stop(); |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
109 } |
0 | 110 } |
111 | |
128 | 112 void DicomServer::SetPortNumber(uint16_t port) |
0 | 113 { |
114 Stop(); | |
115 port_ = port; | |
116 } | |
117 | |
128 | 118 uint16_t DicomServer::GetPortNumber() const |
0 | 119 { |
120 return port_; | |
121 } | |
122 | |
123 void DicomServer::SetClientTimeout(uint32_t timeout) | |
124 { | |
125 Stop(); | |
126 clientTimeout_ = timeout; | |
127 } | |
128 | |
129 uint32_t DicomServer::GetClientTimeout() const | |
130 { | |
131 return clientTimeout_; | |
132 } | |
133 | |
134 | |
135 void DicomServer::SetCalledApplicationEntityTitleCheck(bool check) | |
136 { | |
137 Stop(); | |
138 checkCalledAet_ = check; | |
139 } | |
140 | |
141 bool DicomServer::HasCalledApplicationEntityTitleCheck() const | |
142 { | |
143 return checkCalledAet_; | |
144 } | |
145 | |
146 void DicomServer::SetApplicationEntityTitle(const std::string& aet) | |
147 { | |
148 if (aet.size() == 0) | |
149 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
150 throw OrthancException(ErrorCode_BadApplicationEntityTitle); |
0 | 151 } |
152 | |
1234 | 153 if (aet.size() > 16) |
154 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
155 throw OrthancException(ErrorCode_BadApplicationEntityTitle); |
1234 | 156 } |
157 | |
0 | 158 for (size_t i = 0; i < aet.size(); i++) |
159 { | |
1243 | 160 if (!(aet[i] == '-' || |
161 aet[i] == '_' || | |
162 isdigit(aet[i]) || | |
163 (aet[i] >= 'A' && aet[i] <= 'Z'))) | |
0 | 164 { |
1234 | 165 LOG(WARNING) << "For best interoperability, only upper case, alphanumeric characters should be present in AET: \"" << aet << "\""; |
166 break; | |
0 | 167 } |
168 } | |
169 | |
170 Stop(); | |
171 aet_ = aet; | |
172 } | |
173 | |
174 const std::string& DicomServer::GetApplicationEntityTitle() const | |
175 { | |
176 return aet_; | |
177 } | |
178 | |
179 void DicomServer::SetFindRequestHandlerFactory(IFindRequestHandlerFactory& factory) | |
180 { | |
181 Stop(); | |
182 findRequestHandlerFactory_ = &factory; | |
183 } | |
184 | |
185 bool DicomServer::HasFindRequestHandlerFactory() const | |
186 { | |
187 return (findRequestHandlerFactory_ != NULL); | |
188 } | |
189 | |
190 IFindRequestHandlerFactory& DicomServer::GetFindRequestHandlerFactory() const | |
191 { | |
192 if (HasFindRequestHandlerFactory()) | |
193 { | |
194 return *findRequestHandlerFactory_; | |
195 } | |
196 else | |
197 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
198 throw OrthancException(ErrorCode_NoCFindHandler); |
0 | 199 } |
200 } | |
201 | |
202 void DicomServer::SetMoveRequestHandlerFactory(IMoveRequestHandlerFactory& factory) | |
203 { | |
204 Stop(); | |
205 moveRequestHandlerFactory_ = &factory; | |
206 } | |
207 | |
208 bool DicomServer::HasMoveRequestHandlerFactory() const | |
209 { | |
210 return (moveRequestHandlerFactory_ != NULL); | |
211 } | |
212 | |
213 IMoveRequestHandlerFactory& DicomServer::GetMoveRequestHandlerFactory() const | |
214 { | |
215 if (HasMoveRequestHandlerFactory()) | |
216 { | |
217 return *moveRequestHandlerFactory_; | |
218 } | |
219 else | |
220 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
221 throw OrthancException(ErrorCode_NoCMoveHandler); |
0 | 222 } |
223 } | |
224 | |
225 void DicomServer::SetStoreRequestHandlerFactory(IStoreRequestHandlerFactory& factory) | |
226 { | |
227 Stop(); | |
228 storeRequestHandlerFactory_ = &factory; | |
229 } | |
230 | |
231 bool DicomServer::HasStoreRequestHandlerFactory() const | |
232 { | |
233 return (storeRequestHandlerFactory_ != NULL); | |
234 } | |
235 | |
236 IStoreRequestHandlerFactory& DicomServer::GetStoreRequestHandlerFactory() const | |
237 { | |
238 if (HasStoreRequestHandlerFactory()) | |
239 { | |
240 return *storeRequestHandlerFactory_; | |
241 } | |
242 else | |
243 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
244 throw OrthancException(ErrorCode_NoCStoreHandler); |
0 | 245 } |
246 } | |
247 | |
248 void DicomServer::SetApplicationEntityFilter(IApplicationEntityFilter& factory) | |
249 { | |
250 Stop(); | |
251 applicationEntityFilter_ = &factory; | |
252 } | |
253 | |
254 bool DicomServer::HasApplicationEntityFilter() const | |
255 { | |
256 return (applicationEntityFilter_ != NULL); | |
257 } | |
258 | |
259 IApplicationEntityFilter& DicomServer::GetApplicationEntityFilter() const | |
260 { | |
261 if (HasApplicationEntityFilter()) | |
262 { | |
263 return *applicationEntityFilter_; | |
264 } | |
265 else | |
266 { | |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
267 throw OrthancException(ErrorCode_NoApplicationEntityFilter); |
0 | 268 } |
269 } | |
270 | |
271 void DicomServer::Start() | |
272 { | |
273 Stop(); | |
274 | |
1680 | 275 /* initialize network, i.e. create an instance of T_ASC_Network*. */ |
276 OFCondition cond = ASC_initializeNetwork | |
1681
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
277 (NET_ACCEPTOR, OFstatic_cast(int, port_), /*opt_acse_timeout*/ 30, &pimpl_->network_); |
1680 | 278 if (cond.bad()) |
0 | 279 { |
1680 | 280 LOG(ERROR) << "cannot create network: " << cond.text(); |
281 throw OrthancException(ErrorCode_DicomPortInUse); | |
0 | 282 } |
1680 | 283 |
1675
131136aeeaa7
improved exception handling in the main program
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1656
diff
changeset
|
284 continue_ = true; |
1681
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
285 pimpl_->workers_.reset(new RunnableWorkersPool(4)); // Use 4 workers - TODO as a parameter? |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
286 pimpl_->thread_ = boost::thread(ServerThread, this); |
0 | 287 } |
288 | |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
289 |
0 | 290 void DicomServer::Stop() |
291 { | |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
292 if (continue_) |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
293 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
294 continue_ = false; |
431
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
295 |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
296 if (pimpl_->thread_.joinable()) |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
297 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
298 pimpl_->thread_.join(); |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
299 } |
1454 | 300 |
1681
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
301 pimpl_->workers_.reset(NULL); |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
302 |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
303 /* drop the network, i.e. free memory of T_ASC_Network* structure. This call */ |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
304 /* is the counterpart of ASC_initializeNetwork(...) which was called above. */ |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
305 OFCondition cond = ASC_dropNetwork(&pimpl_->network_); |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
306 if (cond.bad()) |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
307 { |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
308 LOG(ERROR) << "Error while dropping the network: " << cond.text(); |
ee4367497d0d
got rid of buggy BagOfRunnablesBySteps
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1680
diff
changeset
|
309 } |
431
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
310 } |
0 | 311 } |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
312 |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
313 |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
314 bool DicomServer::IsMyAETitle(const std::string& aet) const |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
315 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
316 if (!HasCalledApplicationEntityTitleCheck()) |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
317 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
318 // OK, no check on the AET. |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
319 return true; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
320 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
321 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
322 return Configuration::IsSameAETitle(aet, GetApplicationEntityTitle()); |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
323 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
324 |
0 | 325 } |