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