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