Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Oracle/WebAssemblyOracle.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Oracle/WebAssemblyOracle.cpp@121d01aa328e |
children | 5bc305a166c2 |
rev | line source |
---|---|
825 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1264
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
825 | 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 "WebAssemblyOracle.h" | |
23 | |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
24 #include "OracleCommandExceptionMessage.h" |
825 | 25 #include "SleepOracleCommand.h" |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
26 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
27 #if ORTHANC_ENABLE_DCMTK == 1 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
28 # include "ParseDicomSuccessMessage.h" |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
29 static unsigned int BUCKET_SOP = 1; |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
30 #endif |
825 | 31 |
1484
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1468
diff
changeset
|
32 #include "GetOrthancImageCommand.h" |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1468
diff
changeset
|
33 #include "GetOrthancWebViewerJpegCommand.h" |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1468
diff
changeset
|
34 #include "HttpCommand.h" |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1468
diff
changeset
|
35 #include "OrthancRestApiCommand.h" |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1468
diff
changeset
|
36 #include "ParseDicomFromWadoCommand.h" |
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1468
diff
changeset
|
37 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
38 #include <OrthancException.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1300
diff
changeset
|
39 #include <Toolbox.h> |
825 | 40 |
41 #include <emscripten.h> | |
42 #include <emscripten/html5.h> | |
43 #include <emscripten/fetch.h> | |
44 | |
45 namespace OrthancStone | |
46 { | |
47 class WebAssemblyOracle::TimeoutContext | |
48 { | |
49 private: | |
50 WebAssemblyOracle& oracle_; | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
51 boost::weak_ptr<IObserver> receiver_; |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
52 std::unique_ptr<SleepOracleCommand> command_; |
825 | 53 |
54 public: | |
55 TimeoutContext(WebAssemblyOracle& oracle, | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
56 boost::weak_ptr<IObserver> receiver, |
825 | 57 IOracleCommand* command) : |
58 oracle_(oracle), | |
59 receiver_(receiver) | |
60 { | |
61 if (command == NULL) | |
62 { | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
64 } | |
65 else | |
66 { | |
67 command_.reset(dynamic_cast<SleepOracleCommand*>(command)); | |
68 } | |
69 } | |
70 | |
71 void EmitMessage() | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
72 { |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
73 assert(command_.get() != NULL); |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
74 |
825 | 75 SleepOracleCommand::TimeoutMessage message(*command_); |
76 oracle_.EmitMessage(receiver_, message); | |
77 } | |
78 | |
79 static void Callback(void *userData) | |
80 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
81 std::unique_ptr<TimeoutContext> context(reinterpret_cast<TimeoutContext*>(userData)); |
825 | 82 context->EmitMessage(); |
83 } | |
84 }; | |
85 | |
86 | |
977
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
87 /** |
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
88 This object is created on the heap for every http request. |
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
89 It is deleted in the success (or error) callbacks. |
825 | 90 |
977
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
91 This object references the receiver of the request. Since this is a raw |
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
92 reference, we need additional checks to make sure we send the response to |
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
93 the same object, for the object can be deleted and a new one recreated at the |
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
94 same address (it often happens in the [single-threaded] browser context). |
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
95 */ |
825 | 96 class WebAssemblyOracle::FetchContext : public boost::noncopyable |
97 { | |
98 private: | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
99 WebAssemblyOracle& oracle_; |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
100 boost::weak_ptr<IObserver> receiver_; |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
101 std::unique_ptr<IOracleCommand> command_; |
825 | 102 std::string expectedContentType_; |
103 | |
104 public: | |
105 FetchContext(WebAssemblyOracle& oracle, | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
106 boost::weak_ptr<IObserver> receiver, |
825 | 107 IOracleCommand* command, |
108 const std::string& expectedContentType) : | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
109 oracle_(oracle), |
825 | 110 receiver_(receiver), |
111 command_(command), | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
112 expectedContentType_(expectedContentType) |
825 | 113 { |
1468
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
114 if (Orthanc::Logging::IsTraceLevelEnabled()) |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
115 { |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
116 // Calling "receiver.lock()" is expensive, hence the quick check if TRACE is enabled |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
117 LOG(TRACE) << "WebAssemblyOracle::FetchContext::FetchContext() | " |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
118 << "receiver address = " << std::hex << receiver.lock().get(); |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
119 } |
977
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
120 |
825 | 121 if (command == NULL) |
122 { | |
123 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
124 } | |
125 } | |
126 | |
127 const std::string& GetExpectedContentType() const | |
128 { | |
129 return expectedContentType_; | |
130 } | |
131 | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
132 IMessageEmitter& GetEmitter() const |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
133 { |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
134 return oracle_; |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
135 } |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
136 |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
137 boost::weak_ptr<IObserver> GetReceiver() const |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
138 { |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
139 return receiver_; |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
140 } |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
141 |
825 | 142 void EmitMessage(const IMessage& message) |
143 { | |
1468
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
144 if (Orthanc::Logging::IsTraceLevelEnabled()) |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
145 { |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
146 // Calling "receiver_.lock()" is expensive, hence the quick check if TRACE is enabled |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
147 LOG(TRACE) << "WebAssemblyOracle::FetchContext::EmitMessage receiver_ = " |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
148 << std::hex << receiver_.lock().get() << std::dec; |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
149 } |
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
150 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
151 oracle_.EmitMessage(receiver_, message); |
825 | 152 } |
153 | |
154 IOracleCommand& GetCommand() const | |
155 { | |
156 return *command_; | |
157 } | |
158 | |
159 template <typename T> | |
160 const T& GetTypedCommand() const | |
161 { | |
162 return dynamic_cast<T&>(*command_); | |
163 } | |
164 | |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
165 #if ORTHANC_ENABLE_DCMTK == 1 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
166 void StoreInCache(const std::string& sopInstanceUid, |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
167 std::unique_ptr<Orthanc::ParsedDicomFile>& dicom, |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
168 size_t fileSize) |
964
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
169 { |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
170 if (oracle_.dicomCache_.get()) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
171 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
172 // Store it into the cache for future use |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
173 oracle_.dicomCache_->Acquire(BUCKET_SOP, sopInstanceUid, |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
174 dicom.release(), fileSize, true); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
175 } |
964
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
176 } |
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
177 #endif |
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
178 |
825 | 179 static void SuccessCallback(emscripten_fetch_t *fetch) |
180 { | |
181 /** | |
182 * Firstly, make a local copy of the fetched information, and | |
183 * free data associated with the fetch. | |
184 **/ | |
185 | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
186 if (fetch->userData == NULL) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
187 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
188 LOG(ERROR) << "WebAssemblyOracle::FetchContext::SuccessCallback fetch->userData is NULL!!!!!!!"; |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
189 return; |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
190 } |
825 | 191 |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
192 std::unique_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData)); |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
193 |
825 | 194 std::string answer; |
195 if (fetch->numBytes > 0) | |
196 { | |
197 answer.assign(fetch->data, fetch->numBytes); | |
198 } | |
199 | |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
200 |
825 | 201 /** |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
202 * Retrieving the headers of the HTTP answer. |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
203 **/ |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
204 HttpHeaders headers; |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
205 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
206 #if (__EMSCRIPTEN_major__ < 1 || \ |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
207 (__EMSCRIPTEN_major__ == 1 && __EMSCRIPTEN_minor__ < 38) || \ |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
208 (__EMSCRIPTEN_major__ == 1 && __EMSCRIPTEN_minor__ == 38 && __EMSCRIPTEN_tiny__ < 37)) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
209 # warning Consider upgrading Emscripten to a version above 1.38.37, incomplete support of Fetch API |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
210 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
211 /** |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
212 * HACK - If emscripten < 1.38.37, the fetch API does not |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
213 * contain a way to retrieve the HTTP headers of the answer. We |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
214 * make the assumption that the "Content-Type" header of the |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
215 * response is the same as the "Accept" header of the |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
216 * query. This is fixed thanks to the |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
217 * "emscripten_fetch_get_response_headers()" function that was |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
218 * added to "fetch.h" at emscripten-1.38.37 on 2019-06-26. |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
219 * |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
220 * https://github.com/emscripten-core/emscripten/blob/1.38.37/system/include/emscripten/fetch.h |
825 | 221 * https://github.com/emscripten-core/emscripten/pull/8486 |
222 **/ | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
223 if (fetch->userData != NULL) |
825 | 224 { |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
225 if (!context->GetExpectedContentType().empty()) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
226 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
227 headers["Content-Type"] = context->GetExpectedContentType(); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
228 } |
825 | 229 } |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
230 #else |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
231 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
232 size_t size = emscripten_fetch_get_response_headers_length(fetch); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
233 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
234 std::string plainHeaders(size + 1, '\0'); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
235 emscripten_fetch_get_response_headers(fetch, &plainHeaders[0], size + 1); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
236 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
237 std::vector<std::string> tokens; |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
238 Orthanc::Toolbox::TokenizeString(tokens, plainHeaders, '\n'); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
239 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
240 for (size_t i = 0; i < tokens.size(); i++) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
241 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
242 size_t p = tokens[i].find(':'); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
243 if (p != std::string::npos) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
244 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
245 std::string key = Orthanc::Toolbox::StripSpaces(tokens[i].substr(0, p)); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
246 std::string value = Orthanc::Toolbox::StripSpaces(tokens[i].substr(p + 1)); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
247 headers[key] = value; |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
248 } |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
249 } |
964
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
250 } |
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
251 #endif |
825 | 252 |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
253 LOG(TRACE) << "About to call emscripten_fetch_close"; |
825 | 254 emscripten_fetch_close(fetch); |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
255 LOG(TRACE) << "Successfully called emscripten_fetch_close"; |
825 | 256 |
257 /** | |
258 * Secondly, use the retrieved data. | |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
259 * IMPORTANT NOTE: the receiver might be dead. This is prevented |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
260 * by the object responsible for zombie check, later on. |
825 | 261 **/ |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
262 try |
973
38409549db43
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
971
diff
changeset
|
263 { |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
264 if (context.get() == NULL) |
825 | 265 { |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
266 LOG(ERROR) << "WebAssemblyOracle::FetchContext::SuccessCallback: (context.get() == NULL)"; |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
267 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
268 } |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
269 else |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
270 { |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
271 switch (context->GetCommand().GetType()) |
977
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
272 { |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
273 case IOracleCommand::Type_Http: |
973
38409549db43
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
971
diff
changeset
|
274 { |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
275 HttpCommand::SuccessMessage message(context->GetTypedCommand<HttpCommand>(), headers, answer); |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
276 context->EmitMessage(message); |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
277 break; |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
278 } |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
279 |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
280 case IOracleCommand::Type_OrthancRestApi: |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
281 { |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
282 LOG(TRACE) << "WebAssemblyOracle::FetchContext::SuccessCallback. About to call context->EmitMessage(message);"; |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
283 OrthancRestApiCommand::SuccessMessage message |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
284 (context->GetTypedCommand<OrthancRestApiCommand>(), headers, answer); |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
285 context->EmitMessage(message); |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
286 break; |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
287 } |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
288 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
289 case IOracleCommand::Type_GetOrthancImage: |
973
38409549db43
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
971
diff
changeset
|
290 { |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
291 context->GetTypedCommand<GetOrthancImageCommand>().ProcessHttpAnswer |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
292 (context->GetReceiver(), context->GetEmitter(), answer, headers); |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
293 break; |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
294 } |
973
38409549db43
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
971
diff
changeset
|
295 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
296 case IOracleCommand::Type_GetOrthancWebViewerJpeg: |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
297 { |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
298 context->GetTypedCommand<GetOrthancWebViewerJpegCommand>().ProcessHttpAnswer |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
299 (context->GetReceiver(), context->GetEmitter(), answer); |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
300 break; |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
301 } |
973
38409549db43
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
971
diff
changeset
|
302 |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
303 case IOracleCommand::Type_ParseDicomFromWado: |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
304 { |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
305 #if ORTHANC_ENABLE_DCMTK == 1 |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
306 const ParseDicomFromWadoCommand& command = |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
307 context->GetTypedCommand<ParseDicomFromWadoCommand>(); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
308 |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
309 size_t fileSize; |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
310 std::unique_ptr<Orthanc::ParsedDicomFile> dicom |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
311 (ParseDicomSuccessMessage::ParseWadoAnswer(fileSize, answer, headers)); |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
312 |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
313 { |
1484
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1468
diff
changeset
|
314 ParseDicomSuccessMessage message(command, command.GetSource(), *dicom, fileSize, true); |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
315 context->EmitMessage(message); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
316 } |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
317 |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
318 context->StoreInCache(command.GetSopInstanceUid(), dicom, fileSize); |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
319 #else |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
320 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
321 #endif |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
322 break; |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
323 } |
973
38409549db43
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
971
diff
changeset
|
324 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
325 default: |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
326 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle (in SuccessCallback): " |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
327 << context->GetCommand().GetType(); |
1255
c1c83c1fb837
GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1245
diff
changeset
|
328 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
825 | 329 } |
330 } | |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
331 } |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
332 catch (Orthanc::OrthancException& e) |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
333 { |
1255
c1c83c1fb837
GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1245
diff
changeset
|
334 LOG(INFO) << "Error while processing a fetch answer in the oracle: " << e.What(); |
c1c83c1fb837
GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1245
diff
changeset
|
335 |
c1c83c1fb837
GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1245
diff
changeset
|
336 { |
c1c83c1fb837
GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1245
diff
changeset
|
337 OracleCommandExceptionMessage message(context->GetCommand(), e); |
c1c83c1fb837
GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1245
diff
changeset
|
338 context->EmitMessage(message); |
c1c83c1fb837
GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1245
diff
changeset
|
339 } |
825 | 340 } |
341 } | |
342 | |
343 static void FailureCallback(emscripten_fetch_t *fetch) | |
344 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
345 std::unique_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData)); |
995
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
346 |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
347 { |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
348 const size_t kEmscriptenStatusTextSize = sizeof(emscripten_fetch_t::statusText); |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
349 char message[kEmscriptenStatusTextSize + 1]; |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
350 memcpy(message, fetch->statusText, kEmscriptenStatusTextSize); |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
351 message[kEmscriptenStatusTextSize] = 0; |
959
13e078adfb94
Better error log in fetch failure callback +
Benjamin Golinvaux <bgo@osimis.io>
parents:
956
diff
changeset
|
352 |
996
727f2007ca23
commenting out annoying error
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
353 /*LOG(ERROR) << "Fetching " << fetch->url |
995
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
354 << " failed, HTTP failure status code: " << fetch->status |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
355 << " | statusText = " << message |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
356 << " | numBytes = " << fetch->numBytes |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
357 << " | totalBytes = " << fetch->totalBytes |
996
727f2007ca23
commenting out annoying error
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
358 << " | readyState = " << fetch->readyState;*/ |
995
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
359 } |
825 | 360 |
995
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
361 { |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
362 OracleCommandExceptionMessage message |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
363 (context->GetCommand(), Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol)); |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
364 context->EmitMessage(message); |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
365 } |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
366 |
825 | 367 /** |
368 * TODO - The following code leads to an infinite recursion, at | |
369 * least with Firefox running on incognito mode => WHY? | |
370 **/ | |
959
13e078adfb94
Better error log in fetch failure callback +
Benjamin Golinvaux <bgo@osimis.io>
parents:
956
diff
changeset
|
371 emscripten_fetch_close(fetch); // Also free data on failure. |
825 | 372 } |
373 }; | |
374 | |
375 | |
376 | |
377 class WebAssemblyOracle::FetchCommand : public boost::noncopyable | |
378 { | |
379 private: | |
380 WebAssemblyOracle& oracle_; | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
381 boost::weak_ptr<IObserver> receiver_; |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
382 std::unique_ptr<IOracleCommand> command_; |
825 | 383 Orthanc::HttpMethod method_; |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
384 std::string url_; |
825 | 385 std::string body_; |
386 HttpHeaders headers_; | |
387 unsigned int timeout_; | |
388 std::string expectedContentType_; | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
389 bool hasCredentials_; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
390 std::string username_; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
391 std::string password_; |
825 | 392 |
393 public: | |
394 FetchCommand(WebAssemblyOracle& oracle, | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
395 boost::weak_ptr<IObserver> receiver, |
825 | 396 IOracleCommand* command) : |
397 oracle_(oracle), | |
398 receiver_(receiver), | |
399 command_(command), | |
400 method_(Orthanc::HttpMethod_Get), | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
401 timeout_(0), |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
402 hasCredentials_(false) |
825 | 403 { |
404 if (command == NULL) | |
405 { | |
406 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
407 } | |
408 } | |
409 | |
410 void SetMethod(Orthanc::HttpMethod method) | |
411 { | |
412 method_ = method; | |
413 } | |
414 | |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
415 void SetUrl(const std::string& url) |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
416 { |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
417 url_ = url; |
825 | 418 } |
419 | |
420 void SetBody(std::string& body /* will be swapped */) | |
421 { | |
422 body_.swap(body); | |
423 } | |
424 | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
425 void AddHttpHeaders(const HttpHeaders& headers) |
825 | 426 { |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
427 for (HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it) |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
428 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
429 headers_[it->first] = it->second; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
430 } |
825 | 431 } |
432 | |
433 void SetTimeout(unsigned int timeout) | |
434 { | |
435 timeout_ = timeout; | |
436 } | |
437 | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
438 void SetCredentials(const std::string& username, |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
439 const std::string& password) |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
440 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
441 hasCredentials_ = true; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
442 username_ = username; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
443 password_ = password; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
444 } |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
445 |
825 | 446 void Execute() |
447 { | |
448 if (command_.get() == NULL) | |
449 { | |
450 // Cannot call Execute() twice | |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
933
diff
changeset
|
451 LOG(ERROR) << "WebAssemblyOracle::Execute(): (command_.get() == NULL)"; |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
933
diff
changeset
|
452 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
825 | 453 } |
454 | |
455 emscripten_fetch_attr_t attr; | |
456 emscripten_fetch_attr_init(&attr); | |
457 | |
458 const char* method; | |
459 | |
460 switch (method_) | |
461 { | |
462 case Orthanc::HttpMethod_Get: | |
463 method = "GET"; | |
464 break; | |
465 | |
466 case Orthanc::HttpMethod_Post: | |
467 method = "POST"; | |
468 break; | |
469 | |
470 case Orthanc::HttpMethod_Delete: | |
471 method = "DELETE"; | |
472 break; | |
473 | |
474 case Orthanc::HttpMethod_Put: | |
475 method = "PUT"; | |
476 break; | |
477 | |
478 default: | |
479 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
480 } | |
481 | |
482 strcpy(attr.requestMethod, method); | |
483 | |
971
bc7b249dfbd0
Added EMSCRIPTEN_FETCH_REPLACE flag to requests to prevent stale cache results
Benjamin Golinvaux <bgo@osimis.io>
parents:
964
diff
changeset
|
484 attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_REPLACE; |
825 | 485 attr.onsuccess = FetchContext::SuccessCallback; |
486 attr.onerror = FetchContext::FailureCallback; | |
487 attr.timeoutMSecs = timeout_ * 1000; | |
488 | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
489 if (hasCredentials_) |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
490 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
491 attr.withCredentials = EM_TRUE; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
492 attr.userName = username_.c_str(); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
493 attr.password = password_.c_str(); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
494 } |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
495 |
825 | 496 std::vector<const char*> headers; |
497 headers.reserve(2 * headers_.size() + 1); | |
498 | |
499 std::string expectedContentType; | |
500 | |
501 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it) | |
502 { | |
503 std::string key; | |
504 Orthanc::Toolbox::ToLowerCase(key, it->first); | |
505 | |
506 if (key == "accept") | |
507 { | |
508 expectedContentType = it->second; | |
509 } | |
510 | |
511 if (key != "accept-encoding") // Web browsers forbid the modification of this HTTP header | |
512 { | |
513 headers.push_back(it->first.c_str()); | |
514 headers.push_back(it->second.c_str()); | |
515 } | |
516 } | |
517 | |
518 headers.push_back(NULL); // Termination of the array of HTTP headers | |
519 | |
520 attr.requestHeaders = &headers[0]; | |
521 | |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
522 char* requestData = NULL; |
825 | 523 if (!body_.empty()) |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
524 requestData = reinterpret_cast<char*>(malloc(body_.size())); |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
525 |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
526 try |
825 | 527 { |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
528 if (!body_.empty()) |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
529 { |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
530 memcpy(requestData, &(body_[0]), body_.size()); |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
531 attr.requestDataSize = body_.size(); |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
532 attr.requestData = requestData; |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
533 } |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
534 attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType); |
825 | 535 |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
536 // Must be the last call to prevent memory leak on error |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
537 emscripten_fetch(&attr, url_.c_str()); |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
538 } |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
539 catch(...) |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
540 { |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
541 if(requestData != NULL) |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
542 free(requestData); |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
543 throw; |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
544 } |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
545 } |
825 | 546 }; |
964
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
547 |
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
548 |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
549 void WebAssemblyOracle::SetOrthancUrl(FetchCommand& command, |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
550 const std::string& uri) const |
964
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
551 { |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
552 if (isLocalOrthanc_) |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
553 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
554 command.SetUrl(localOrthancRoot_ + uri); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
555 } |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
556 else |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
557 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
558 command.SetUrl(remoteOrthanc_.GetUrl() + uri); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
559 command.AddHttpHeaders(remoteOrthanc_.GetHttpHeaders()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
560 |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
561 if (!remoteOrthanc_.GetUsername().empty()) |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
562 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
563 command.SetCredentials(remoteOrthanc_.GetUsername(), remoteOrthanc_.GetPassword()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
564 } |
964
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
565 } |
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
566 } |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
567 |
964
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
568 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
569 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
570 HttpCommand* command) |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
571 { |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
572 FetchCommand fetch(*this, receiver, command); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
573 |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
574 fetch.SetMethod(command->GetMethod()); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
575 fetch.SetUrl(command->GetUrl()); |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
576 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
577 fetch.SetTimeout(command->GetTimeout()); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
578 |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
579 if (command->GetMethod() == Orthanc::HttpMethod_Post || |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
580 command->GetMethod() == Orthanc::HttpMethod_Put) |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
581 { |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
582 std::string body; |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
583 command->SwapBody(body); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
584 fetch.SetBody(body); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
585 } |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
586 |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
587 fetch.Execute(); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
588 } |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
589 |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
590 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
591 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
825 | 592 OrthancRestApiCommand* command) |
593 { | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
594 try |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
595 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
596 //LOG(TRACE) << "*********** WebAssemblyOracle::Execute."; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
597 //LOG(TRACE) << "WebAssemblyOracle::Execute | command = " << command; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
598 FetchCommand fetch(*this, receiver, command); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
599 |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
600 fetch.SetMethod(command->GetMethod()); |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
601 SetOrthancUrl(fetch, command->GetUri()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
602 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
603 fetch.SetTimeout(command->GetTimeout()); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
604 |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
605 if (command->GetMethod() == Orthanc::HttpMethod_Post || |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
606 command->GetMethod() == Orthanc::HttpMethod_Put) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
607 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
608 std::string body; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
609 command->SwapBody(body); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
610 fetch.SetBody(body); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
611 } |
825 | 612 |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
613 fetch.Execute(); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
614 //LOG(TRACE) << "*********** successful end of WebAssemblyOracle::Execute."; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
615 } |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
616 catch (const Orthanc::OrthancException& e) |
825 | 617 { |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
618 if (e.HasDetails()) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
619 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
620 LOG(ERROR) << "OrthancException in WebAssemblyOracle::Execute: " << e.What() << " Details: " << e.GetDetails(); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
621 } |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
622 else |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
623 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
624 LOG(ERROR) << "OrthancException in WebAssemblyOracle::Execute: " << e.What(); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
625 } |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
626 //LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute."; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
627 throw; |
825 | 628 } |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
629 catch (const std::exception& e) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
630 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
631 LOG(ERROR) << "std::exception in WebAssemblyOracle::Execute: " << e.what(); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
632 // LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute."; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
633 throw; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
634 } |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
635 catch (...) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
636 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
637 LOG(ERROR) << "Unknown exception in WebAssemblyOracle::Execute"; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
638 // LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute."; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
639 throw; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
640 } |
825 | 641 } |
642 | |
643 | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
644 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
825 | 645 GetOrthancImageCommand* command) |
646 { | |
647 FetchCommand fetch(*this, receiver, command); | |
648 | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
649 SetOrthancUrl(fetch, command->GetUri()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
650 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
825 | 651 fetch.SetTimeout(command->GetTimeout()); |
652 | |
653 fetch.Execute(); | |
654 } | |
655 | |
656 | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
657 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
825 | 658 GetOrthancWebViewerJpegCommand* command) |
659 { | |
660 FetchCommand fetch(*this, receiver, command); | |
661 | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
662 SetOrthancUrl(fetch, command->GetUri()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
663 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
825 | 664 fetch.SetTimeout(command->GetTimeout()); |
665 | |
666 fetch.Execute(); | |
667 } | |
668 | |
669 | |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
670 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
671 ParseDicomFromWadoCommand* command) |
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
672 { |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
673 std::unique_ptr<ParseDicomFromWadoCommand> protection(command); |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
674 |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
675 #if ORTHANC_ENABLE_DCMTK == 1 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
676 if (dicomCache_.get()) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
677 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
678 ParsedDicomCache::Reader reader(*dicomCache_, BUCKET_SOP, protection->GetSopInstanceUid()); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
679 if (reader.IsValid() && |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
680 reader.HasPixelData()) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
681 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
682 // Reuse the DICOM file from the cache |
1484
121d01aa328e
SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1468
diff
changeset
|
683 ParseDicomSuccessMessage message(*protection, protection->GetSource(), reader.GetDicom(), |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
684 reader.GetFileSize(), reader.HasPixelData()); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
685 EmitMessage(receiver, message); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
686 return; |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
687 } |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
688 } |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
689 #endif |
825 | 690 |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
691 switch (command->GetRestCommand().GetType()) |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
692 { |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
693 case IOracleCommand::Type_Http: |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
694 { |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
695 const HttpCommand& rest = |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
696 dynamic_cast<const HttpCommand&>(protection->GetRestCommand()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
697 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
698 FetchCommand fetch(*this, receiver, protection.release()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
699 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
700 fetch.SetMethod(rest.GetMethod()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
701 fetch.SetUrl(rest.GetUrl()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
702 fetch.AddHttpHeaders(rest.GetHttpHeaders()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
703 fetch.SetTimeout(rest.GetTimeout()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
704 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
705 if (rest.GetMethod() == Orthanc::HttpMethod_Post || |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
706 rest.GetMethod() == Orthanc::HttpMethod_Put) |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
707 { |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
708 std::string body = rest.GetBody(); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
709 fetch.SetBody(body); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
710 } |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
711 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
712 fetch.Execute(); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
713 break; |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
714 } |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
715 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
716 case IOracleCommand::Type_OrthancRestApi: |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
717 { |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
718 const OrthancRestApiCommand& rest = |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
719 dynamic_cast<const OrthancRestApiCommand&>(protection->GetRestCommand()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
720 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
721 FetchCommand fetch(*this, receiver, protection.release()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
722 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
723 fetch.SetMethod(rest.GetMethod()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
724 SetOrthancUrl(fetch, rest.GetUri()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
725 fetch.AddHttpHeaders(rest.GetHttpHeaders()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
726 fetch.SetTimeout(rest.GetTimeout()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
727 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
728 if (rest.GetMethod() == Orthanc::HttpMethod_Post || |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
729 rest.GetMethod() == Orthanc::HttpMethod_Put) |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
730 { |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
731 std::string body = rest.GetBody(); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
732 fetch.SetBody(body); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
733 } |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
734 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
735 fetch.Execute(); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
736 break; |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
737 } |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
738 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
739 default: |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
740 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
741 } |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
742 } |
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
743 |
825 | 744 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
745 bool WebAssemblyOracle::Schedule(boost::shared_ptr<IObserver> receiver, |
825 | 746 IOracleCommand* command) |
747 { | |
977
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
748 LOG(TRACE) << "WebAssemblyOracle::Schedule : receiver = " |
1468
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
749 << std::hex << receiver.get(); |
977
262a0244e9b2
Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents:
975
diff
changeset
|
750 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
751 std::unique_ptr<IOracleCommand> protection(command); |
825 | 752 |
753 if (command == NULL) | |
754 { | |
755 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
756 } | |
757 | |
758 switch (command->GetType()) | |
759 { | |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
760 case IOracleCommand::Type_Http: |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
761 Execute(receiver, dynamic_cast<HttpCommand*>(protection.release())); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
762 break; |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
763 |
825 | 764 case IOracleCommand::Type_OrthancRestApi: |
765 Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release())); | |
766 break; | |
767 | |
768 case IOracleCommand::Type_GetOrthancImage: | |
769 Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release())); | |
770 break; | |
771 | |
772 case IOracleCommand::Type_GetOrthancWebViewerJpeg: | |
773 break; | |
774 | |
775 case IOracleCommand::Type_Sleep: | |
776 { | |
777 unsigned int timeoutMS = dynamic_cast<SleepOracleCommand*>(command)->GetDelay(); | |
778 emscripten_set_timeout(TimeoutContext::Callback, timeoutMS, | |
779 new TimeoutContext(*this, receiver, protection.release())); | |
780 break; | |
781 } | |
782 | |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
783 case IOracleCommand::Type_ParseDicomFromWado: |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
784 #if ORTHANC_ENABLE_DCMTK == 1 |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
785 Execute(receiver, dynamic_cast<ParseDicomFromWadoCommand*>(protection.release())); |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
786 #else |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
787 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
788 "DCMTK must be enabled to parse DICOM files"); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
789 #endif |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
790 break; |
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
791 |
825 | 792 default: |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
793 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle (in Schedule): " |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
794 << command->GetType(); |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
795 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
825 | 796 } |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
797 |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
798 return true; |
825 | 799 } |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
800 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
801 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
802 void WebAssemblyOracle::SetDicomCacheSize(size_t size) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
803 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
804 #if ORTHANC_ENABLE_DCMTK == 1 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
805 if (size == 0) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
806 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
807 dicomCache_.reset(); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
808 } |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
809 else |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
810 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
811 dicomCache_.reset(new ParsedDicomCache(size)); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
812 } |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
813 #else |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
814 LOG(INFO) << "DCMTK support is disabled, the DICOM cache is disabled"; |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
815 #endif |
825 | 816 } |
817 } |