Mercurial > hg > orthanc
annotate OrthancServer/DicomProtocol/DicomServer.cpp @ 925:a4362c5263e2 mac
note
author | jodogne |
---|---|
date | Wed, 26 Feb 2014 15:12:50 +0100 |
parents | 2e67366aab83 |
children | 401a9633e492 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
0 | 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 | |
33 #include "DicomServer.h" | |
34 | |
62 | 35 #include "../../Core/OrthancException.h" |
0 | 36 #include "../../Core/Toolbox.h" |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
37 #include "../../Core/Uuid.h" |
0 | 38 #include "../Internals/CommandDispatcher.h" |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
39 #include "../OrthancInitialization.h" |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
40 #include "EmbeddedResources.h" |
0 | 41 |
42 #include <boost/thread.hpp> | |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
43 #include <boost/filesystem.hpp> |
0 | 44 #include <dcmtk/dcmdata/dcdict.h> |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
45 #include <glog/logging.h> |
0 | 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 { | |
56 boost::thread thread_; | |
57 | |
58 //std::set< | |
59 }; | |
60 | |
61 | |
660 | 62 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
63 static void LoadEmbeddedDictionary(DcmDataDictionary& dictionary, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
64 EmbeddedResources::FileResourceId resource) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
65 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
66 Toolbox::TemporaryFile tmp; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
67 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
68 FILE* fp = fopen(tmp.GetPath().c_str(), "wb"); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
69 fwrite(EmbeddedResources::GetFileResourceBuffer(resource), |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
70 EmbeddedResources::GetFileResourceSize(resource), 1, fp); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
71 fclose(fp); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
72 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
73 if (!dictionary.loadDictionary(tmp.GetPath().c_str())) |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
74 { |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
75 throw OrthancException(ErrorCode_InternalError); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
76 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
77 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
78 |
660 | 79 #else |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
80 static void LoadExternalDictionary(DcmDataDictionary& dictionary, |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
81 const std::string& directory, |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
82 const std::string& filename) |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
83 { |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
84 boost::filesystem::path p = directory; |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
85 p = p / filename; |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
86 |
494
012b63028085
CMake parameter for the location of DCMTK dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
431
diff
changeset
|
87 LOG(WARNING) << "Loading the external DICOM dictionary " << p; |
012b63028085
CMake parameter for the location of DCMTK dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
431
diff
changeset
|
88 |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
89 if (!dictionary.loadDictionary(p.string().c_str())) |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
90 { |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
91 throw OrthancException(ErrorCode_InternalError); |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
92 } |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
93 } |
660 | 94 |
95 #endif | |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
96 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
97 |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
98 void DicomServer::InitializeDictionary() |
0 | 99 { |
100 /* Disable "gethostbyaddr" (which results in memory leaks) and use raw IP addresses */ | |
101 dcmDisableGethostbyaddr.set(OFTrue); | |
102 | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
103 dcmDataDict.clear(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
104 DcmDataDictionary& d = dcmDataDict.wrlock(); |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
105 |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
106 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1 |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
107 LOG(WARNING) << "Loading the embedded dictionaries"; |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
108 /** |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
109 * Do not load DICONDE dictionary, it breaks the other tags. The |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
110 * command "strace storescu 2>&1 |grep dic" shows that DICONDE |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
111 * dictionary is not loaded by storescu. |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
112 **/ |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
113 //LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_DICONDE); |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
114 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
115 LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_DICOM); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
116 LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_PRIVATE); |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
117 |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
118 #elif defined(__linux) |
494
012b63028085
CMake parameter for the location of DCMTK dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
431
diff
changeset
|
119 std::string path = DCMTK_DICTIONARY_DIR; |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
120 |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
121 const char* env = std::getenv(DCM_DICT_ENVIRONMENT_VARIABLE); |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
122 if (env != NULL) |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
123 { |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
124 path = std::string(env); |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
125 } |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
126 |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
127 LoadExternalDictionary(d, path, "dicom.dic"); |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
128 LoadExternalDictionary(d, path, "private.dic"); |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
129 |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
130 #else |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
131 #error Support your platform here |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
132 #endif |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
133 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
134 dcmDataDict.unlock(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
135 |
0 | 136 /* make sure data dictionary is loaded */ |
137 if (!dcmDataDict.isDictionaryLoaded()) | |
138 { | |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
139 LOG(ERROR) << "No DICOM dictionary loaded, check environment variable: " << DCM_DICT_ENVIRONMENT_VARIABLE; |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
140 throw OrthancException(ErrorCode_InternalError); |
0 | 141 } |
142 | |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
143 { |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
144 // Test the dictionary with a simple DICOM tag |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
145 DcmTag key(0x0010, 0x1030); // This is PatientWeight |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
146 if (key.getEVR() != EVR_DS) |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
147 { |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
148 LOG(ERROR) << "The DICOM dictionary has not been correctly read"; |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
149 throw OrthancException(ErrorCode_InternalError); |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
150 } |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
151 } |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
152 } |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
153 |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
154 |
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
155 void DicomServer::ServerThread(DicomServer* server) |
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
156 { |
0 | 157 /* initialize network, i.e. create an instance of T_ASC_Network*. */ |
158 T_ASC_Network *net; | |
159 OFCondition cond = ASC_initializeNetwork | |
160 (NET_ACCEPTOR, OFstatic_cast(int, server->port_), /*opt_acse_timeout*/ 30, &net); | |
161 if (cond.bad()) | |
162 { | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
163 LOG(ERROR) << "cannot create network: " << cond.text(); |
62 | 164 throw OrthancException("Cannot create network"); |
0 | 165 } |
166 | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
167 LOG(INFO) << "DICOM server started"; |
0 | 168 |
169 server->started_ = true; | |
170 | |
171 while (server->continue_) | |
172 { | |
173 /* receive an association and acknowledge or reject it. If the association was */ | |
174 /* acknowledged, offer corresponding services and invoke one or more if required. */ | |
175 std::auto_ptr<Internals::CommandDispatcher> dispatcher(Internals::AcceptAssociation(*server, net)); | |
176 | |
177 if (dispatcher.get() != NULL) | |
178 { | |
179 if (server->isThreaded_) | |
180 { | |
181 server->bagOfDispatchers_.Add(dispatcher.release()); | |
182 } | |
183 else | |
184 { | |
185 IRunnableBySteps::RunUntilDone(*dispatcher); | |
186 } | |
187 } | |
188 } | |
189 | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
190 LOG(INFO) << "DICOM server stopping"; |
0 | 191 |
192 /* drop the network, i.e. free memory of T_ASC_Network* structure. This call */ | |
193 /* is the counterpart of ASC_initializeNetwork(...) which was called above. */ | |
194 cond = ASC_dropNetwork(&net); | |
195 if (cond.bad()) | |
196 { | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
197 LOG(ERROR) << "Error while dropping the network: " << cond.text(); |
0 | 198 } |
199 } | |
200 | |
201 | |
656 | 202 DicomServer::DicomServer() : |
203 pimpl_(new PImpl), | |
204 aet_("ANY-SCP") | |
0 | 205 { |
206 port_ = 104; | |
207 findRequestHandlerFactory_ = NULL; | |
208 moveRequestHandlerFactory_ = NULL; | |
209 storeRequestHandlerFactory_ = NULL; | |
210 applicationEntityFilter_ = NULL; | |
211 checkCalledAet_ = true; | |
212 clientTimeout_ = 30; | |
213 isThreaded_ = true; | |
656 | 214 continue_ = false; |
215 started_ = false; | |
0 | 216 } |
217 | |
218 DicomServer::~DicomServer() | |
219 { | |
220 Stop(); | |
221 } | |
222 | |
128 | 223 void DicomServer::SetPortNumber(uint16_t port) |
0 | 224 { |
225 Stop(); | |
226 port_ = port; | |
227 } | |
228 | |
128 | 229 uint16_t DicomServer::GetPortNumber() const |
0 | 230 { |
231 return port_; | |
232 } | |
233 | |
234 void DicomServer::SetThreaded(bool isThreaded) | |
235 { | |
236 Stop(); | |
237 isThreaded_ = isThreaded; | |
238 } | |
239 | |
240 bool DicomServer::IsThreaded() const | |
241 { | |
242 return isThreaded_; | |
243 } | |
244 | |
245 void DicomServer::SetClientTimeout(uint32_t timeout) | |
246 { | |
247 Stop(); | |
248 clientTimeout_ = timeout; | |
249 } | |
250 | |
251 uint32_t DicomServer::GetClientTimeout() const | |
252 { | |
253 return clientTimeout_; | |
254 } | |
255 | |
256 | |
257 void DicomServer::SetCalledApplicationEntityTitleCheck(bool check) | |
258 { | |
259 Stop(); | |
260 checkCalledAet_ = check; | |
261 } | |
262 | |
263 bool DicomServer::HasCalledApplicationEntityTitleCheck() const | |
264 { | |
265 return checkCalledAet_; | |
266 } | |
267 | |
268 void DicomServer::SetApplicationEntityTitle(const std::string& aet) | |
269 { | |
270 if (aet.size() == 0) | |
271 { | |
62 | 272 throw OrthancException("Too short AET"); |
0 | 273 } |
274 | |
275 for (size_t i = 0; i < aet.size(); i++) | |
276 { | |
277 if (!isalnum(aet[i]) && aet[i] != '-') | |
278 { | |
62 | 279 throw OrthancException("Only alphanumeric characters are allowed in AET"); |
0 | 280 } |
281 } | |
282 | |
283 Stop(); | |
284 aet_ = aet; | |
285 } | |
286 | |
287 const std::string& DicomServer::GetApplicationEntityTitle() const | |
288 { | |
289 return aet_; | |
290 } | |
291 | |
292 void DicomServer::SetFindRequestHandlerFactory(IFindRequestHandlerFactory& factory) | |
293 { | |
294 Stop(); | |
295 findRequestHandlerFactory_ = &factory; | |
296 } | |
297 | |
298 bool DicomServer::HasFindRequestHandlerFactory() const | |
299 { | |
300 return (findRequestHandlerFactory_ != NULL); | |
301 } | |
302 | |
303 IFindRequestHandlerFactory& DicomServer::GetFindRequestHandlerFactory() const | |
304 { | |
305 if (HasFindRequestHandlerFactory()) | |
306 { | |
307 return *findRequestHandlerFactory_; | |
308 } | |
309 else | |
310 { | |
62 | 311 throw OrthancException("No C-FIND request handler factory"); |
0 | 312 } |
313 } | |
314 | |
315 void DicomServer::SetMoveRequestHandlerFactory(IMoveRequestHandlerFactory& factory) | |
316 { | |
317 Stop(); | |
318 moveRequestHandlerFactory_ = &factory; | |
319 } | |
320 | |
321 bool DicomServer::HasMoveRequestHandlerFactory() const | |
322 { | |
323 return (moveRequestHandlerFactory_ != NULL); | |
324 } | |
325 | |
326 IMoveRequestHandlerFactory& DicomServer::GetMoveRequestHandlerFactory() const | |
327 { | |
328 if (HasMoveRequestHandlerFactory()) | |
329 { | |
330 return *moveRequestHandlerFactory_; | |
331 } | |
332 else | |
333 { | |
62 | 334 throw OrthancException("No C-MOVE request handler factory"); |
0 | 335 } |
336 } | |
337 | |
338 void DicomServer::SetStoreRequestHandlerFactory(IStoreRequestHandlerFactory& factory) | |
339 { | |
340 Stop(); | |
341 storeRequestHandlerFactory_ = &factory; | |
342 } | |
343 | |
344 bool DicomServer::HasStoreRequestHandlerFactory() const | |
345 { | |
346 return (storeRequestHandlerFactory_ != NULL); | |
347 } | |
348 | |
349 IStoreRequestHandlerFactory& DicomServer::GetStoreRequestHandlerFactory() const | |
350 { | |
351 if (HasStoreRequestHandlerFactory()) | |
352 { | |
353 return *storeRequestHandlerFactory_; | |
354 } | |
355 else | |
356 { | |
62 | 357 throw OrthancException("No C-STORE request handler factory"); |
0 | 358 } |
359 } | |
360 | |
361 void DicomServer::SetApplicationEntityFilter(IApplicationEntityFilter& factory) | |
362 { | |
363 Stop(); | |
364 applicationEntityFilter_ = &factory; | |
365 } | |
366 | |
367 bool DicomServer::HasApplicationEntityFilter() const | |
368 { | |
369 return (applicationEntityFilter_ != NULL); | |
370 } | |
371 | |
372 IApplicationEntityFilter& DicomServer::GetApplicationEntityFilter() const | |
373 { | |
374 if (HasApplicationEntityFilter()) | |
375 { | |
376 return *applicationEntityFilter_; | |
377 } | |
378 else | |
379 { | |
62 | 380 throw OrthancException("No application entity filter"); |
0 | 381 } |
382 } | |
383 | |
384 void DicomServer::Start() | |
385 { | |
386 Stop(); | |
387 continue_ = true; | |
388 started_ = false; | |
389 pimpl_->thread_ = boost::thread(ServerThread, this); | |
390 | |
391 while (!started_) | |
392 { | |
393 Toolbox::USleep(50000); // Wait 50ms | |
394 } | |
395 } | |
396 | |
397 void DicomServer::Stop() | |
398 { | |
399 continue_ = false; | |
431
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
400 |
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
401 if (pimpl_->thread_.joinable()) |
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
402 { |
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
403 pimpl_->thread_.join(); |
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
404 } |
0 | 405 |
406 bagOfDispatchers_.StopAll(); | |
407 } | |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
408 |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
409 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
|
410 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
411 if (!HasCalledApplicationEntityTitleCheck()) |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
412 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
413 // OK, no check on the AET. |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
414 return true; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
415 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
416 |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
417 return Orthanc::IsSameAETitle(aet, GetApplicationEntityTitle()); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
418 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
419 |
0 | 420 } |