Mercurial > hg > orthanc-stone
annotate Applications/Platforms/WebAssembly/WebAssemblyOracle.cpp @ 1730:af4a2d08549c
preparing for release
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 02 Dec 2020 12:47:05 +0100 |
parents | 81273beabc9f |
children | 9ac2a65d4172 |
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. | |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1591
diff
changeset
|
16 * |
825 | 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 /** |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
86 This object is created on the heap for every http request. |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
87 It is deleted in the success (or error) callbacks. |
825 | 88 |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
89 This object references the receiver of the request. Since this is a raw |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
90 reference, we need additional checks to make sure we send the response to |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
91 the same object, for the object can be deleted and a new one recreated at the |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
92 same address (it often happens in the [single-threaded] browser context). |
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
|
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 | |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
130 void EmitException(const Orthanc::OrthancException& exception) |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
131 { |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
132 assert(command_.get() != NULL); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
133 OracleCommandExceptionMessage message(*command_, exception); |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
134 oracle_.EmitMessage(receiver_, message); |
825 | 135 } |
136 | |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
137 void ProcessFetchResult(const std::string& answer, |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
138 const HttpHeaders& headers) |
825 | 139 { |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
140 assert(command_.get() != NULL); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
141 oracle_.ProcessFetchResult(receiver_, answer, headers, *command_); |
825 | 142 } |
143 | |
144 static void SuccessCallback(emscripten_fetch_t *fetch) | |
145 { | |
146 /** | |
147 * Firstly, make a local copy of the fetched information, and | |
148 * free data associated with the fetch. | |
149 **/ | |
150 | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
151 if (fetch->userData == NULL) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
152 { |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
153 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
|
154 return; |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
155 } |
825 | 156 |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
157 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
|
158 |
825 | 159 std::string answer; |
160 if (fetch->numBytes > 0) | |
161 { | |
162 answer.assign(fetch->data, fetch->numBytes); | |
163 } | |
164 | |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
165 |
825 | 166 /** |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
167 * Retrieving the headers of the HTTP answer. |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
168 **/ |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
169 HttpHeaders headers; |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
170 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
171 #if (__EMSCRIPTEN_major__ < 1 || \ |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
172 (__EMSCRIPTEN_major__ == 1 && __EMSCRIPTEN_minor__ < 38) || \ |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
173 (__EMSCRIPTEN_major__ == 1 && __EMSCRIPTEN_minor__ == 38 && __EMSCRIPTEN_tiny__ < 37)) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
174 # 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
|
175 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
176 /** |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
177 * 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
|
178 * 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
|
179 * 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
|
180 * 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
|
181 * query. This is fixed thanks to the |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
182 * "emscripten_fetch_get_response_headers()" function that was |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
183 * 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
|
184 * |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
185 * https://github.com/emscripten-core/emscripten/blob/1.38.37/system/include/emscripten/fetch.h |
825 | 186 * https://github.com/emscripten-core/emscripten/pull/8486 |
187 **/ | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
188 if (fetch->userData != NULL) |
825 | 189 { |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
190 if (!context->GetExpectedContentType().empty()) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
191 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
192 headers["Content-Type"] = context->GetExpectedContentType(); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
193 } |
825 | 194 } |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
195 #else |
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 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
|
198 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
199 std::string plainHeaders(size + 1, '\0'); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
200 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
|
201 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
202 std::vector<std::string> tokens; |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
203 Orthanc::Toolbox::TokenizeString(tokens, plainHeaders, '\n'); |
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 for (size_t i = 0; i < tokens.size(); i++) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
206 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
207 size_t p = tokens[i].find(':'); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
208 if (p != std::string::npos) |
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 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
|
211 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
|
212 headers[key] = value; |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
213 } |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
214 } |
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
|
215 } |
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
|
216 #endif |
825 | 217 |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
218 LOG(TRACE) << "About to call emscripten_fetch_close"; |
825 | 219 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
|
220 LOG(TRACE) << "Successfully called emscripten_fetch_close"; |
825 | 221 |
222 /** | |
223 * 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
|
224 * 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
|
225 * by the object responsible for zombie check, later on. |
825 | 226 **/ |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
227 try |
973
38409549db43
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
971
diff
changeset
|
228 { |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
229 if (context.get() == NULL) |
825 | 230 { |
975
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
231 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
|
232 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
|
233 } |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
234 else |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
235 { |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
236 context->ProcessFetchResult(answer, headers); |
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 } |
e75fd08d6c75
Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents:
973
diff
changeset
|
239 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
|
240 { |
1255
c1c83c1fb837
GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1245
diff
changeset
|
241 LOG(INFO) << "Error while processing a fetch answer in the oracle: " << e.What(); |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
242 context->EmitException(e); |
825 | 243 } |
244 } | |
245 | |
246 static void FailureCallback(emscripten_fetch_t *fetch) | |
247 { | |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
248 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
|
249 |
1572 | 250 #if 0 |
995
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
251 { |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
252 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
|
253 char message[kEmscriptenStatusTextSize + 1]; |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
254 memcpy(message, fetch->statusText, kEmscriptenStatusTextSize); |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
255 message[kEmscriptenStatusTextSize] = 0; |
959
13e078adfb94
Better error log in fetch failure callback +
Benjamin Golinvaux <bgo@osimis.io>
parents:
956
diff
changeset
|
256 |
1572 | 257 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
|
258 << " 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
|
259 << " | statusText = " << message |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
260 << " | numBytes = " << fetch->numBytes |
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
261 << " | totalBytes = " << fetch->totalBytes |
1572 | 262 << " | readyState = " << fetch->readyState; |
995
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
263 } |
1572 | 264 #endif |
825 | 265 |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
266 context->EmitException(Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol)); |
995
9893fa8cd7a6
send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
992
diff
changeset
|
267 |
825 | 268 /** |
269 * TODO - The following code leads to an infinite recursion, at | |
270 * least with Firefox running on incognito mode => WHY? | |
271 **/ | |
959
13e078adfb94
Better error log in fetch failure callback +
Benjamin Golinvaux <bgo@osimis.io>
parents:
956
diff
changeset
|
272 emscripten_fetch_close(fetch); // Also free data on failure. |
825 | 273 } |
274 }; | |
275 | |
276 | |
277 | |
278 class WebAssemblyOracle::FetchCommand : public boost::noncopyable | |
279 { | |
280 private: | |
281 WebAssemblyOracle& oracle_; | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
282 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
|
283 std::unique_ptr<IOracleCommand> command_; |
825 | 284 Orthanc::HttpMethod method_; |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
285 std::string url_; |
825 | 286 std::string body_; |
287 HttpHeaders headers_; | |
288 unsigned int timeout_; | |
289 std::string expectedContentType_; | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
290 bool hasCredentials_; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
291 std::string username_; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
292 std::string password_; |
825 | 293 |
294 public: | |
295 FetchCommand(WebAssemblyOracle& oracle, | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
296 boost::weak_ptr<IObserver> receiver, |
825 | 297 IOracleCommand* command) : |
298 oracle_(oracle), | |
299 receiver_(receiver), | |
300 command_(command), | |
301 method_(Orthanc::HttpMethod_Get), | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
302 timeout_(0), |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
303 hasCredentials_(false) |
825 | 304 { |
305 if (command == NULL) | |
306 { | |
307 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
308 } | |
309 } | |
310 | |
311 void SetMethod(Orthanc::HttpMethod method) | |
312 { | |
313 method_ = method; | |
314 } | |
315 | |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
316 Orthanc::HttpMethod GetMethod() const |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
317 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
318 return method_; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
319 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
320 |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
321 void SetUrl(const std::string& url) |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
322 { |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
323 url_ = url; |
825 | 324 } |
325 | |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
326 const std::string& GetUrl() const |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
327 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
328 return url_; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
329 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
330 |
825 | 331 void SetBody(std::string& body /* will be swapped */) |
332 { | |
333 body_.swap(body); | |
334 } | |
335 | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
336 void AddHttpHeaders(const HttpHeaders& headers) |
825 | 337 { |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
338 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
|
339 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
340 headers_[it->first] = it->second; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
341 } |
825 | 342 } |
343 | |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
344 const HttpHeaders& GetHttpHeaders() const |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
345 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
346 return headers_; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
347 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
348 |
825 | 349 void SetTimeout(unsigned int timeout) |
350 { | |
351 timeout_ = timeout; | |
352 } | |
353 | |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
354 unsigned int GetTimeout() const |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
355 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
356 return timeout_; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
357 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
358 |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
359 void SetCredentials(const std::string& username, |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
360 const std::string& password) |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
361 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
362 hasCredentials_ = true; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
363 username_ = username; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
364 password_ = password; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
365 } |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
366 |
825 | 367 void Execute() |
368 { | |
369 if (command_.get() == NULL) | |
370 { | |
371 // 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
|
372 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
|
373 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
825 | 374 } |
375 | |
376 emscripten_fetch_attr_t attr; | |
377 emscripten_fetch_attr_init(&attr); | |
378 | |
379 const char* method; | |
380 | |
381 switch (method_) | |
382 { | |
383 case Orthanc::HttpMethod_Get: | |
384 method = "GET"; | |
385 break; | |
386 | |
387 case Orthanc::HttpMethod_Post: | |
388 method = "POST"; | |
389 break; | |
390 | |
391 case Orthanc::HttpMethod_Delete: | |
392 method = "DELETE"; | |
393 break; | |
394 | |
395 case Orthanc::HttpMethod_Put: | |
396 method = "PUT"; | |
397 break; | |
398 | |
399 default: | |
400 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
401 } | |
402 | |
403 strcpy(attr.requestMethod, method); | |
404 | |
971
bc7b249dfbd0
Added EMSCRIPTEN_FETCH_REPLACE flag to requests to prevent stale cache results
Benjamin Golinvaux <bgo@osimis.io>
parents:
964
diff
changeset
|
405 attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_REPLACE; |
825 | 406 attr.onsuccess = FetchContext::SuccessCallback; |
407 attr.onerror = FetchContext::FailureCallback; | |
408 attr.timeoutMSecs = timeout_ * 1000; | |
409 | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
410 if (hasCredentials_) |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
411 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
412 attr.withCredentials = EM_TRUE; |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
413 attr.userName = username_.c_str(); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
414 attr.password = password_.c_str(); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
415 } |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
416 |
825 | 417 std::vector<const char*> headers; |
418 headers.reserve(2 * headers_.size() + 1); | |
419 | |
420 std::string expectedContentType; | |
421 | |
422 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it) | |
423 { | |
424 std::string key; | |
425 Orthanc::Toolbox::ToLowerCase(key, it->first); | |
426 | |
427 if (key == "accept") | |
428 { | |
429 expectedContentType = it->second; | |
430 } | |
431 | |
432 if (key != "accept-encoding") // Web browsers forbid the modification of this HTTP header | |
433 { | |
434 headers.push_back(it->first.c_str()); | |
435 headers.push_back(it->second.c_str()); | |
436 } | |
437 } | |
438 | |
439 headers.push_back(NULL); // Termination of the array of HTTP headers | |
440 | |
441 attr.requestHeaders = &headers[0]; | |
442 | |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
443 char* requestData = NULL; |
825 | 444 if (!body_.empty()) |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
445 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
|
446 |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
447 try |
825 | 448 { |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
449 if (!body_.empty()) |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
450 { |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
451 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
|
452 attr.requestDataSize = body_.size(); |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
453 attr.requestData = requestData; |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
454 } |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
455 attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType); |
825 | 456 |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
457 // 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
|
458 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
|
459 } |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
460 catch(...) |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
461 { |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
462 if(requestData != NULL) |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
463 free(requestData); |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
464 throw; |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
465 } |
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
831
diff
changeset
|
466 } |
825 | 467 }; |
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
|
468 |
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
|
469 |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
470 void WebAssemblyOracle::ProcessFetchResult(boost::weak_ptr<IObserver>& receiver, |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
471 const std::string& answer, |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
472 const HttpHeaders& headers, |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
473 const IOracleCommand& command) |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
474 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
475 switch (command.GetType()) |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
476 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
477 case IOracleCommand::Type_Http: |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
478 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
479 HttpCommand::SuccessMessage message(dynamic_cast<const HttpCommand&>(command), headers, answer); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
480 EmitMessage(receiver, message); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
481 break; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
482 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
483 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
484 case IOracleCommand::Type_OrthancRestApi: |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
485 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
486 LOG(TRACE) << "WebAssemblyOracle::FetchContext::SuccessCallback. About to call EmitMessage(message);"; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
487 OrthancRestApiCommand::SuccessMessage message |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
488 (dynamic_cast<const OrthancRestApiCommand&>(command), headers, answer); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
489 EmitMessage(receiver, message); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
490 break; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
491 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
492 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
493 case IOracleCommand::Type_GetOrthancImage: |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
494 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
495 dynamic_cast<const GetOrthancImageCommand&>(command).ProcessHttpAnswer(receiver, *this, answer, headers); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
496 break; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
497 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
498 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
499 case IOracleCommand::Type_GetOrthancWebViewerJpeg: |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
500 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
501 dynamic_cast<const GetOrthancWebViewerJpegCommand&>(command).ProcessHttpAnswer(receiver, *this, answer); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
502 break; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
503 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
504 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
505 case IOracleCommand::Type_ParseDicomFromWado: |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
506 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
507 #if ORTHANC_ENABLE_DCMTK == 1 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
508 const ParseDicomFromWadoCommand& c = dynamic_cast<const ParseDicomFromWadoCommand&>(command); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
509 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
510 size_t fileSize; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
511 std::unique_ptr<Orthanc::ParsedDicomFile> dicom |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
512 (ParseDicomSuccessMessage::ParseWadoAnswer(fileSize, answer, headers)); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
513 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
514 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
515 ParseDicomSuccessMessage message(c, c.GetSource(), *dicom, fileSize, true); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
516 EmitMessage(receiver, message); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
517 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
518 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
519 if (dicomCache_.get()) |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
520 { |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
521 // Store it into the cache for future use |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
522 dicomCache_->Acquire(BUCKET_SOP, c.GetSopInstanceUid(), dicom.release(), fileSize, true); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
523 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
524 #else |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
525 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
526 #endif |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
527 break; |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
528 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
529 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
530 default: |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
531 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle (in SuccessCallback): " |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
532 << command.GetType(); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
533 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
534 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
535 } |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
536 |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
537 |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
538 void WebAssemblyOracle::SetOrthancUrl(FetchCommand& command, |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
539 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
|
540 { |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
541 if (isLocalOrthanc_) |
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(localOrthancRoot_ + uri); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
544 } |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
545 else |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
546 { |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
547 command.SetUrl(remoteOrthanc_.GetUrl() + uri); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
548 command.AddHttpHeaders(remoteOrthanc_.GetHttpHeaders()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
549 |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
550 if (!remoteOrthanc_.GetUsername().empty()) |
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.SetCredentials(remoteOrthanc_.GetUsername(), remoteOrthanc_.GetPassword()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
553 } |
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
|
554 } |
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
|
555 } |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
556 |
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
|
557 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
558 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
|
559 HttpCommand* command) |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
560 { |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
561 FetchCommand fetch(*this, receiver, command); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
562 |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
563 fetch.SetMethod(command->GetMethod()); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
564 fetch.SetUrl(command->GetUrl()); |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
565 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
566 fetch.SetTimeout(command->GetTimeout()); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
567 |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
568 if (command->GetMethod() == Orthanc::HttpMethod_Post || |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
569 command->GetMethod() == Orthanc::HttpMethod_Put) |
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 std::string body; |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
572 command->SwapBody(body); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
573 fetch.SetBody(body); |
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 |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
576 fetch.Execute(); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
577 } |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
578 |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
579 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
580 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
825 | 581 OrthancRestApiCommand* command) |
582 { | |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
583 try |
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 //LOG(TRACE) << "*********** WebAssemblyOracle::Execute."; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
586 //LOG(TRACE) << "WebAssemblyOracle::Execute | command = " << command; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
587 FetchCommand fetch(*this, receiver, command); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
588 |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
589 fetch.SetMethod(command->GetMethod()); |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
590 SetOrthancUrl(fetch, command->GetUri()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
591 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
592 fetch.SetTimeout(command->GetTimeout()); |
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 if (command->GetMethod() == Orthanc::HttpMethod_Post || |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
595 command->GetMethod() == Orthanc::HttpMethod_Put) |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
596 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
597 std::string body; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
598 command->SwapBody(body); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
599 fetch.SetBody(body); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
600 } |
825 | 601 |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
602 fetch.Execute(); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
603 //LOG(TRACE) << "*********** successful end of WebAssemblyOracle::Execute."; |
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 catch (const Orthanc::OrthancException& e) |
825 | 606 { |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
607 if (e.HasDetails()) |
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() << " Details: " << e.GetDetails(); |
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 else |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
612 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
613 LOG(ERROR) << "OrthancException in WebAssemblyOracle::Execute: " << e.What(); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
614 } |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
615 //LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute."; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
616 throw; |
825 | 617 } |
933
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
618 catch (const std::exception& e) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
619 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
620 LOG(ERROR) << "std::exception in WebAssemblyOracle::Execute: " << e.what(); |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
621 // LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute."; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
622 throw; |
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 catch (...) |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
625 { |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
626 LOG(ERROR) << "Unknown exception in WebAssemblyOracle::Execute"; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
627 // LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute."; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
628 throw; |
f75f6cb69c1b
Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents:
843
diff
changeset
|
629 } |
825 | 630 } |
631 | |
632 | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
633 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
825 | 634 GetOrthancImageCommand* command) |
635 { | |
636 FetchCommand fetch(*this, receiver, command); | |
637 | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
638 SetOrthancUrl(fetch, command->GetUri()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
639 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
825 | 640 fetch.SetTimeout(command->GetTimeout()); |
641 | |
642 fetch.Execute(); | |
643 } | |
644 | |
645 | |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
646 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
825 | 647 GetOrthancWebViewerJpegCommand* command) |
648 { | |
649 FetchCommand fetch(*this, receiver, command); | |
650 | |
1242
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
651 SetOrthancUrl(fetch, command->GetUri()); |
b9b5d4378874
working of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1229
diff
changeset
|
652 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
825 | 653 fetch.SetTimeout(command->GetTimeout()); |
654 | |
655 fetch.Execute(); | |
656 } | |
657 | |
658 | |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
659 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
660 ParseDicomFromWadoCommand* command) |
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
661 { |
1299
c38c89684d83
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
662 std::unique_ptr<ParseDicomFromWadoCommand> protection(command); |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
663 |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
664 #if ORTHANC_ENABLE_DCMTK == 1 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
665 if (dicomCache_.get()) |
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 ParsedDicomCache::Reader reader(*dicomCache_, BUCKET_SOP, protection->GetSopInstanceUid()); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
668 if (reader.IsValid() && |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
669 reader.HasPixelData()) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
670 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
671 // 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
|
672 ParseDicomSuccessMessage message(*protection, protection->GetSource(), reader.GetDicom(), |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
673 reader.GetFileSize(), reader.HasPixelData()); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
674 EmitMessage(receiver, message); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
675 return; |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
676 } |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
677 } |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
678 #endif |
825 | 679 |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
680 switch (command->GetRestCommand().GetType()) |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
681 { |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
682 case IOracleCommand::Type_Http: |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
683 { |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
684 const HttpCommand& rest = |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
685 dynamic_cast<const HttpCommand&>(protection->GetRestCommand()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
686 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
687 FetchCommand fetch(*this, receiver, protection.release()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
688 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
689 fetch.SetMethod(rest.GetMethod()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
690 fetch.SetUrl(rest.GetUrl()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
691 fetch.AddHttpHeaders(rest.GetHttpHeaders()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
692 fetch.SetTimeout(rest.GetTimeout()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
693 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
694 if (rest.GetMethod() == Orthanc::HttpMethod_Post || |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
695 rest.GetMethod() == Orthanc::HttpMethod_Put) |
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 std::string body = rest.GetBody(); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
698 fetch.SetBody(body); |
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 fetch.Execute(); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
702 break; |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
703 } |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
704 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
705 case IOracleCommand::Type_OrthancRestApi: |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
706 { |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
707 const OrthancRestApiCommand& rest = |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
708 dynamic_cast<const OrthancRestApiCommand&>(protection->GetRestCommand()); |
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 FetchCommand fetch(*this, receiver, protection.release()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
711 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
712 fetch.SetMethod(rest.GetMethod()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
713 SetOrthancUrl(fetch, rest.GetUri()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
714 fetch.AddHttpHeaders(rest.GetHttpHeaders()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
715 fetch.SetTimeout(rest.GetTimeout()); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
716 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
717 if (rest.GetMethod() == Orthanc::HttpMethod_Post || |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
718 rest.GetMethod() == Orthanc::HttpMethod_Put) |
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 std::string body = rest.GetBody(); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
721 fetch.SetBody(body); |
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 fetch.Execute(); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
725 break; |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
726 } |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
727 |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
728 default: |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
729 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
730 } |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
731 } |
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
732 |
825 | 733 |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
734 bool WebAssemblyOracle::Schedule(boost::shared_ptr<IObserver> receiver, |
825 | 735 IOracleCommand* command) |
736 { | |
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
|
737 LOG(TRACE) << "WebAssemblyOracle::Schedule : receiver = " |
1468
323bf6040f5d
fix for boost::program_options
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
738 << 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
|
739 |
1298
8a0a62189f46
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
740 std::unique_ptr<IOracleCommand> protection(command); |
825 | 741 |
742 if (command == NULL) | |
743 { | |
744 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
745 } | |
746 | |
747 switch (command->GetType()) | |
748 { | |
992
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
749 case IOracleCommand::Type_Http: |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
750 Execute(receiver, dynamic_cast<HttpCommand*>(protection.release())); |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
751 break; |
a9f5d0742e22
implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
752 |
825 | 753 case IOracleCommand::Type_OrthancRestApi: |
754 Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release())); | |
755 break; | |
756 | |
757 case IOracleCommand::Type_GetOrthancImage: | |
758 Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release())); | |
759 break; | |
760 | |
761 case IOracleCommand::Type_GetOrthancWebViewerJpeg: | |
1524
5bc305a166c2
Re-enabled Jpeg command scheduling in WebAssemblyOracle
Benjamin Golinvaux <bgo@osimis.io>
parents:
1512
diff
changeset
|
762 Execute(receiver, dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.release())); |
825 | 763 break; |
764 | |
765 case IOracleCommand::Type_Sleep: | |
766 { | |
767 unsigned int timeoutMS = dynamic_cast<SleepOracleCommand*>(command)->GetDelay(); | |
768 emscripten_set_timeout(TimeoutContext::Callback, timeoutMS, | |
769 new TimeoutContext(*this, receiver, protection.release())); | |
770 break; | |
771 } | |
772 | |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
773 case IOracleCommand::Type_ParseDicomFromWado: |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
774 #if ORTHANC_ENABLE_DCMTK == 1 |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
775 Execute(receiver, dynamic_cast<ParseDicomFromWadoCommand*>(protection.release())); |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
776 #else |
1723
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
777 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, |
81273beabc9f
refactoring: WebAssemblyOracle::ProcessFetchResult()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1678
diff
changeset
|
778 "DCMTK must be enabled to parse DICOM files"); |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
779 #endif |
1243
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
780 break; |
608983cc2512
removing unused logs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1242
diff
changeset
|
781 |
825 | 782 default: |
1244
b17959d4da06
working on ParseDicomFromWadoCommand for wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1243
diff
changeset
|
783 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
|
784 << command->GetType(); |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
785 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
825 | 786 } |
1229
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
787 |
b9f2a111c5b9
fix compilation of WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1076
diff
changeset
|
788 return true; |
825 | 789 } |
1245
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
790 |
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 void WebAssemblyOracle::SetDicomCacheSize(size_t size) |
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 #if ORTHANC_ENABLE_DCMTK == 1 |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
795 if (size == 0) |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
796 { |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
797 dicomCache_.reset(); |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
798 } |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
799 else |
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 dicomCache_.reset(new ParsedDicomCache(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 #else |
3d4dc87af04b
ParseDicomFromWadoCommand working in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1244
diff
changeset
|
804 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
|
805 #endif |
825 | 806 } |
1675
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
807 |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
808 |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
809 WebAssemblyOracle::CachedInstanceAccessor::CachedInstanceAccessor(WebAssemblyOracle& oracle, |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
810 const std::string& sopInstanceUid) |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
811 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
812 #if ORTHANC_ENABLE_DCMTK == 1 |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
813 if (oracle.dicomCache_.get() != NULL) |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
814 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
815 reader_.reset(new ParsedDicomCache::Reader(*oracle.dicomCache_, BUCKET_SOP, sopInstanceUid)); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
816 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
817 #endif |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
818 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
819 |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
820 bool WebAssemblyOracle::CachedInstanceAccessor::IsValid() const |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
821 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
822 #if ORTHANC_ENABLE_DCMTK == 1 |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
823 return (reader_.get() != NULL && |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
824 reader_->IsValid()); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
825 #else |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
826 return false; |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
827 #endif |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
828 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
829 |
1678 | 830 #if ORTHANC_ENABLE_DCMTK == 1 |
1675
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
831 const Orthanc::ParsedDicomFile& WebAssemblyOracle::CachedInstanceAccessor::GetDicom() const |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
832 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
833 if (IsValid()) |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
834 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
835 assert(reader_.get() != NULL); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
836 return reader_->GetDicom(); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
837 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
838 else |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
839 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
840 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
841 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
842 } |
1678 | 843 #endif |
1675
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
844 |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
845 size_t WebAssemblyOracle::CachedInstanceAccessor::GetFileSize() const |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
846 { |
1678 | 847 #if ORTHANC_ENABLE_DCMTK == 1 |
1675
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
848 if (IsValid()) |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
849 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
850 assert(reader_.get() != NULL); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
851 return reader_->GetFileSize(); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
852 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
853 else |
1678 | 854 #endif |
1675
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
855 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
856 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
857 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
858 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
859 |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
860 bool WebAssemblyOracle::CachedInstanceAccessor::HasPixelData() const |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
861 { |
1678 | 862 #if ORTHANC_ENABLE_DCMTK == 1 |
1675
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
863 if (IsValid()) |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
864 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
865 assert(reader_.get() != NULL); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
866 return reader_->HasPixelData(); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
867 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
868 else |
1678 | 869 #endif |
1675
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
870 { |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
871 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
872 } |
6fa05252b085
don't load low-quality image if the parsed dicom file is cached by the oracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
873 } |
825 | 874 } |