Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Toolbox/IWebService.h @ 1138:1a73f852810a broker
integration mainline->broker
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 Nov 2019 07:28:39 +0100 |
parents | e146743f6cdc |
children | 21c2b0eee53c |
rev | line source |
---|---|
57 | 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 |
57 | 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. | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
16 * |
57 | 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 | |
732
c35e98d22764
move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
24 #include "../../Messages/IObserver.h" |
c35e98d22764
move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
726
diff
changeset
|
25 #include "../../Messages/ICallable.h" |
377 | 26 |
1048
f6be9412e42a
cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
940
diff
changeset
|
27 #include <Core/Enumerations.h> |
377 | 28 #include <Core/IDynamicObject.h> |
29 #include <Core/Logging.h> | |
30 | |
57 | 31 #include <string> |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
32 #include <map> |
57 | 33 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
34 namespace Deprecated |
57 | 35 { |
288 | 36 // The IWebService performs HTTP requests. |
37 // Since applications can run in native or WASM environment and, since | |
38 // in a WASM environment, the WebService is asynchronous, the IWebservice | |
39 // also implements an asynchronous interface: you must schedule a request | |
40 // and you'll be notified when the response/error is ready. | |
377 | 41 class IWebService : public boost::noncopyable |
269 | 42 { |
43 public: | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
44 typedef std::map<std::string, std::string> HttpHeaders; |
257 | 45 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
46 class HttpRequestSuccessMessage : public OrthancStone::IMessage |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
47 { |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
48 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
49 |
377 | 50 private: |
51 const std::string& uri_; | |
52 const void* answer_; | |
53 size_t answerSize_; | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
54 const HttpHeaders& answerHeaders_; |
377 | 55 const Orthanc::IDynamicObject* payload_; |
56 | |
57 public: | |
301 | 58 HttpRequestSuccessMessage(const std::string& uri, |
309 | 59 const void* answer, |
60 size_t answerSize, | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
61 const HttpHeaders& answerHeaders, |
377 | 62 const Orthanc::IDynamicObject* payload) : |
63 uri_(uri), | |
64 answer_(answer), | |
65 answerSize_(answerSize), | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
66 answerHeaders_(answerHeaders), |
377 | 67 payload_(payload) |
68 { | |
69 } | |
70 | |
71 const std::string& GetUri() const | |
72 { | |
73 return uri_; | |
74 } | |
75 | |
76 const void* GetAnswer() const | |
77 { | |
78 return answer_; | |
79 } | |
80 | |
81 size_t GetAnswerSize() const | |
82 { | |
83 return answerSize_; | |
84 } | |
85 | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
86 const HttpHeaders& GetAnswerHttpHeaders() const |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
87 { |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
88 return answerHeaders_; |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
89 } |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
90 |
377 | 91 bool HasPayload() const |
92 { | |
93 return payload_ != NULL; | |
94 } | |
95 | |
96 const Orthanc::IDynamicObject& GetPayload() const; | |
97 }; | |
98 | |
99 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
100 class HttpRequestErrorMessage : public OrthancStone::IMessage |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
101 { |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
102 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
103 |
377 | 104 private: |
105 const std::string& uri_; | |
106 const Orthanc::IDynamicObject* payload_; | |
940
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
107 Orthanc::HttpStatus httpStatus_; |
377 | 108 |
109 public: | |
301 | 110 HttpRequestErrorMessage(const std::string& uri, |
940
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
111 Orthanc::HttpStatus httpStatus, |
377 | 112 const Orthanc::IDynamicObject* payload) : |
113 uri_(uri), | |
940
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
114 payload_(payload), |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
115 httpStatus_(httpStatus) |
377 | 116 { |
117 } | |
118 | |
119 const std::string& GetUri() const | |
120 { | |
121 return uri_; | |
122 } | |
123 | |
940
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
124 Orthanc::HttpStatus GetHttpStatus() const |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
125 { |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
126 return httpStatus_; |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
127 } |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
128 |
377 | 129 bool HasPayload() const |
130 { | |
131 return payload_ != NULL; | |
132 } | |
133 | |
134 const Orthanc::IDynamicObject& GetPayload() const; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
135 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
136 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
137 |
269 | 138 virtual ~IWebService() |
139 { | |
140 } | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
141 |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
417
diff
changeset
|
142 virtual void EnableCache(bool enable) = 0; |
377 | 143 |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
144 virtual void GetAsync(const std::string& uri, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
145 const HttpHeaders& headers, |
377 | 146 Orthanc::IDynamicObject* payload /* takes ownership */, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
147 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
148 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
309 | 149 unsigned int timeoutInSeconds = 60) = 0; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
150 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
151 virtual void PostAsync(const std::string& uri, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
152 const HttpHeaders& headers, |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
153 const std::string& body, |
377 | 154 Orthanc::IDynamicObject* payload /* takes ownership */, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
155 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
156 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
309 | 157 unsigned int timeoutInSeconds = 60) = 0; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
158 |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
159 virtual void DeleteAsync(const std::string& uri, |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
160 const HttpHeaders& headers, |
377 | 161 Orthanc::IDynamicObject* payload /* takes ownership */, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
162 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
163 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
164 unsigned int timeoutInSeconds = 60) = 0; |
269 | 165 }; |
57 | 166 } |