Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Toolbox/OrthancApiClient.h @ 1084:6cf58788f37f broker
fix GenericToolboxTests
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 Oct 2019 13:19:25 +0200 |
parents | b537002f83a9 |
children | 21c2b0eee53c |
rev | line source |
---|---|
270 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
270 | 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 <boost/shared_ptr.hpp> | |
25 #include <json/json.h> | |
26 | |
27 #include "IWebService.h" | |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1060
diff
changeset
|
28 #include "../../Messages/ObserverBase.h" |
270 | 29 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
30 namespace Deprecated |
270 | 31 { |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
32 class OrthancApiClient : |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
33 public OrthancStone::IObservable, |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1060
diff
changeset
|
34 public OrthancStone::ObserverBase<OrthancApiClient> |
270 | 35 { |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
36 public: |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
37 class JsonResponseReadyMessage : public OrthancStone::IMessage |
270 | 38 { |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
39 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
40 |
377 | 41 private: |
42 const std::string& uri_; | |
43 const Json::Value& json_; | |
44 const Orthanc::IDynamicObject* payload_; | |
270 | 45 |
377 | 46 public: |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
47 JsonResponseReadyMessage(const std::string& uri, |
377 | 48 const Json::Value& json, |
49 const Orthanc::IDynamicObject* payload) : | |
50 uri_(uri), | |
51 json_(json), | |
52 payload_(payload) | |
270 | 53 { |
54 } | |
55 | |
377 | 56 const std::string& GetUri() const |
57 { | |
58 return uri_; | |
59 } | |
60 | |
61 const Json::Value& GetJson() const | |
62 { | |
63 return json_; | |
64 } | |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
65 |
377 | 66 bool HasPayload() const |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
67 { |
377 | 68 return payload_ != NULL; |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
69 } |
377 | 70 |
71 const Orthanc::IDynamicObject& GetPayload() const; | |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
72 }; |
377 | 73 |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
74 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
75 class BinaryResponseReadyMessage : public OrthancStone::IMessage |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
76 { |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
77 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
78 |
377 | 79 private: |
80 const std::string& uri_; | |
81 const void* answer_; | |
82 size_t answerSize_; | |
83 const Orthanc::IDynamicObject* payload_; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
84 |
377 | 85 public: |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
86 BinaryResponseReadyMessage(const std::string& uri, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
87 const void* answer, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
88 size_t answerSize, |
377 | 89 const Orthanc::IDynamicObject* payload) : |
90 uri_(uri), | |
91 answer_(answer), | |
92 answerSize_(answerSize), | |
93 payload_(payload) | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
94 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
95 } |
377 | 96 |
97 const std::string& GetUri() const | |
98 { | |
99 return uri_; | |
100 } | |
101 | |
102 const void* GetAnswer() const | |
103 { | |
104 return answer_; | |
105 } | |
106 | |
107 size_t GetAnswerSize() const | |
108 { | |
109 return answerSize_; | |
110 } | |
111 | |
112 bool HasPayload() const | |
113 { | |
114 return payload_ != NULL; | |
115 } | |
116 | |
117 const Orthanc::IDynamicObject& GetPayload() const; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
118 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
119 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
120 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
121 class EmptyResponseReadyMessage : public OrthancStone::IMessage |
377 | 122 { |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
123 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
124 |
377 | 125 private: |
126 const std::string& uri_; | |
127 const Orthanc::IDynamicObject* payload_; | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
128 |
377 | 129 public: |
130 EmptyResponseReadyMessage(const std::string& uri, | |
131 const Orthanc::IDynamicObject* payload) : | |
132 uri_(uri), | |
133 payload_(payload) | |
134 { | |
135 } | |
136 | |
137 const std::string& GetUri() const | |
138 { | |
139 return uri_; | |
140 } | |
141 | |
142 bool HasPayload() const | |
143 { | |
144 return payload_ != NULL; | |
145 } | |
146 | |
147 const Orthanc::IDynamicObject& GetPayload() const; | |
148 }; | |
270 | 149 |
377 | 150 |
151 | |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
152 private: |
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
153 class WebServicePayload; |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
154 |
270 | 155 protected: |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
156 IWebService& web_; |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
157 std::string baseUrl_; |
270 | 158 |
159 public: | |
1060
e146743f6cdc
removing file MessageBroker.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1057
diff
changeset
|
160 OrthancApiClient(IWebService& web, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
161 const std::string& baseUrl); |
377 | 162 |
163 virtual ~OrthancApiClient() | |
164 { | |
165 } | |
270 | 166 |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
502
diff
changeset
|
167 const std::string& GetBaseUrl() const {return baseUrl_;} |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
502
diff
changeset
|
168 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
169 // schedule a GET request expecting a JSON response. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
170 void GetJsonAsync(const std::string& uri, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
171 OrthancStone::MessageHandler<JsonResponseReadyMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
172 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 173 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
270 | 174 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
175 // schedule a GET request expecting a binary response. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
176 void GetBinaryAsync(const std::string& uri, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
177 const std::string& contentType, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
178 OrthancStone::MessageHandler<BinaryResponseReadyMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
179 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
180 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
270 | 181 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
182 // schedule a GET request expecting a binary response. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
183 void GetBinaryAsync(const std::string& uri, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
184 const IWebService::HttpHeaders& headers, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
185 OrthancStone::MessageHandler<BinaryResponseReadyMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
186 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 187 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
188 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
189 // schedule a POST request expecting a JSON response. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
190 void PostBinaryAsyncExpectJson(const std::string& uri, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
191 const std::string& body, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
192 OrthancStone::MessageHandler<JsonResponseReadyMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
193 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 194 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
195 |
309 | 196 // schedule a POST request expecting a JSON response. |
197 void PostJsonAsyncExpectJson(const std::string& uri, | |
198 const Json::Value& data, | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
199 OrthancStone::MessageHandler<JsonResponseReadyMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
200 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 201 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
202 |
424
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
203 // schedule a POST request and don't mind the response. |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
204 void PostJsonAsync(const std::string& uri, |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
205 const Json::Value& data); |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
206 |
502 | 207 // schedule a POST request and don't expect any response. |
208 void PostJsonAsync(const std::string& uri, | |
209 const Json::Value& data, | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
210 OrthancStone::MessageHandler<EmptyResponseReadyMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
211 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
502 | 212 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
213 | |
214 | |
424
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
215 // schedule a POST request and don't mind the response. |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
216 void PostBinaryAsync(const std::string& uri, |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
217 const std::string& body); |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
218 |
502 | 219 // schedule a POST request and don't expect any response. |
220 void PostBinaryAsync(const std::string& uri, | |
221 const std::string& body, | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
222 OrthancStone::MessageHandler<EmptyResponseReadyMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
223 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
502 | 224 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
225 | |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
226 // schedule a DELETE request expecting an empty response. |
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
227 void DeleteAsync(const std::string& uri, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
228 OrthancStone::MessageHandler<EmptyResponseReadyMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
229 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 230 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
231 |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
232 void NotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message); |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
233 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
234 void NotifyHttpError(const IWebService::HttpRequestErrorMessage& message); |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
235 |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
236 private: |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
237 void HandleFromCache(const std::string& uri, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
238 const IWebService::HttpHeaders& headers, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
239 Orthanc::IDynamicObject* payload /* takes ownership */); |
270 | 240 }; |
241 } |