Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/OrthancApiClient.h @ 632:500c3f70b6c2
- Added a ClearAllChains method to PolylineSceneLayer --> revision must change
when calling it ==> BumpRevision has been added to base class
- Added some docs
= Added GetMinDepth + GetMaxDepth to Scene2D (to alleviate the need for app-
specific "Z depth registry" : clients may simply add a new layer on top or at
the bottom of the existing layer set.
- Added the line tracker measurement tools, commands and trackers. Generic base
classes + Line measure
- started work on the line measure handles
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Thu, 09 May 2019 10:41:31 +0200 |
parents | 92305ee35b1c |
children | f0008c55e5f7 |
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" | |
28 #include "../Messages/IObservable.h" | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
29 #include "../Messages/Promise.h" |
270 | 30 |
31 namespace OrthancStone | |
32 { | |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
33 class OrthancApiClient : |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
34 public IObservable, |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
35 public IObserver |
270 | 36 { |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
37 public: |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
38 class JsonResponseReadyMessage : |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
39 public BaseMessage<MessageType_OrthancApi_GenericGetJson_Ready> |
270 | 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 |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
75 class BinaryResponseReadyMessage : |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
76 public BaseMessage<MessageType_OrthancApi_GenericGetBinary_Ready> |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
77 { |
377 | 78 private: |
79 const std::string& uri_; | |
80 const void* answer_; | |
81 size_t answerSize_; | |
82 const Orthanc::IDynamicObject* payload_; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
83 |
377 | 84 public: |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
85 BinaryResponseReadyMessage(const std::string& uri, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
86 const void* answer, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
87 size_t answerSize, |
377 | 88 const Orthanc::IDynamicObject* payload) : |
89 uri_(uri), | |
90 answer_(answer), | |
91 answerSize_(answerSize), | |
92 payload_(payload) | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
93 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
94 } |
377 | 95 |
96 const std::string& GetUri() const | |
97 { | |
98 return uri_; | |
99 } | |
100 | |
101 const void* GetAnswer() const | |
102 { | |
103 return answer_; | |
104 } | |
105 | |
106 size_t GetAnswerSize() const | |
107 { | |
108 return answerSize_; | |
109 } | |
110 | |
111 bool HasPayload() const | |
112 { | |
113 return payload_ != NULL; | |
114 } | |
115 | |
116 const Orthanc::IDynamicObject& GetPayload() const; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
117 }; |
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 |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
120 class EmptyResponseReadyMessage : |
422
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
121 public BaseMessage<MessageType_OrthancApi_GenericEmptyResponse_Ready> |
377 | 122 { |
123 private: | |
124 const std::string& uri_; | |
125 const Orthanc::IDynamicObject* payload_; | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
126 |
377 | 127 public: |
128 EmptyResponseReadyMessage(const std::string& uri, | |
129 const Orthanc::IDynamicObject* payload) : | |
130 uri_(uri), | |
131 payload_(payload) | |
132 { | |
133 } | |
134 | |
135 const std::string& GetUri() const | |
136 { | |
137 return uri_; | |
138 } | |
139 | |
140 bool HasPayload() const | |
141 { | |
142 return payload_ != NULL; | |
143 } | |
144 | |
145 const Orthanc::IDynamicObject& GetPayload() const; | |
146 }; | |
270 | 147 |
377 | 148 |
149 | |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
150 private: |
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
151 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
|
152 |
270 | 153 protected: |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
154 IWebService& web_; |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
155 std::string baseUrl_; |
270 | 156 |
157 public: | |
158 OrthancApiClient(MessageBroker& broker, | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
159 IWebService& web, |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
160 const std::string& baseUrl); |
377 | 161 |
162 virtual ~OrthancApiClient() | |
163 { | |
164 } | |
270 | 165 |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
502
diff
changeset
|
166 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
|
167 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
168 // schedule a GET request expecting a JSON response. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
169 void GetJsonAsync(const std::string& uri, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
170 MessageHandler<JsonResponseReadyMessage>* successCallback, |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
171 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 172 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
270 | 173 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
174 // schedule a GET request expecting a binary response. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
175 void GetBinaryAsync(const std::string& uri, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
176 const std::string& contentType, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
177 MessageHandler<BinaryResponseReadyMessage>* successCallback, |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
178 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
179 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
270 | 180 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
181 // schedule a GET request expecting a binary response. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
182 void GetBinaryAsync(const std::string& uri, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
183 const IWebService::HttpHeaders& headers, |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
184 MessageHandler<BinaryResponseReadyMessage>* successCallback, |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
185 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 186 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
187 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
188 // schedule a POST request expecting a JSON response. |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
189 void PostBinaryAsyncExpectJson(const std::string& uri, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
190 const std::string& body, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
191 MessageHandler<JsonResponseReadyMessage>* successCallback, |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
192 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 193 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
194 |
309 | 195 // schedule a POST request expecting a JSON response. |
196 void PostJsonAsyncExpectJson(const std::string& uri, | |
197 const Json::Value& data, | |
198 MessageHandler<JsonResponseReadyMessage>* successCallback, | |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
199 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 200 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
271
diff
changeset
|
201 |
424
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
202 // 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
|
203 void PostJsonAsync(const std::string& uri, |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
204 const Json::Value& data); |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
205 |
502 | 206 // schedule a POST request and don't expect any response. |
207 void PostJsonAsync(const std::string& uri, | |
208 const Json::Value& data, | |
209 MessageHandler<EmptyResponseReadyMessage>* successCallback, | |
210 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, | |
211 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); | |
212 | |
213 | |
424
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
214 // 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
|
215 void PostBinaryAsync(const std::string& uri, |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
216 const std::string& body); |
bb573a52fc63
allow POST messages with success and failure handlers
am@osimis.io
parents:
422
diff
changeset
|
217 |
502 | 218 // schedule a POST request and don't expect any response. |
219 void PostBinaryAsync(const std::string& uri, | |
220 const std::string& body, | |
221 MessageHandler<EmptyResponseReadyMessage>* successCallback, | |
222 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, | |
223 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); | |
224 | |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
225 // schedule a DELETE request expecting an empty response. |
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
226 void DeleteAsync(const std::string& uri, |
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
227 MessageHandler<EmptyResponseReadyMessage>* successCallback, |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
228 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
377 | 229 Orthanc::IDynamicObject* payload = NULL /* takes ownership */); |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
230 |
382
dd4c7e82b4be
removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
231 void NotifyHttpSuccess(const IWebService::HttpRequestSuccessMessage& message); |
383
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
232 |
939f626eb6d7
removing converters in OrthancApiClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
382
diff
changeset
|
233 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
|
234 |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
235 private: |
4fe42ae3653a
introduced a basic cache at OrthancApiClient level so it can be used with the RadiographyScene
am@osimis.io
parents:
417
diff
changeset
|
236 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
|
237 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
|
238 Orthanc::IDynamicObject* payload /* takes ownership */); |
270 | 239 }; |
240 } |