comparison Applications/Platforms/WebAssembly/WebAssemblyOracle.h @ 1591:5887a4f8594b

moving platform-specific files out of the "OrthancStone" folder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Oct 2020 13:15:03 +0200
parents OrthancStone/Sources/Oracle/WebAssemblyOracle.h@37d90bd69f31
children 4fb8fdf03314
comparison
equal deleted inserted replaced
1590:7b963bccafef 1591:5887a4f8594b
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #pragma once
23
24 #include "../../../OrthancStone/Sources/OrthancStone.h"
25
26 #if !defined(ORTHANC_ENABLE_WASM)
27 # error The macro ORTHANC_ENABLE_WASM must be defined
28 #endif
29
30 #if ORTHANC_ENABLE_WASM != 1
31 # error This file can only compiled for WebAssembly
32 #endif
33
34 #include "../../../OrthancStone/Sources/Messages/IObservable.h"
35 #include "../../../OrthancStone/Sources/Messages/IMessageEmitter.h"
36 #include "../../../OrthancStone/Sources/Oracle/IOracle.h"
37
38 #if ORTHANC_ENABLE_DCMTK == 1
39 # include "../../../OrthancStone/Sources/Toolbox/ParsedDicomCache.h"
40 #endif
41
42 #include <Compatibility.h> // For ORTHANC_OVERRIDE
43 #include <WebServiceParameters.h>
44
45 #include <Enumerations.h>
46
47 namespace OrthancStone
48 {
49 class GetOrthancImageCommand;
50 class GetOrthancWebViewerJpegCommand;
51 class HttpCommand;
52 class OrthancRestApiCommand;
53 class ParseDicomFromWadoCommand;
54
55 class WebAssemblyOracle :
56 public IOracle,
57 public IMessageEmitter
58 {
59 private:
60 typedef std::map<std::string, std::string> HttpHeaders;
61
62 class TimeoutContext;
63 class FetchContext;
64 class FetchCommand;
65
66 void SetOrthancUrl(FetchCommand& command,
67 const std::string& uri) const;
68
69 void Execute(boost::weak_ptr<IObserver> receiver,
70 HttpCommand* command);
71
72 void Execute(boost::weak_ptr<IObserver> receiver,
73 OrthancRestApiCommand* command);
74
75 void Execute(boost::weak_ptr<IObserver> receiver,
76 GetOrthancImageCommand* command);
77
78 void Execute(boost::weak_ptr<IObserver> receiver,
79 GetOrthancWebViewerJpegCommand* command);
80
81 void Execute(boost::weak_ptr<IObserver> receiver,
82 ParseDicomFromWadoCommand* command);
83
84 IObservable oracleObservable_;
85 bool isLocalOrthanc_;
86 std::string localOrthancRoot_;
87 Orthanc::WebServiceParameters remoteOrthanc_;
88
89 #if ORTHANC_ENABLE_DCMTK == 1
90 std::unique_ptr<ParsedDicomCache> dicomCache_;
91 #endif
92
93 public:
94 WebAssemblyOracle() :
95 isLocalOrthanc_(false)
96 {
97 }
98
99 virtual void EmitMessage(boost::weak_ptr<IObserver> observer,
100 const IMessage& message) ORTHANC_OVERRIDE
101 {
102 oracleObservable_.EmitMessage(observer, message);
103 }
104
105 virtual bool Schedule(boost::shared_ptr<IObserver> receiver,
106 IOracleCommand* command) ORTHANC_OVERRIDE;
107
108 IObservable& GetOracleObservable()
109 {
110 return oracleObservable_;
111 }
112
113 void SetLocalOrthanc(const std::string& root)
114 {
115 isLocalOrthanc_ = true;
116 localOrthancRoot_ = root;
117 }
118
119 void SetRemoteOrthanc(const Orthanc::WebServiceParameters& orthanc)
120 {
121 isLocalOrthanc_ = false;
122 remoteOrthanc_ = orthanc;
123 }
124
125 void SetDicomCacheSize(size_t size);
126 };
127 }