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