Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/IWebService.h @ 456:b70fcc134ba4
moved LambdaCallable (currently still disable because it does not work in WASM)
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Wed, 23 Jan 2019 13:58:51 +0100 |
parents | a750f11892ec |
children | f0008c55e5f7 |
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 | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
24 #include "../../Framework/Messages/IObserver.h" |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
25 #include "../../Framework/Messages/ICallable.h" |
377 | 26 |
27 #include <Core/IDynamicObject.h> | |
28 #include <Core/Logging.h> | |
29 | |
57 | 30 #include <string> |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
31 #include <map> |
57 | 32 |
33 namespace OrthancStone | |
34 { | |
288 | 35 // The IWebService performs HTTP requests. |
36 // Since applications can run in native or WASM environment and, since | |
37 // in a WASM environment, the WebService is asynchronous, the IWebservice | |
38 // also implements an asynchronous interface: you must schedule a request | |
39 // and you'll be notified when the response/error is ready. | |
377 | 40 class IWebService : public boost::noncopyable |
269 | 41 { |
42 protected: | |
43 MessageBroker& broker_; | |
377 | 44 |
269 | 45 public: |
417
aee3d7941c9b
preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
383
diff
changeset
|
46 typedef std::map<std::string, std::string> HttpHeaders; |
257 | 47 |
377 | 48 class HttpRequestSuccessMessage : public BaseMessage<MessageType_HttpRequestSuccess> |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
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 | |
100 class HttpRequestErrorMessage : public BaseMessage<MessageType_HttpRequestError> | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
101 { |
377 | 102 private: |
103 const std::string& uri_; | |
104 const Orthanc::IDynamicObject* payload_; | |
105 | |
106 public: | |
301 | 107 HttpRequestErrorMessage(const std::string& uri, |
377 | 108 const Orthanc::IDynamicObject* payload) : |
109 uri_(uri), | |
110 payload_(payload) | |
111 { | |
112 } | |
113 | |
114 const std::string& GetUri() const | |
115 { | |
116 return uri_; | |
117 } | |
118 | |
119 bool HasPayload() const | |
120 { | |
121 return payload_ != NULL; | |
122 } | |
123 | |
124 const Orthanc::IDynamicObject& GetPayload() const; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
125 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
126 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
127 |
377 | 128 IWebService(MessageBroker& broker) : |
129 broker_(broker) | |
130 { | |
131 } | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
132 |
377 | 133 |
269 | 134 virtual ~IWebService() |
135 { | |
136 } | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
137 |
434
3a8bcc45c221
moved the HTTP cache from OrthancApiClient to BaseWebService (not implemented yet in WASM)
am@osimis.io
parents:
417
diff
changeset
|
138 virtual void EnableCache(bool enable) = 0; |
377 | 139 |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
140 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
|
141 const HttpHeaders& headers, |
377 | 142 Orthanc::IDynamicObject* payload /* takes ownership */, |
301 | 143 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
309 | 144 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
145 unsigned int timeoutInSeconds = 60) = 0; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
146 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
147 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
|
148 const HttpHeaders& headers, |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
149 const std::string& body, |
377 | 150 Orthanc::IDynamicObject* payload /* takes ownership */, |
301 | 151 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
309 | 152 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
153 unsigned int timeoutInSeconds = 60) = 0; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
154 |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
155 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
|
156 const HttpHeaders& headers, |
377 | 157 Orthanc::IDynamicObject* payload /* takes ownership */, |
315
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
158 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
159 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback = NULL, |
aad37d0b6407
Added LayerWidget::RemoveLayer + DELETE commands in WebService
am@osimis.io
parents:
309
diff
changeset
|
160 unsigned int timeoutInSeconds = 60) = 0; |
269 | 161 }; |
57 | 162 } |