Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOracle.h @ 1899:917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
author | Alain Mazy <am@osimis.io> |
---|---|
date | Sat, 29 Jan 2022 12:47:32 +0100 |
parents | |
children | 184b0aeae1af |
comparison
equal
deleted
inserted
replaced
1898:a5e54bd87b25 | 1899:917500c46fe0 |
---|---|
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-2022 Osimis S.A., Belgium | |
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
7 * | |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Lesser General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with this program. If not, see | |
20 * <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #pragma once | |
25 | |
26 #include "../../../OrthancStone/Sources/OrthancStone.h" | |
27 | |
28 #if !defined(ORTHANC_ENABLE_WASM) | |
29 # error The macro ORTHANC_ENABLE_WASM must be defined | |
30 #endif | |
31 | |
32 #if ORTHANC_ENABLE_WASM != 1 | |
33 # error This file can only compiled for WebAssembly | |
34 #endif | |
35 | |
36 #include "../../../OrthancStone/Sources/Messages/IObservable.h" | |
37 #include "../../../OrthancStone/Sources/Messages/IMessageEmitter.h" | |
38 #include "../../../OrthancStone/Sources/Oracle/IOracle.h" | |
39 | |
40 #if ORTHANC_ENABLE_DCMTK == 1 | |
41 # include "../../../OrthancStone/Sources/Toolbox/ParsedDicomCache.h" | |
42 #endif | |
43 | |
44 #include <Compatibility.h> // For ORTHANC_OVERRIDE | |
45 #include <WebServiceParameters.h> | |
46 | |
47 #include <Enumerations.h> | |
48 | |
49 namespace OrthancStone | |
50 { | |
51 class GetOrthancImageCommand; | |
52 class GetOrthancWebViewerJpegCommand; | |
53 class HttpCommand; | |
54 class OrthancRestApiCommand; | |
55 class ParseDicomFromWadoCommand; | |
56 | |
57 class WebAssemblyOracle : | |
58 public IOracle, | |
59 public IMessageEmitter | |
60 { | |
61 private: | |
62 typedef std::map<std::string, std::string> HttpHeaders; | |
63 | |
64 class TimeoutContext; | |
65 class FetchContext; | |
66 class FetchCommand; | |
67 | |
68 void SetOrthancUrl(FetchCommand& command, | |
69 const std::string& uri) const; | |
70 | |
71 void Execute(boost::weak_ptr<IObserver> receiver, | |
72 HttpCommand* command); | |
73 | |
74 void Execute(boost::weak_ptr<IObserver> receiver, | |
75 OrthancRestApiCommand* command); | |
76 | |
77 void Execute(boost::weak_ptr<IObserver> receiver, | |
78 GetOrthancImageCommand* command); | |
79 | |
80 void Execute(boost::weak_ptr<IObserver> receiver, | |
81 GetOrthancWebViewerJpegCommand* command); | |
82 | |
83 void Execute(boost::weak_ptr<IObserver> receiver, | |
84 ParseDicomFromWadoCommand* command); | |
85 | |
86 IObservable oracleObservable_; | |
87 bool isLocalOrthanc_; | |
88 std::string localOrthancRoot_; | |
89 Orthanc::WebServiceParameters remoteOrthanc_; | |
90 | |
91 #if ORTHANC_ENABLE_DCMTK == 1 | |
92 std::unique_ptr<ParsedDicomCache> dicomCache_; | |
93 #endif | |
94 | |
95 void ProcessFetchResult(boost::weak_ptr<IObserver>& receiver, | |
96 const std::string& answer, | |
97 const HttpHeaders& headers, | |
98 const IOracleCommand& command); | |
99 | |
100 public: | |
101 WebAssemblyOracle() : | |
102 isLocalOrthanc_(false) | |
103 { | |
104 } | |
105 | |
106 virtual void EmitMessage(boost::weak_ptr<IObserver> observer, | |
107 const IMessage& message) ORTHANC_OVERRIDE | |
108 { | |
109 oracleObservable_.EmitMessage(observer, message); | |
110 } | |
111 | |
112 virtual bool Schedule(boost::shared_ptr<IObserver> receiver, | |
113 IOracleCommand* command) ORTHANC_OVERRIDE; | |
114 | |
115 IObservable& GetOracleObservable() | |
116 { | |
117 return oracleObservable_; | |
118 } | |
119 | |
120 void SetLocalOrthanc(const std::string& root) | |
121 { | |
122 isLocalOrthanc_ = true; | |
123 localOrthancRoot_ = root; | |
124 } | |
125 | |
126 void SetRemoteOrthanc(const Orthanc::WebServiceParameters& orthanc) | |
127 { | |
128 isLocalOrthanc_ = false; | |
129 remoteOrthanc_ = orthanc; | |
130 } | |
131 | |
132 void SetDicomCacheSize(size_t size); | |
133 | |
134 class CachedInstanceAccessor : public boost::noncopyable | |
135 { | |
136 private: | |
137 #if ORTHANC_ENABLE_DCMTK == 1 | |
138 std::unique_ptr<ParsedDicomCache::Reader> reader_; | |
139 #endif | |
140 | |
141 public: | |
142 CachedInstanceAccessor(WebAssemblyOracle& oracle, | |
143 const std::string& sopInstanceUid); | |
144 | |
145 bool IsValid() const; | |
146 | |
147 #if ORTHANC_ENABLE_DCMTK == 1 | |
148 const Orthanc::ParsedDicomFile& GetDicom() const; | |
149 #endif | |
150 | |
151 size_t GetFileSize() const; | |
152 | |
153 bool HasPixelData() const; | |
154 }; | |
155 }; | |
156 } |