Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Toolbox/IWebService.h @ 1101:141593f1aa88
fix build on ubuntu
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 26 Oct 2019 11:35:41 +0200 |
parents | f6be9412e42a |
children | e146743f6cdc 2d8ab34c8c91 |
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 protected: | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
44 OrthancStone::MessageBroker& broker_; |
377 | 45 |
269 | 46 public: |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
47 typedef std::map<std::string, std::string> HttpHeaders; |
257 | 48 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
49 class HttpRequestSuccessMessage : public OrthancStone::IMessage |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
50 { |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
51 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
52 |
377 | 53 private: |
54 const std::string& uri_; | |
55 const void* answer_; | |
56 size_t answerSize_; | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
57 const HttpHeaders& answerHeaders_; |
377 | 58 const Orthanc::IDynamicObject* payload_; |
59 | |
60 public: | |
301 | 61 HttpRequestSuccessMessage(const std::string& uri, |
309 | 62 const void* answer, |
63 size_t answerSize, | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
64 const HttpHeaders& answerHeaders, |
377 | 65 const Orthanc::IDynamicObject* payload) : |
66 uri_(uri), | |
67 answer_(answer), | |
68 answerSize_(answerSize), | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
69 answerHeaders_(answerHeaders), |
377 | 70 payload_(payload) |
71 { | |
72 } | |
73 | |
74 const std::string& GetUri() const | |
75 { | |
76 return uri_; | |
77 } | |
78 | |
79 const void* GetAnswer() const | |
80 { | |
81 return answer_; | |
82 } | |
83 | |
84 size_t GetAnswerSize() const | |
85 { | |
86 return answerSize_; | |
87 } | |
88 | |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
89 const HttpHeaders& GetAnswerHttpHeaders() const |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
90 { |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
91 return answerHeaders_; |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
92 } |
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
93 |
377 | 94 bool HasPayload() const |
95 { | |
96 return payload_ != NULL; | |
97 } | |
98 | |
99 const Orthanc::IDynamicObject& GetPayload() const; | |
100 }; | |
101 | |
102 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
103 class HttpRequestErrorMessage : public OrthancStone::IMessage |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
104 { |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
105 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
106 |
377 | 107 private: |
108 const std::string& uri_; | |
109 const Orthanc::IDynamicObject* payload_; | |
940
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
110 Orthanc::HttpStatus httpStatus_; |
377 | 111 |
112 public: | |
301 | 113 HttpRequestErrorMessage(const std::string& uri, |
940
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
114 Orthanc::HttpStatus httpStatus, |
377 | 115 const Orthanc::IDynamicObject* payload) : |
116 uri_(uri), | |
940
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
117 payload_(payload), |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
118 httpStatus_(httpStatus) |
377 | 119 { |
120 } | |
121 | |
122 const std::string& GetUri() const | |
123 { | |
124 return uri_; | |
125 } | |
126 | |
940
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
127 Orthanc::HttpStatus GetHttpStatus() const |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
128 { |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
129 return httpStatus_; |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
130 } |
861c080ef47b
handling httpStatus in WebService error messages
Alain Mazy <alain@mazy.be>
parents:
732
diff
changeset
|
131 |
377 | 132 bool HasPayload() const |
133 { | |
134 return payload_ != NULL; | |
135 } | |
136 | |
137 const Orthanc::IDynamicObject& GetPayload() const; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
138 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
139 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
140 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
141 IWebService(OrthancStone::MessageBroker& broker) : |
377 | 142 broker_(broker) |
143 { | |
144 } | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
145 |
377 | 146 |
269 | 147 virtual ~IWebService() |
148 { | |
149 } | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
150 |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
417
diff
changeset
|
151 virtual void EnableCache(bool enable) = 0; |
377 | 152 |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
153 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
|
154 const HttpHeaders& headers, |
377 | 155 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
|
156 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
157 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
309 | 158 unsigned int timeoutInSeconds = 60) = 0; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
159 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
160 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
|
161 const HttpHeaders& headers, |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
162 const std::string& body, |
377 | 163 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
|
164 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
643
diff
changeset
|
165 OrthancStone::MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
309 | 166 unsigned int timeoutInSeconds = 60) = 0; |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
167 |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
168 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
|
169 const HttpHeaders& headers, |
377 | 170 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
|
171 OrthancStone::MessageHandler<IWebService::HttpRequestSuccessMessage>* 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, |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
173 unsigned int timeoutInSeconds = 60) = 0; |
269 | 174 }; |
57 | 175 } |