Mercurial > hg > orthanc
annotate OrthancServer/DicomProtocol/DicomServer.cpp @ 1417:8e23f16a198d
fix issues 35 and 37
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2015 15:17:02 +0200 |
parents | 6e7e5ed91c2d |
children | c0bdc47165ef |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
0 | 5 * |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "../PrecompiledHeadersServer.h" |
0 | 34 #include "DicomServer.h" |
35 | |
62 | 36 #include "../../Core/OrthancException.h" |
0 | 37 #include "../../Core/Toolbox.h" |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
38 #include "../../Core/Uuid.h" |
0 | 39 #include "../Internals/CommandDispatcher.h" |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
40 #include "../OrthancInitialization.h" |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
41 #include "EmbeddedResources.h" |
0 | 42 |
43 #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
|
44 #include <boost/filesystem.hpp> |
0 | 45 #include <dcmtk/dcmdata/dcdict.h> |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
46 #include <glog/logging.h> |
0 | 47 |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
48 #if defined(__linux) |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
49 #include <cstdlib> |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
50 #endif |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
51 |
0 | 52 |
62 | 53 namespace Orthanc |
0 | 54 { |
55 struct DicomServer::PImpl | |
56 { | |
57 boost::thread thread_; | |
58 | |
59 //std::set< | |
60 }; | |
61 | |
62 | |
660 | 63 #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
64 static void LoadEmbeddedDictionary(DcmDataDictionary& dictionary, |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
65 EmbeddedResources::FileResourceId resource) |
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 Toolbox::TemporaryFile tmp; |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
68 |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
69 FILE* fp = fopen(tmp.GetPath().c_str(), "wb"); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
70 fwrite(EmbeddedResources::GetFileResourceBuffer(resource), |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
71 EmbeddedResources::GetFileResourceSize(resource), 1, fp); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
72 fclose(fp); |
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 if (!dictionary.loadDictionary(tmp.GetPath().c_str())) |
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 throw OrthancException(ErrorCode_InternalError); |
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 } |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
79 |
660 | 80 #else |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 { |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
85 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
|
86 p = p / filename; |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
87 |
494
012b63028085
CMake parameter for the location of DCMTK dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
431
diff
changeset
|
88 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
|
89 |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
90 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
|
91 { |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
92 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
|
93 } |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
94 } |
660 | 95 |
96 #endif | |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
97 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
98 |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
99 void DicomServer::InitializeDictionary() |
0 | 100 { |
101 /* Disable "gethostbyaddr" (which results in memory leaks) and use raw IP addresses */ | |
102 dcmDisableGethostbyaddr.set(OFTrue); | |
103 | |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
104 dcmDataDict.clear(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
105 DcmDataDictionary& d = dcmDataDict.wrlock(); |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
106 |
376
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
107 #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
|
108 LOG(WARNING) << "Loading the embedded dictionaries"; |
357
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 * 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
|
111 * 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
|
112 * dictionary is not loaded by storescu. |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
113 **/ |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
114 //LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_DICONDE); |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
115 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
116 LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_DICOM); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
117 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
|
118 |
890 | 119 #elif defined(__linux) || defined(__FreeBSD_kernel__) |
494
012b63028085
CMake parameter for the location of DCMTK dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
431
diff
changeset
|
120 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
|
121 |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
122 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
|
123 if (env != NULL) |
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 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
|
126 } |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
127 |
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, "dicom.dic"); |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
129 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
|
130 |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
131 #else |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
132 #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
|
133 #endif |
2cef9c2d4148
separate path for SQLite index, manual loading of external dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
357
diff
changeset
|
134 |
291
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
135 dcmDataDict.unlock(); |
4d7469f72a0b
embedding of dicom dictionaries
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
136 |
0 | 137 /* make sure data dictionary is loaded */ |
138 if (!dcmDataDict.isDictionaryLoaded()) | |
139 { | |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
140 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
|
141 throw OrthancException(ErrorCode_InternalError); |
0 | 142 } |
143 | |
357
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 // Test the dictionary with a simple DICOM tag |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
146 DcmTag key(0x0010, 0x1030); // This is PatientWeight |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
147 if (key.getEVR() != EVR_DS) |
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 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
|
150 throw OrthancException(ErrorCode_InternalError); |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
151 } |
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
152 } |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
153 } |
357
8d3a0db39967
fix of standalone builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
298
diff
changeset
|
154 |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
155 |
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
156 void DicomServer::ServerThread(DicomServer* server) |
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
157 { |
0 | 158 /* initialize network, i.e. create an instance of T_ASC_Network*. */ |
159 T_ASC_Network *net; | |
160 OFCondition cond = ASC_initializeNetwork | |
161 (NET_ACCEPTOR, OFstatic_cast(int, server->port_), /*opt_acse_timeout*/ 30, &net); | |
162 if (cond.bad()) | |
163 { | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
164 LOG(ERROR) << "cannot create network: " << cond.text(); |
62 | 165 throw OrthancException("Cannot create network"); |
0 | 166 } |
167 | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
168 LOG(INFO) << "DICOM server started"; |
0 | 169 |
170 server->started_ = true; | |
171 | |
172 while (server->continue_) | |
173 { | |
174 /* receive an association and acknowledge or reject it. If the association was */ | |
175 /* acknowledged, offer corresponding services and invoke one or more if required. */ | |
176 std::auto_ptr<Internals::CommandDispatcher> dispatcher(Internals::AcceptAssociation(*server, net)); | |
177 | |
178 if (dispatcher.get() != NULL) | |
179 { | |
180 if (server->isThreaded_) | |
181 { | |
182 server->bagOfDispatchers_.Add(dispatcher.release()); | |
183 } | |
184 else | |
185 { | |
186 IRunnableBySteps::RunUntilDone(*dispatcher); | |
187 } | |
188 } | |
189 } | |
190 | |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
191 LOG(INFO) << "DICOM server stopping"; |
0 | 192 |
1193
e95e7f9eba96
fix crash when stopping Orthanc during a DICOM connection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
193 if (server->isThreaded_) |
e95e7f9eba96
fix crash when stopping Orthanc during a DICOM connection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
194 { |
e95e7f9eba96
fix crash when stopping Orthanc during a DICOM connection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
195 server->bagOfDispatchers_.StopAll(); |
e95e7f9eba96
fix crash when stopping Orthanc during a DICOM connection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
196 } |
e95e7f9eba96
fix crash when stopping Orthanc during a DICOM connection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
197 |
0 | 198 /* drop the network, i.e. free memory of T_ASC_Network* structure. This call */ |
199 /* is the counterpart of ASC_initializeNetwork(...) which was called above. */ | |
200 cond = ASC_dropNetwork(&net); | |
201 if (cond.bad()) | |
202 { | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
203 LOG(ERROR) << "Error while dropping the network: " << cond.text(); |
0 | 204 } |
205 } | |
206 | |
207 | |
656 | 208 DicomServer::DicomServer() : |
209 pimpl_(new PImpl), | |
210 aet_("ANY-SCP") | |
0 | 211 { |
212 port_ = 104; | |
213 findRequestHandlerFactory_ = NULL; | |
214 moveRequestHandlerFactory_ = NULL; | |
215 storeRequestHandlerFactory_ = NULL; | |
216 applicationEntityFilter_ = NULL; | |
217 checkCalledAet_ = true; | |
218 clientTimeout_ = 30; | |
219 isThreaded_ = true; | |
656 | 220 continue_ = false; |
221 started_ = false; | |
0 | 222 } |
223 | |
224 DicomServer::~DicomServer() | |
225 { | |
226 Stop(); | |
227 } | |
228 | |
128 | 229 void DicomServer::SetPortNumber(uint16_t port) |
0 | 230 { |
231 Stop(); | |
232 port_ = port; | |
233 } | |
234 | |
128 | 235 uint16_t DicomServer::GetPortNumber() const |
0 | 236 { |
237 return port_; | |
238 } | |
239 | |
240 void DicomServer::SetThreaded(bool isThreaded) | |
241 { | |
242 Stop(); | |
243 isThreaded_ = isThreaded; | |
244 } | |
245 | |
246 bool DicomServer::IsThreaded() const | |
247 { | |
248 return isThreaded_; | |
249 } | |
250 | |
251 void DicomServer::SetClientTimeout(uint32_t timeout) | |
252 { | |
253 Stop(); | |
254 clientTimeout_ = timeout; | |
255 } | |
256 | |
257 uint32_t DicomServer::GetClientTimeout() const | |
258 { | |
259 return clientTimeout_; | |
260 } | |
261 | |
262 | |
263 void DicomServer::SetCalledApplicationEntityTitleCheck(bool check) | |
264 { | |
265 Stop(); | |
266 checkCalledAet_ = check; | |
267 } | |
268 | |
269 bool DicomServer::HasCalledApplicationEntityTitleCheck() const | |
270 { | |
271 return checkCalledAet_; | |
272 } | |
273 | |
274 void DicomServer::SetApplicationEntityTitle(const std::string& aet) | |
275 { | |
276 if (aet.size() == 0) | |
277 { | |
62 | 278 throw OrthancException("Too short AET"); |
0 | 279 } |
280 | |
1234 | 281 if (aet.size() > 16) |
282 { | |
283 throw OrthancException("AET must be shorter than 16 characters"); | |
284 } | |
285 | |
0 | 286 for (size_t i = 0; i < aet.size(); i++) |
287 { | |
1243 | 288 if (!(aet[i] == '-' || |
289 aet[i] == '_' || | |
290 isdigit(aet[i]) || | |
291 (aet[i] >= 'A' && aet[i] <= 'Z'))) | |
0 | 292 { |
1234 | 293 LOG(WARNING) << "For best interoperability, only upper case, alphanumeric characters should be present in AET: \"" << aet << "\""; |
294 break; | |
0 | 295 } |
296 } | |
297 | |
298 Stop(); | |
299 aet_ = aet; | |
300 } | |
301 | |
302 const std::string& DicomServer::GetApplicationEntityTitle() const | |
303 { | |
304 return aet_; | |
305 } | |
306 | |
307 void DicomServer::SetFindRequestHandlerFactory(IFindRequestHandlerFactory& factory) | |
308 { | |
309 Stop(); | |
310 findRequestHandlerFactory_ = &factory; | |
311 } | |
312 | |
313 bool DicomServer::HasFindRequestHandlerFactory() const | |
314 { | |
315 return (findRequestHandlerFactory_ != NULL); | |
316 } | |
317 | |
318 IFindRequestHandlerFactory& DicomServer::GetFindRequestHandlerFactory() const | |
319 { | |
320 if (HasFindRequestHandlerFactory()) | |
321 { | |
322 return *findRequestHandlerFactory_; | |
323 } | |
324 else | |
325 { | |
62 | 326 throw OrthancException("No C-FIND request handler factory"); |
0 | 327 } |
328 } | |
329 | |
330 void DicomServer::SetMoveRequestHandlerFactory(IMoveRequestHandlerFactory& factory) | |
331 { | |
332 Stop(); | |
333 moveRequestHandlerFactory_ = &factory; | |
334 } | |
335 | |
336 bool DicomServer::HasMoveRequestHandlerFactory() const | |
337 { | |
338 return (moveRequestHandlerFactory_ != NULL); | |
339 } | |
340 | |
341 IMoveRequestHandlerFactory& DicomServer::GetMoveRequestHandlerFactory() const | |
342 { | |
343 if (HasMoveRequestHandlerFactory()) | |
344 { | |
345 return *moveRequestHandlerFactory_; | |
346 } | |
347 else | |
348 { | |
62 | 349 throw OrthancException("No C-MOVE request handler factory"); |
0 | 350 } |
351 } | |
352 | |
353 void DicomServer::SetStoreRequestHandlerFactory(IStoreRequestHandlerFactory& factory) | |
354 { | |
355 Stop(); | |
356 storeRequestHandlerFactory_ = &factory; | |
357 } | |
358 | |
359 bool DicomServer::HasStoreRequestHandlerFactory() const | |
360 { | |
361 return (storeRequestHandlerFactory_ != NULL); | |
362 } | |
363 | |
364 IStoreRequestHandlerFactory& DicomServer::GetStoreRequestHandlerFactory() const | |
365 { | |
366 if (HasStoreRequestHandlerFactory()) | |
367 { | |
368 return *storeRequestHandlerFactory_; | |
369 } | |
370 else | |
371 { | |
62 | 372 throw OrthancException("No C-STORE request handler factory"); |
0 | 373 } |
374 } | |
375 | |
376 void DicomServer::SetApplicationEntityFilter(IApplicationEntityFilter& factory) | |
377 { | |
378 Stop(); | |
379 applicationEntityFilter_ = &factory; | |
380 } | |
381 | |
382 bool DicomServer::HasApplicationEntityFilter() const | |
383 { | |
384 return (applicationEntityFilter_ != NULL); | |
385 } | |
386 | |
387 IApplicationEntityFilter& DicomServer::GetApplicationEntityFilter() const | |
388 { | |
389 if (HasApplicationEntityFilter()) | |
390 { | |
391 return *applicationEntityFilter_; | |
392 } | |
393 else | |
394 { | |
62 | 395 throw OrthancException("No application entity filter"); |
0 | 396 } |
397 } | |
398 | |
399 void DicomServer::Start() | |
400 { | |
401 Stop(); | |
402 continue_ = true; | |
403 started_ = false; | |
404 pimpl_->thread_ = boost::thread(ServerThread, this); | |
405 | |
406 while (!started_) | |
407 { | |
408 Toolbox::USleep(50000); // Wait 50ms | |
409 } | |
410 } | |
411 | |
412 void DicomServer::Stop() | |
413 { | |
414 continue_ = false; | |
431
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
415 |
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
416 if (pimpl_->thread_.joinable()) |
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
417 { |
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
418 pimpl_->thread_.join(); |
16b52fb8d034
fix by cyril paulus
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
419 } |
0 | 420 } |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
421 |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
422 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
|
423 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
424 if (!HasCalledApplicationEntityTitleCheck()) |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
425 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
426 // OK, no check on the AET. |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
427 return true; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
428 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
429 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
430 return Configuration::IsSameAETitle(aet, GetApplicationEntityTitle()); |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
431 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
432 |
0 | 433 } |