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