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