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