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