Mercurial > hg > orthanc-stone
annotate Framework/Oracle/GenericOracleRunner.cpp @ 1310:9bea7e15b519 broker
- first pass at changes to cope with the refactoring of the loading system
- global loader-related data accessible through ILoadersContext::ILock
- many changes in legacy loaders (CT, RTSTRUCT, DOSE) + loader cache
- NOT FINISHED! there are shared_from_this calls in ctors! this will crash!
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 09 Mar 2020 14:53:22 +0100 |
parents | c38c89684d83 |
children | 30deba7bc8e2 |
rev | line source |
---|---|
1077 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1271
0ca50d275b9a
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1254
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
1077 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "GenericOracleRunner.h" | |
23 | |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
24 #if !defined(ORTHANC_ENABLE_DCMTK) |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
25 # error The macro ORTHANC_ENABLE_DCMTK must be defined |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
26 #endif |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
27 |
1077 | 28 #include "GetOrthancImageCommand.h" |
29 #include "GetOrthancWebViewerJpegCommand.h" | |
30 #include "HttpCommand.h" | |
31 #include "OracleCommandExceptionMessage.h" | |
32 #include "OrthancRestApiCommand.h" | |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
33 #include "ParseDicomFromFileCommand.h" |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
34 #include "ParseDicomFromWadoCommand.h" |
1104 | 35 #include "ReadFileCommand.h" |
1077 | 36 |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
37 #if ORTHANC_ENABLE_DCMTK == 1 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
38 # include "ParseDicomSuccessMessage.h" |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
39 # include <dcmtk/dcmdata/dcdeftag.h> |
1153 | 40 # include <dcmtk/dcmdata/dcfilefo.h> |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
41 static unsigned int BUCKET_DICOMDIR = 0; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
42 static unsigned int BUCKET_SOP = 1; |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
43 #endif |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
44 |
1077 | 45 #include <Core/Compression/GzipCompressor.h> |
46 #include <Core/HttpClient.h> | |
47 #include <Core/OrthancException.h> | |
48 #include <Core/Toolbox.h> | |
1104 | 49 #include <Core/SystemToolbox.h> |
50 | |
51 #include <boost/filesystem.hpp> | |
1077 | 52 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
53 |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
54 |
1077 | 55 namespace OrthancStone |
56 { | |
57 static void CopyHttpHeaders(Orthanc::HttpClient& client, | |
58 const Orthanc::HttpClient::HttpHeaders& headers) | |
59 { | |
60 for (Orthanc::HttpClient::HttpHeaders::const_iterator | |
61 it = headers.begin(); it != headers.end(); it++ ) | |
62 { | |
63 client.AddHeader(it->first, it->second); | |
64 } | |
65 } | |
66 | |
67 | |
68 static void DecodeAnswer(std::string& answer, | |
69 const Orthanc::HttpClient::HttpHeaders& headers) | |
70 { | |
71 Orthanc::HttpCompression contentEncoding = Orthanc::HttpCompression_None; | |
72 | |
73 for (Orthanc::HttpClient::HttpHeaders::const_iterator it = headers.begin(); | |
74 it != headers.end(); ++it) | |
75 { | |
76 std::string s; | |
77 Orthanc::Toolbox::ToLowerCase(s, it->first); | |
78 | |
79 if (s == "content-encoding") | |
80 { | |
81 if (it->second == "gzip") | |
82 { | |
83 contentEncoding = Orthanc::HttpCompression_Gzip; | |
84 } | |
85 else | |
86 { | |
87 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, | |
88 "Unsupported HTTP Content-Encoding: " + it->second); | |
89 } | |
90 | |
91 break; | |
92 } | |
93 } | |
94 | |
95 if (contentEncoding == Orthanc::HttpCompression_Gzip) | |
96 { | |
97 std::string compressed; | |
98 answer.swap(compressed); | |
99 | |
100 Orthanc::GzipCompressor compressor; | |
101 compressor.Uncompress(answer, compressed.c_str(), compressed.size()); | |
102 | |
103 LOG(INFO) << "Uncompressing gzip Encoding: from " << compressed.size() | |
104 << " to " << answer.size() << " bytes"; | |
105 } | |
106 } | |
107 | |
108 | |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
109 static void RunHttpCommand(std::string& answer, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
110 Orthanc::HttpClient::HttpHeaders& answerHeaders, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
111 const HttpCommand& command) |
1077 | 112 { |
113 Orthanc::HttpClient client; | |
114 client.SetUrl(command.GetUrl()); | |
115 client.SetMethod(command.GetMethod()); | |
116 client.SetTimeout(command.GetTimeout()); | |
117 | |
118 CopyHttpHeaders(client, command.GetHttpHeaders()); | |
119 | |
1079
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
120 if (command.HasCredentials()) |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
121 { |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
122 client.SetCredentials(command.GetUsername().c_str(), command.GetPassword().c_str()); |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
123 } |
e6d2ff8f1ab4
credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1077
diff
changeset
|
124 |
1077 | 125 if (command.GetMethod() == Orthanc::HttpMethod_Post || |
126 command.GetMethod() == Orthanc::HttpMethod_Put) | |
127 { | |
128 client.SetBody(command.GetBody()); | |
129 } | |
130 | |
131 client.ApplyAndThrowException(answer, answerHeaders); | |
132 DecodeAnswer(answer, answerHeaders); | |
133 } | |
134 | |
135 | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
136 static void RunInternal(boost::weak_ptr<IObserver> receiver, |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
137 IMessageEmitter& emitter, |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
138 const HttpCommand& command) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
139 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
140 std::string answer; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
141 Orthanc::HttpClient::HttpHeaders answerHeaders; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
142 RunHttpCommand(answer, answerHeaders, command); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
143 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
144 HttpCommand::SuccessMessage message(command, answerHeaders, answer); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
145 emitter.EmitMessage(receiver, message); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
146 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
147 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
148 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
149 static void RunOrthancRestApiCommand(std::string& answer, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
150 Orthanc::HttpClient::HttpHeaders& answerHeaders, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
151 const Orthanc::WebServiceParameters& orthanc, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
152 const OrthancRestApiCommand& command) |
1077 | 153 { |
154 Orthanc::HttpClient client(orthanc, command.GetUri()); | |
1254
7a0460c5e98e
don't follow redirections if contacting the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1153
diff
changeset
|
155 client.SetRedirectionFollowed(false); |
1077 | 156 client.SetMethod(command.GetMethod()); |
157 client.SetTimeout(command.GetTimeout()); | |
158 | |
159 CopyHttpHeaders(client, command.GetHttpHeaders()); | |
160 | |
161 if (command.GetMethod() == Orthanc::HttpMethod_Post || | |
162 command.GetMethod() == Orthanc::HttpMethod_Put) | |
163 { | |
164 client.SetBody(command.GetBody()); | |
165 } | |
166 | |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
167 client.ApplyAndThrowException(answer, answerHeaders); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
168 DecodeAnswer(answer, answerHeaders); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
169 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
170 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
171 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
172 static void RunInternal(boost::weak_ptr<IObserver> receiver, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
173 IMessageEmitter& emitter, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
174 const Orthanc::WebServiceParameters& orthanc, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
175 const OrthancRestApiCommand& command) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
176 { |
1077 | 177 std::string answer; |
178 Orthanc::HttpClient::HttpHeaders answerHeaders; | |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
179 RunOrthancRestApiCommand(answer, answerHeaders, orthanc, command); |
1077 | 180 |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
181 OrthancRestApiCommand::SuccessMessage message(command, answerHeaders, answer); |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
182 emitter.EmitMessage(receiver, message); |
1077 | 183 } |
184 | |
185 | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
186 static void RunInternal(boost::weak_ptr<IObserver> receiver, |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
187 IMessageEmitter& emitter, |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
188 const Orthanc::WebServiceParameters& orthanc, |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
189 const GetOrthancImageCommand& command) |
1077 | 190 { |
191 Orthanc::HttpClient client(orthanc, command.GetUri()); | |
1254
7a0460c5e98e
don't follow redirections if contacting the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1153
diff
changeset
|
192 client.SetRedirectionFollowed(false); |
1077 | 193 client.SetTimeout(command.GetTimeout()); |
194 | |
195 CopyHttpHeaders(client, command.GetHttpHeaders()); | |
196 | |
197 std::string answer; | |
198 Orthanc::HttpClient::HttpHeaders answerHeaders; | |
199 client.ApplyAndThrowException(answer, answerHeaders); | |
200 | |
201 DecodeAnswer(answer, answerHeaders); | |
202 | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
203 command.ProcessHttpAnswer(receiver, emitter, answer, answerHeaders); |
1077 | 204 } |
205 | |
206 | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
207 static void RunInternal(boost::weak_ptr<IObserver> receiver, |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
208 IMessageEmitter& emitter, |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
209 const Orthanc::WebServiceParameters& orthanc, |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
210 const GetOrthancWebViewerJpegCommand& command) |
1077 | 211 { |
212 Orthanc::HttpClient client(orthanc, command.GetUri()); | |
1254
7a0460c5e98e
don't follow redirections if contacting the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1153
diff
changeset
|
213 client.SetRedirectionFollowed(false); |
1077 | 214 client.SetTimeout(command.GetTimeout()); |
215 | |
216 CopyHttpHeaders(client, command.GetHttpHeaders()); | |
217 | |
218 std::string answer; | |
219 Orthanc::HttpClient::HttpHeaders answerHeaders; | |
220 client.ApplyAndThrowException(answer, answerHeaders); | |
221 | |
222 DecodeAnswer(answer, answerHeaders); | |
223 | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
224 command.ProcessHttpAnswer(receiver, emitter, answer); |
1077 | 225 } |
226 | |
227 | |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
228 static std::string GetPath(const std::string& root, |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
229 const std::string& file) |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
230 { |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
231 boost::filesystem::path a(root); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
232 boost::filesystem::path b(file); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
233 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
234 boost::filesystem::path c; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
235 if (b.is_absolute()) |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
236 { |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
237 c = b; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
238 } |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
239 else |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
240 { |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
241 c = a / b; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
242 } |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
243 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
244 return c.string(); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
245 } |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
246 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
247 |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
248 static void RunInternal(boost::weak_ptr<IObserver> receiver, |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
249 IMessageEmitter& emitter, |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
250 const std::string& root, |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
251 const ReadFileCommand& command) |
1104 | 252 { |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
253 std::string path = GetPath(root, command.GetPath()); |
1149
2da8b4d6f8c1
renamed ParsedDicomFileCache as ParsedDicomCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1148
diff
changeset
|
254 LOG(TRACE) << "Oracle reading file: " << path; |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
255 |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
256 std::string content; |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
257 Orthanc::SystemToolbox::ReadFile(content, path, true /* log */); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
258 |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
259 ReadFileCommand::SuccessMessage message(command, content); |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
260 emitter.EmitMessage(receiver, message); |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
261 } |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
262 |
1104 | 263 |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
264 #if ORTHANC_ENABLE_DCMTK == 1 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
265 static Orthanc::ParsedDicomFile* ParseDicom(uint64_t& fileSize, /* OUT */ |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
266 const std::string& path, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
267 bool isPixelData) |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
268 { |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
269 if (!Orthanc::SystemToolbox::IsRegularFile(path)) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
270 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
271 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentFile); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
272 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
273 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
274 LOG(TRACE) << "Parsing DICOM file, " << (isPixelData ? "with" : "without") |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
275 << " pixel data: " << path; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
276 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
277 boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
278 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
279 fileSize = Orthanc::SystemToolbox::GetFileSize(path); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
280 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
281 // Check for 32bit systems |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
282 if (fileSize != static_cast<uint64_t>(static_cast<size_t>(fileSize))) |
1104 | 283 { |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
284 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
285 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
286 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
287 DcmFileFormat dicom; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
288 bool ok; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
289 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
290 if (isPixelData) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
291 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
292 ok = dicom.loadFile(path.c_str()).good(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
293 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
294 else |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
295 { |
1136
42581a6182c8
reactivation of the cache of parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1135
diff
changeset
|
296 #if DCMTK_VERSION_NUMBER >= 362 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
297 /** |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
298 * NB : We could stop at (0x3007, 0x0000) instead of |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
299 * DCM_PixelData as the Stone framework does not use further |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
300 * tags (cf. the Orthanc::DICOM_TAG_* constants), but we still |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
301 * use "PixelData" as this does not change the runtime much, and |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
302 * as it is more explicit. |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
303 **/ |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
304 static const DcmTagKey STOP = DCM_PixelData; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
305 //static const DcmTagKey STOP(0x3007, 0x0000); |
1148 | 306 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
307 ok = dicom.loadFileUntilTag(path.c_str(), EXS_Unknown, EGL_noChange, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
308 DCM_MaxReadLength, ERM_autoDetect, STOP).good(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
309 #else |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
310 // The primitive "loadFileUntilTag" was introduced in DCMTK 3.6.2 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
311 ok = dicom.loadFile(path.c_str()).good(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
312 #endif |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
313 } |
1104 | 314 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
315 if (ok) |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
316 { |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1271
diff
changeset
|
317 std::unique_ptr<Orthanc::ParsedDicomFile> result(new Orthanc::ParsedDicomFile(dicom)); |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
318 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
319 boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
320 LOG(TRACE) << path << ": parsed in " << (end-start).total_milliseconds() << " ms"; |
1136
42581a6182c8
reactivation of the cache of parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1135
diff
changeset
|
321 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
322 return result.release(); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
323 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
324 else |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
325 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
326 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
327 "Cannot parse file: " + path); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
328 } |
1104 | 329 } |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
330 |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
331 |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
332 static void RunInternal(boost::weak_ptr<IObserver> receiver, |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
333 IMessageEmitter& emitter, |
1150 | 334 boost::shared_ptr<ParsedDicomCache> cache, |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
335 const std::string& root, |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
336 const ParseDicomFromFileCommand& command) |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
337 { |
1137
cc029987b6dc
improved cache key
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1136
diff
changeset
|
338 const std::string path = GetPath(root, command.GetPath()); |
cc029987b6dc
improved cache key
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1136
diff
changeset
|
339 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
340 if (cache) |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
341 { |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
342 ParsedDicomCache::Reader reader(*cache, BUCKET_DICOMDIR, path); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
343 if (reader.IsValid() && |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
344 (!command.IsPixelDataIncluded() || |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
345 reader.HasPixelData())) |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
346 { |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
347 // Reuse the DICOM file from the cache |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
348 ParseDicomSuccessMessage message(command, reader.GetDicom(), reader.GetFileSize(), reader.HasPixelData()); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
349 emitter.EmitMessage(receiver, message); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
350 return; |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
351 } |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
352 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
353 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
354 uint64_t fileSize; |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1271
diff
changeset
|
355 std::unique_ptr<Orthanc::ParsedDicomFile> parsed(ParseDicom(fileSize, path, command.IsPixelDataIncluded())); |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
356 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
357 if (fileSize != static_cast<size_t>(fileSize)) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
358 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
359 // Cannot load such a large file on 32-bit architecture |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
360 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
361 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
362 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
363 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
364 ParseDicomSuccessMessage message |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
365 (command, *parsed, static_cast<size_t>(fileSize), command.IsPixelDataIncluded()); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
366 emitter.EmitMessage(receiver, message); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
367 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
368 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
369 if (cache) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
370 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
371 // Store it into the cache for future use |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
372 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
373 // Invalidate to overwrite DICOM instance that would already |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
374 // be stored without pixel data |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
375 cache->Invalidate(BUCKET_DICOMDIR, path); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
376 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
377 cache->Acquire(BUCKET_DICOMDIR, path, parsed.release(), |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
378 static_cast<size_t>(fileSize), command.IsPixelDataIncluded()); |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
379 } |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
380 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
381 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
382 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
383 static void RunInternal(boost::weak_ptr<IObserver> receiver, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
384 IMessageEmitter& emitter, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
385 boost::shared_ptr<ParsedDicomCache> cache, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
386 const Orthanc::WebServiceParameters& orthanc, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
387 const ParseDicomFromWadoCommand& command) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
388 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
389 if (cache) |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
390 { |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
391 ParsedDicomCache::Reader reader(*cache, BUCKET_SOP, command.GetSopInstanceUid()); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
392 if (reader.IsValid() && |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
393 reader.HasPixelData()) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
394 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
395 // Reuse the DICOM file from the cache |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
396 ParseDicomSuccessMessage message(command, reader.GetDicom(), reader.GetFileSize(), reader.HasPixelData()); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
397 emitter.EmitMessage(receiver, message); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
398 return; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
399 } |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
400 } |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
401 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
402 std::string answer; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
403 Orthanc::HttpClient::HttpHeaders answerHeaders; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
404 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
405 switch (command.GetRestCommand().GetType()) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
406 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
407 case IOracleCommand::Type_Http: |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
408 RunHttpCommand(answer, answerHeaders, dynamic_cast<const HttpCommand&>(command.GetRestCommand())); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
409 break; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
410 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
411 case IOracleCommand::Type_OrthancRestApi: |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
412 RunOrthancRestApiCommand(answer, answerHeaders, orthanc, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
413 dynamic_cast<const OrthancRestApiCommand&>(command.GetRestCommand())); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
414 break; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
415 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
416 default: |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
417 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
418 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
419 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
420 size_t fileSize; |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1271
diff
changeset
|
421 std::unique_ptr<Orthanc::ParsedDicomFile> parsed(ParseDicomSuccessMessage::ParseWadoAnswer(fileSize, answer, answerHeaders)); |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
422 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
423 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
424 ParseDicomSuccessMessage message(command, *parsed, fileSize, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
425 true /* pixel data always is included in WADO-RS */); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
426 emitter.EmitMessage(receiver, message); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
427 } |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
428 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
429 if (cache) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
430 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
431 // Store it into the cache for future use |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
432 cache->Acquire(BUCKET_SOP, command.GetSopInstanceUid(), parsed.release(), fileSize, true); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
433 } |
1124
a8bf81756839
unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1116
diff
changeset
|
434 } |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
435 #endif |
1104 | 436 |
437 | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
438 void GenericOracleRunner::Run(boost::weak_ptr<IObserver> receiver, |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
439 IMessageEmitter& emitter, |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
440 const IOracleCommand& command) |
1077 | 441 { |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
442 Orthanc::ErrorCode error = Orthanc::ErrorCode_Success; |
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
443 |
1077 | 444 try |
445 { | |
446 switch (command.GetType()) | |
447 { | |
448 case IOracleCommand::Type_Sleep: | |
449 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType, | |
450 "Sleep command cannot be executed by the runner"); | |
451 | |
452 case IOracleCommand::Type_Http: | |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
453 RunInternal(receiver, emitter, dynamic_cast<const HttpCommand&>(command)); |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
454 break; |
1077 | 455 |
456 case IOracleCommand::Type_OrthancRestApi: | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
457 RunInternal(receiver, emitter, orthanc_, |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
458 dynamic_cast<const OrthancRestApiCommand&>(command)); |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
459 break; |
1077 | 460 |
461 case IOracleCommand::Type_GetOrthancImage: | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
462 RunInternal(receiver, emitter, orthanc_, |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
463 dynamic_cast<const GetOrthancImageCommand&>(command)); |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
464 break; |
1077 | 465 |
466 case IOracleCommand::Type_GetOrthancWebViewerJpeg: | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
467 RunInternal(receiver, emitter, orthanc_, |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
468 dynamic_cast<const GetOrthancWebViewerJpegCommand&>(command)); |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
469 break; |
1077 | 470 |
1104 | 471 case IOracleCommand::Type_ReadFile: |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
472 RunInternal(receiver, emitter, rootDirectory_, |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
473 dynamic_cast<const ReadFileCommand&>(command)); |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
474 break; |
1104 | 475 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
476 case IOracleCommand::Type_ParseDicomFromFile: |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
477 case IOracleCommand::Type_ParseDicomFromWado: |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
478 #if ORTHANC_ENABLE_DCMTK == 1 |
1151
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
479 switch (command.GetType()) |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
480 { |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
481 case IOracleCommand::Type_ParseDicomFromFile: |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
482 RunInternal(receiver, emitter, dicomCache_, rootDirectory_, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
483 dynamic_cast<const ParseDicomFromFileCommand&>(command)); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
484 break; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
485 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
486 case IOracleCommand::Type_ParseDicomFromWado: |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
487 RunInternal(receiver, emitter, dicomCache_, orthanc_, |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
488 dynamic_cast<const ParseDicomFromWadoCommand&>(command)); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
489 break; |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
490 |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
491 default: |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
492 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
48befc2bf66d
ParseDicomFromWadoCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1150
diff
changeset
|
493 } |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
494 break; |
1110
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
495 #else |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
496 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
497 "DCMTK must be enabled to parse DICOM files"); |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
498 #endif |
b82b74d13830
ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1104
diff
changeset
|
499 |
1077 | 500 default: |
501 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
502 } | |
503 } | |
504 catch (Orthanc::OrthancException& e) | |
505 { | |
506 LOG(ERROR) << "Exception within the oracle: " << e.What(); | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
507 error = e.GetErrorCode(); |
1077 | 508 } |
509 catch (...) | |
510 { | |
511 LOG(ERROR) << "Threaded exception within the oracle"; | |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
512 error = Orthanc::ErrorCode_InternalError; |
1077 | 513 } |
1134
87fbeb823375
allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1128
diff
changeset
|
514 |
1135
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
515 if (error != Orthanc::ErrorCode_Success) |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
516 { |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
517 OracleCommandExceptionMessage message(command, error); |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
518 emitter.EmitMessage(receiver, message); |
a0a33e5ea5bb
IOracleCommand::Clone()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1134
diff
changeset
|
519 } |
1077 | 520 } |
521 } |