annotate Framework/Oracle/WebAssemblyOracle.cpp @ 1145:4f99c7905f8d broker

mingw qt
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 12 Nov 2019 18:28:46 +0100
parents 008dbc4ceb62
children b9f2a111c5b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "WebAssemblyOracle.h"
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "SleepOracleCommand.h"
995
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
25 #include "OracleCommandExceptionMessage.h"
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <Core/OrthancException.h>
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <Core/Toolbox.h>
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <emscripten.h>
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <emscripten/html5.h>
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <emscripten/fetch.h>
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
34 #if 0
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
35 extern bool logbgo233;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
36 extern bool logbgo115;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
37 #endif
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace OrthancStone
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 class WebAssemblyOracle::TimeoutContext
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 private:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 WebAssemblyOracle& oracle_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 const IObserver& receiver_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 std::auto_ptr<SleepOracleCommand> command_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 public:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 TimeoutContext(WebAssemblyOracle& oracle,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 const IObserver& receiver,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 IOracleCommand* command) :
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 oracle_(oracle),
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 receiver_(receiver)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 if (command == NULL)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 else
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 command_.reset(dynamic_cast<SleepOracleCommand*>(command));
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 void EmitMessage()
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 SleepOracleCommand::TimeoutMessage message(*command_);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 oracle_.EmitMessage(receiver_, message);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 static void Callback(void *userData)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 std::auto_ptr<TimeoutContext> context(reinterpret_cast<TimeoutContext*>(userData));
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 context->EmitMessage();
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 };
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 class WebAssemblyOracle::Emitter : public IMessageEmitter
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 private:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 WebAssemblyOracle& oracle_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 public:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 Emitter(WebAssemblyOracle& oracle) :
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 oracle_(oracle)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 virtual void EmitMessage(const IObserver& receiver,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 const IMessage& message)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
93 LOG(TRACE) << "WebAssemblyOracle::Emitter::EmitMessage receiver = "
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
94 << std::hex << &receiver << std::dec;
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 oracle_.EmitMessage(receiver, message);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 };
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
99 /**
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
100 This object is created on the heap for every http request.
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
101 It is deleted in the success (or error) callbacks.
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
103 This object references the receiver of the request. Since this is a raw
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
104 reference, we need additional checks to make sure we send the response to
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
105 the same object, for the object can be deleted and a new one recreated at the
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
106 same address (it often happens in the [single-threaded] browser context).
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
107 */
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 class WebAssemblyOracle::FetchContext : public boost::noncopyable
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 private:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 Emitter emitter_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 const IObserver& receiver_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 std::auto_ptr<IOracleCommand> command_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 std::string expectedContentType_;
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
115 std::string receiverFingerprint_;
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 public:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 FetchContext(WebAssemblyOracle& oracle,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 const IObserver& receiver,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 IOracleCommand* command,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 const std::string& expectedContentType) :
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 emitter_(oracle),
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 receiver_(receiver),
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 command_(command),
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
125 expectedContentType_(expectedContentType),
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
126 receiverFingerprint_(receiver.GetFingerprint())
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
128 LOG(TRACE) << "WebAssemblyOracle::FetchContext::FetchContext() | "
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
129 << "receiver address = " << std::hex << &receiver << std::dec
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
130 << " with fingerprint = " << receiverFingerprint_;
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
131
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 if (command == NULL)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 const std::string& GetExpectedContentType() const
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 return expectedContentType_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 void EmitMessage(const IMessage& message)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
145 LOG(TRACE) << "WebAssemblyOracle::FetchContext::EmitMessage receiver_ = "
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
146 << std::hex << &receiver_ << std::dec;
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 emitter_.EmitMessage(receiver_, message);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 IMessageEmitter& GetEmitter()
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 return emitter_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 const IObserver& GetReceiver() const
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 return receiver_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 IOracleCommand& GetCommand() const
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 return *command_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 template <typename T>
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 const T& GetTypedCommand() const
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 return dynamic_cast<T&>(*command_);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
171 #if 0
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
172 static std::string ToString(Orthanc::HttpMethod method)
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
173 {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
174 switch (method) {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
175 case Orthanc::HttpMethod_Get:
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
176 return "GET";
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
177 break;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
178 case Orthanc::HttpMethod_Post:
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
179 return "POST";
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
180 break;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
181 default:
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
182 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
183 break;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
184 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
185 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
186 static void DumpCommand(emscripten_fetch_t* fetch, std::string answer)
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
187 {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
188 FetchContext* context = reinterpret_cast<FetchContext*>(fetch->userData);
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
189
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
190 const auto& command = context->GetTypedCommand<OrthancRestApiCommand>();
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
191 auto commandStr = ToString(command.GetMethod());
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
192 LOG(TRACE) << "SuccessCallback for REST command. Method is : " << commandStr;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
193 switch (command.GetMethod()) {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
194 case Orthanc::HttpMethod_Get:
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
195 LOG(TRACE) << " * SuccessCallback GET URI = " << command.GetUri() << " timeout = " << command.GetTimeout();
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
196 LOG(TRACE) << " * SuccessCallback GET RESPONSE = " << answer;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
197 break;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
198 case Orthanc::HttpMethod_Post:
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
199 LOG(TRACE) << " * SuccessCallback POST URI = " << command.GetUri() << " body = " << command.GetBody() << " timeout = " << command.GetTimeout();
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
200 LOG(TRACE) << " * SuccessCallback POST RESPONSE = " << answer;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
201 break;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
202 default:
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
203 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
204 break;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
205 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
206 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
207 #endif
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
208
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 static void SuccessCallback(emscripten_fetch_t *fetch)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 /**
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 * Firstly, make a local copy of the fetched information, and
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 * free data associated with the fetch.
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 **/
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData));
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 971
diff changeset
217
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
218 // an UUID is 36 chars : 32 hex chars + 4 hyphens: char #0 --> char #35
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
219 // char #36 is \0.
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
220 bool callHandler = true;
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
221
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
222 // TODO: remove this line because we are NOT allowed to call methods on GetReceiver that is maybe a dangling ref
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
223 if (context->GetReceiver().DoesFingerprintLookGood())
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
224 {
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
225 callHandler = true;
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
226 std::string currentFingerprint(context->GetReceiver().GetFingerprint());
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
227
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
228 LOG(TRACE) << "SuccessCallback for object at address (" << std::hex
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
229 << &(context->GetReceiver()) << std::dec
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
230 << " with current fingerprint = " << currentFingerprint
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
231 << ". Fingerprint looks OK";
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
232
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
233 if (currentFingerprint != context->receiverFingerprint_)
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
234 {
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
235 LOG(TRACE) << " ** SuccessCallback: BUT currentFingerprint != "
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
236 << "receiverFingerprint_(" << context->receiverFingerprint_ << ")";
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
237 callHandler = false;
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
238 }
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
239 else
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
240 {
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
241 LOG(TRACE) << " ** SuccessCallback: FetchContext-level "
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
242 << "fingerprints are the same: "
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
243 << context->receiverFingerprint_
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
244 << " ---> oracle will dispatch the response to observer: "
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
245 << std::hex << &(context->GetReceiver()) << std::dec;
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
246 }
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
247 }
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
248 else {
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
249 LOG(TRACE) << "SuccessCallback for object at address (" << std::hex << &(context->GetReceiver()) << std::dec << " with current fingerprint is XXXXX -- NOT A VALID FINGERPRINT! OBJECT IS READ ! CALLBACK WILL NOT BE CALLED!";
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
250 callHandler = false;
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
251 }
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
252
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
253 if (fetch->userData == NULL)
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
254 {
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
255 LOG(ERROR) << "WebAssemblyOracle::FetchContext::SuccessCallback fetch->userData is NULL!!!!!!!";
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
256 }
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 std::string answer;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 if (fetch->numBytes > 0)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 answer.assign(fetch->data, fetch->numBytes);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 /**
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 * TODO - HACK - As of emscripten-1.38.31, the fetch API does
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 * not contain a way to retrieve the HTTP headers of the
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 * answer. We make the assumption that the "Content-Type" header
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 * of the response is the same as the "Accept" header of the
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 * query. This should be fixed in future versions of emscripten.
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 * https://github.com/emscripten-core/emscripten/pull/8486
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 **/
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 HttpHeaders headers;
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
274 if (fetch->userData != NULL)
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 {
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
276 if (!context->GetExpectedContentType().empty())
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
277 {
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
278 headers["Content-Type"] = context->GetExpectedContentType();
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
279 }
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
282 #if 0
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
283 if (context->GetCommand().GetType() == IOracleCommand::Type_OrthancRestApi) {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
284 //if (logbgo115)
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
285 DumpCommand(fetch, answer);
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
286 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
287 #endif
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
288 LOG(TRACE) << "About to call emscripten_fetch_close";
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 emscripten_fetch_close(fetch);
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
290 LOG(TRACE) << "Successfully called emscripten_fetch_close";
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 /**
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 * Secondly, use the retrieved data.
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
294 * IMPORTANT NOTE: the receiver might be dead. This is prevented
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
295 * by the object responsible for zombie check, later on.
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 **/
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
297 try
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 971
diff changeset
298 {
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
299 if (context.get() == NULL)
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 {
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
301 LOG(ERROR) << "WebAssemblyOracle::FetchContext::SuccessCallback: (context.get() == NULL)";
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
302 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
303 }
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
304 else
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
305 {
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
306 if (callHandler)
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
307 {
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 971
diff changeset
308 switch (context->GetCommand().GetType())
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 971
diff changeset
309 {
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
310 case IOracleCommand::Type_Http:
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
311 {
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
312 HttpCommand::SuccessMessage message(context->GetTypedCommand<HttpCommand>(), headers, answer);
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
313 context->EmitMessage(message);
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
314 break;
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
315 }
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
316
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
317 case IOracleCommand::Type_OrthancRestApi:
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
318 {
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
319 LOG(TRACE) << "WebAssemblyOracle::FetchContext::SuccessCallback. About to call context->EmitMessage(message);";
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
320 OrthancRestApiCommand::SuccessMessage message
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
321 (context->GetTypedCommand<OrthancRestApiCommand>(), headers, answer);
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
322 context->EmitMessage(message);
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
323 break;
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
324 }
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 971
diff changeset
325
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
326 case IOracleCommand::Type_GetOrthancImage:
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
327 {
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
328 context->GetTypedCommand<GetOrthancImageCommand>().ProcessHttpAnswer
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
329 (context->GetEmitter(), context->GetReceiver(), answer, headers);
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
330 break;
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
331 }
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 971
diff changeset
332
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
333 case IOracleCommand::Type_GetOrthancWebViewerJpeg:
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
334 {
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
335 context->GetTypedCommand<GetOrthancWebViewerJpegCommand>().ProcessHttpAnswer
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
336 (context->GetEmitter(), context->GetReceiver(), answer);
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
337 break;
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
338 }
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 971
diff changeset
339
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
340 default:
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
341 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: "
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
342 << context->GetCommand().GetType();
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 971
diff changeset
343 }
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
346 }
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
347 catch (Orthanc::OrthancException& e)
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
348 {
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
349 LOG(ERROR) << "Error while processing a fetch answer in the oracle: " << e.What();
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 static void FailureCallback(emscripten_fetch_t *fetch)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData));
995
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
356
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
357 {
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
358 const size_t kEmscriptenStatusTextSize = sizeof(emscripten_fetch_t::statusText);
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
359 char message[kEmscriptenStatusTextSize + 1];
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
360 memcpy(message, fetch->statusText, kEmscriptenStatusTextSize);
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
361 message[kEmscriptenStatusTextSize] = 0;
959
13e078adfb94 Better error log in fetch failure callback +
Benjamin Golinvaux <bgo@osimis.io>
parents: 956
diff changeset
362
996
727f2007ca23 commenting out annoying error
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
363 /*LOG(ERROR) << "Fetching " << fetch->url
995
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
364 << " failed, HTTP failure status code: " << fetch->status
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
365 << " | statusText = " << message
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
366 << " | numBytes = " << fetch->numBytes
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
367 << " | totalBytes = " << fetch->totalBytes
996
727f2007ca23 commenting out annoying error
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
368 << " | readyState = " << fetch->readyState;*/
995
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
369 }
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
995
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
371 {
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
372 OracleCommandExceptionMessage message
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
373 (context->GetCommand(), Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol));
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
374 context->EmitMessage(message);
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
375 }
9893fa8cd7a6 send error message for HTTP fetching in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 992
diff changeset
376
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 /**
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 * TODO - The following code leads to an infinite recursion, at
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 * least with Firefox running on incognito mode => WHY?
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 **/
959
13e078adfb94 Better error log in fetch failure callback +
Benjamin Golinvaux <bgo@osimis.io>
parents: 956
diff changeset
381 emscripten_fetch_close(fetch); // Also free data on failure.
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 };
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 class WebAssemblyOracle::FetchCommand : public boost::noncopyable
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 private:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 WebAssemblyOracle& oracle_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 const IObserver& receiver_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 std::auto_ptr<IOracleCommand> command_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 Orthanc::HttpMethod method_;
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
394 std::string url_;
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 std::string body_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 HttpHeaders headers_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 unsigned int timeout_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 std::string expectedContentType_;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 public:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 FetchCommand(WebAssemblyOracle& oracle,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 const IObserver& receiver,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 IOracleCommand* command) :
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 oracle_(oracle),
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 receiver_(receiver),
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 command_(command),
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 method_(Orthanc::HttpMethod_Get),
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 timeout_(0)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 if (command == NULL)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 void SetMethod(Orthanc::HttpMethod method)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 method_ = method;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
421 void SetOrthancUri(const std::string& uri)
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 {
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
423 url_ = oracle_.orthancRoot_ + uri;
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
424 }
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
425
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
426 void SetUrl(const std::string& url)
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
427 {
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
428 url_ = url;
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 void SetBody(std::string& body /* will be swapped */)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 body_.swap(body);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 void SetHttpHeaders(const HttpHeaders& headers)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 headers_ = headers;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 void SetTimeout(unsigned int timeout)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 timeout_ = timeout;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 void Execute()
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 {
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
448 #if 0
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
449 if (logbgo233) {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
450 if (logbgo115)
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
451 LOG(TRACE) << " WebAssemblyOracle::Execute () command addr " <<
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
452 std::hex << command_.get() << std::dec;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
453 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
454 #endif
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 if (command_.get() == NULL)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 // Cannot call Execute() twice
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 933
diff changeset
458 LOG(ERROR) << "WebAssemblyOracle::Execute(): (command_.get() == NULL)";
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 933
diff changeset
459 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 emscripten_fetch_attr_t attr;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 emscripten_fetch_attr_init(&attr);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 const char* method;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 switch (method_)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 case Orthanc::HttpMethod_Get:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 method = "GET";
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 break;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 case Orthanc::HttpMethod_Post:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 method = "POST";
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 break;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 case Orthanc::HttpMethod_Delete:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 method = "DELETE";
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 break;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 case Orthanc::HttpMethod_Put:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 method = "PUT";
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 break;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 default:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 strcpy(attr.requestMethod, method);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490
971
bc7b249dfbd0 Added EMSCRIPTEN_FETCH_REPLACE flag to requests to prevent stale cache results
Benjamin Golinvaux <bgo@osimis.io>
parents: 964
diff changeset
491 attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_REPLACE;
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 attr.onsuccess = FetchContext::SuccessCallback;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 attr.onerror = FetchContext::FailureCallback;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 attr.timeoutMSecs = timeout_ * 1000;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 std::vector<const char*> headers;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 headers.reserve(2 * headers_.size() + 1);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 std::string expectedContentType;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 std::string key;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 Orthanc::Toolbox::ToLowerCase(key, it->first);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 if (key == "accept")
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 expectedContentType = it->second;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 if (key != "accept-encoding") // Web browsers forbid the modification of this HTTP header
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 headers.push_back(it->first.c_str());
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 headers.push_back(it->second.c_str());
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 headers.push_back(NULL); // Termination of the array of HTTP headers
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 attr.requestHeaders = &headers[0];
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
841
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
522 char* requestData = NULL;
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 if (!body_.empty())
841
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
524 requestData = reinterpret_cast<char*>(malloc(body_.size()));
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
525
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
526 try
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 {
841
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
528 if (!body_.empty())
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
529 {
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
530 memcpy(requestData, &(body_[0]), body_.size());
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
531 attr.requestDataSize = body_.size();
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
532 attr.requestData = requestData;
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
533 }
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
534 attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType);
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535
841
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
536 // Must be the last call to prevent memory leak on error
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
537 #if 0
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
538 LOG(TRACE) << "Performing " << method << " request on URI: \"" << url_ << "\"";
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
539 #endif
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
540 emscripten_fetch(&attr, url_.c_str());
841
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
541 }
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
542 catch(...)
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
543 {
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
544 if(requestData != NULL)
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
545 free(requestData);
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
546 throw;
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
547 }
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 831
diff changeset
548 }
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 };
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
550
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
551 #if 0
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
552 static void DumpCommand(OrthancRestApiCommand* pCommand)
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
553 {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
554 OrthancRestApiCommand& command = *pCommand;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
555 LOG(TRACE) << "WebAssemblyOracle::Execute for REST command.";
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
556 switch (command.GetMethod()) {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
557 case Orthanc::HttpMethod_Get:
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
558 LOG(TRACE) << " * WebAssemblyOracle::Execute GET URI = " << command.GetUri() << " timeout = " << command.GetTimeout();
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
559 break;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
560 case Orthanc::HttpMethod_Post:
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
561 LOG(TRACE) << " * WebAssemblyOracle::Execute POST URI = " << command.GetUri() << " body = " << command.GetBody() << " timeout = " << command.GetTimeout();
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
562 break;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
563 default:
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
564 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
565 break;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
566 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
567 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
568 #endif
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
569
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
570
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
571 void WebAssemblyOracle::Execute(const IObserver& receiver,
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
572 HttpCommand* command)
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
573 {
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
574 FetchCommand fetch(*this, receiver, command);
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
575
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
576 fetch.SetMethod(command->GetMethod());
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
577 fetch.SetUrl(command->GetUrl());
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
578 fetch.SetHttpHeaders(command->GetHttpHeaders());
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
579 fetch.SetTimeout(command->GetTimeout());
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
580
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
581 if (command->GetMethod() == Orthanc::HttpMethod_Post ||
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
582 command->GetMethod() == Orthanc::HttpMethod_Put)
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
583 {
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
584 std::string body;
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
585 command->SwapBody(body);
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
586 fetch.SetBody(body);
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
587 }
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
588
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
589 fetch.Execute();
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
590 }
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
591
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
592
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 void WebAssemblyOracle::Execute(const IObserver& receiver,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 OrthancRestApiCommand* command)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 {
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
596 #if 0
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
597 DumpCommand(command);
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
598
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
599 if (logbgo233) {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
600 if (logbgo115)
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
601 LOG(TRACE) << " WebAssemblyOracle::Execute (OrthancRestApiCommand) command addr " <<
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
602 std::hex << command << std::dec;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
603 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
604 #endif
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
605
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
606 try
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
607 {
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
608 //LOG(TRACE) << "*********** WebAssemblyOracle::Execute.";
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
609 //LOG(TRACE) << "WebAssemblyOracle::Execute | command = " << command;
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
610 FetchCommand fetch(*this, receiver, command);
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
611
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
612 fetch.SetMethod(command->GetMethod());
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
613 fetch.SetOrthancUri(command->GetUri());
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
614 fetch.SetHttpHeaders(command->GetHttpHeaders());
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
615 fetch.SetTimeout(command->GetTimeout());
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
616
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
617 if (command->GetMethod() == Orthanc::HttpMethod_Post ||
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
618 command->GetMethod() == Orthanc::HttpMethod_Put)
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
619 {
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
620 std::string body;
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
621 command->SwapBody(body);
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
622 fetch.SetBody(body);
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
623 }
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
625 fetch.Execute();
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
626 //LOG(TRACE) << "*********** successful end of WebAssemblyOracle::Execute.";
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
627 }
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
628 catch (const Orthanc::OrthancException& e)
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 {
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
630 if (e.HasDetails())
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
631 {
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
632 LOG(ERROR) << "OrthancException in WebAssemblyOracle::Execute: " << e.What() << " Details: " << e.GetDetails();
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
633 }
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
634 else
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
635 {
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
636 LOG(ERROR) << "OrthancException in WebAssemblyOracle::Execute: " << e.What();
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
637 }
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
638 //LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute.";
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
639 throw;
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 }
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
641 catch (const std::exception& e)
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
642 {
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
643 LOG(ERROR) << "std::exception in WebAssemblyOracle::Execute: " << e.what();
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
644 // LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute.";
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
645 throw;
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
646 }
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
647 catch (...)
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
648 {
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
649 LOG(ERROR) << "Unknown exception in WebAssemblyOracle::Execute";
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
650 // LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute.";
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
651 throw;
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
652 }
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 void WebAssemblyOracle::Execute(const IObserver& receiver,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 GetOrthancImageCommand* command)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 {
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
659 #if 0
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
660 if (logbgo233) {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
661 if (logbgo115)
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
662 LOG(TRACE) << " WebAssemblyOracle::Execute (GetOrthancImageCommand) command addr " <<
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
663 std::hex << command << std::dec;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
664 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
665 #endif
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
666
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 FetchCommand fetch(*this, receiver, command);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
669 fetch.SetOrthancUri(command->GetUri());
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 fetch.SetHttpHeaders(command->GetHttpHeaders());
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 fetch.SetTimeout(command->GetTimeout());
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 fetch.Execute();
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 void WebAssemblyOracle::Execute(const IObserver& receiver,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 GetOrthancWebViewerJpegCommand* command)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 {
964
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
680 #if 0
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
681 if (logbgo233) {
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
682 if (logbgo115)
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
683 LOG(TRACE) << " WebAssemblyOracle::Execute (GetOrthancWebViewerJpegCommand) command addr " << std::hex << command << std::dec;
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
684 }
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
685 #endif
91f827272c1f Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
686
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 FetchCommand fetch(*this, receiver, command);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
689 fetch.SetOrthancUri(command->GetUri());
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 fetch.SetHttpHeaders(command->GetHttpHeaders());
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 fetch.SetTimeout(command->GetTimeout());
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 fetch.Execute();
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697
1076
008dbc4ceb62 removed LambdaCallable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 996
diff changeset
698 void WebAssemblyOracle::Schedule(boost::shared_ptr<IObserver>& receiver,
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 IOracleCommand* command)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 {
977
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
701 LOG(TRACE) << "WebAssemblyOracle::Schedule : receiver = "
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
702 << std::hex << &receiver << std::dec
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
703 << " | Current fingerprint is " << receiver.GetFingerprint();
262a0244e9b2 Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
Benjamin Golinvaux <bgo@osimis.io>
parents: 975
diff changeset
704
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 std::auto_ptr<IOracleCommand> protection(command);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 if (command == NULL)
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 switch (command->GetType())
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 {
992
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
714 case IOracleCommand::Type_Http:
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
715 Execute(receiver, dynamic_cast<HttpCommand*>(protection.release()));
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
716 break;
a9f5d0742e22 implementation of HttpCommand in WebAssemblyOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
717
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 case IOracleCommand::Type_OrthancRestApi:
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
719 //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
720 //{
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
721 // const IObserver* pReceiver = &receiver;
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
722 // LOG(TRACE) << "WebAssemblyOracle::Schedule | pReceiver is " << pReceiver;
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
723 // LOG(TRACE) << "WebAssemblyOracle::Schedule | command = " << command;
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
724 // OrthancRestApiCommand* rac = dynamic_cast<OrthancRestApiCommand*>(protection.get());
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
725 // LOG(TRACE) << "WebAssemblyOracle::Schedule | typed command = " << rac;
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
726 // LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri();
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
727 //}
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
728 //// END OF BLOCK TO REMOVE
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release()));
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 break;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 case IOracleCommand::Type_GetOrthancImage:
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
733 //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
734 //{
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
735 // GetOrthancImageCommand* rac = dynamic_cast<GetOrthancImageCommand*>(protection.get());
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
736 // LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri();
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
737 //}
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
738 //// END OF BLOCK TO REMOVE
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release()));
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 break;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 case IOracleCommand::Type_GetOrthancWebViewerJpeg:
933
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
743 //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
744 //{
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
745 // GetOrthancWebViewerJpegCommand* rac = dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.get());
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
746 // LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri();
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
747 //}
f75f6cb69c1b Commented-out traces for debug
Benjamin Golinvaux <bgo@osimis.io>
parents: 843
diff changeset
748 //// END OF BLOCK TO REMOVE
825
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 Execute(receiver, dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.release()));
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 break;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 case IOracleCommand::Type_Sleep:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 {
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 unsigned int timeoutMS = dynamic_cast<SleepOracleCommand*>(command)->GetDelay();
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 emscripten_set_timeout(TimeoutContext::Callback, timeoutMS,
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 new TimeoutContext(*this, receiver, protection.release()));
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 break;
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 default:
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: " << command->GetType();
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 }
9a6c7a5dcb76 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 }