Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/IWebService.h @ 301:547e1cf7aa7b am-callable-and-promise
cleanup
author | am@osimis.io |
---|---|
date | Tue, 18 Sep 2018 15:34:28 +0200 |
parents | b4abaeb783b1 |
children | 14ef1227120f |
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 | |
135
e2fe9352f240
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
5 * Copyright (C) 2017-2018 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 | |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
24 #include <Core/IDynamicObject.h> |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
25 #include "../../Framework/Messages/IObserver.h" |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
26 #include "../../Framework/Messages/ICallable.h" |
57 | 27 #include <string> |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
28 #include <map> |
252 | 29 #include <Core/Logging.h> |
57 | 30 |
31 namespace OrthancStone | |
32 { | |
288 | 33 // The IWebService performs HTTP requests. |
34 // Since applications can run in native or WASM environment and, since | |
35 // in a WASM environment, the WebService is asynchronous, the IWebservice | |
36 // also implements an asynchronous interface: you must schedule a request | |
37 // and you'll be notified when the response/error is ready. | |
269 | 38 class IWebService |
39 { | |
40 protected: | |
41 MessageBroker& broker_; | |
42 public: | |
43 typedef std::map<std::string, std::string> Headers; | |
257 | 44 |
301 | 45 struct HttpRequestSuccessMessage: public BaseMessage<MessageType_HttpRequestSuccess> |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
46 { |
301 | 47 const std::string& uri_; |
48 const void* answer_; | |
49 size_t answerSize_; | |
50 Orthanc::IDynamicObject* payload_; | |
51 HttpRequestSuccessMessage(const std::string& uri, | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
52 const void* answer, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
53 size_t answerSize, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
54 Orthanc::IDynamicObject* payload) |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
55 : BaseMessage(), |
301 | 56 uri_(uri), |
57 answer_(answer), | |
58 answerSize_(answerSize), | |
59 payload_(payload) | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
60 {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
61 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
62 |
301 | 63 struct HttpRequestErrorMessage: public BaseMessage<MessageType_HttpRequestError> |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
64 { |
301 | 65 const std::string& uri_; |
66 Orthanc::IDynamicObject* payload_; | |
67 HttpRequestErrorMessage(const std::string& uri, | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
68 Orthanc::IDynamicObject* payload) |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
69 : BaseMessage(), |
301 | 70 uri_(uri), |
71 payload_(payload) | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
72 {} |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
73 }; |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
74 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
75 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
76 |
269 | 77 IWebService(MessageBroker& broker) |
78 : broker_(broker) | |
79 {} | |
57 | 80 |
269 | 81 virtual ~IWebService() |
82 { | |
83 } | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
84 |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
85 virtual void GetAsync(const std::string& uri, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
86 const Headers& headers, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
87 Orthanc::IDynamicObject* payload, |
301 | 88 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
89 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback) = 0; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
90 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
91 virtual void PostAsync(const std::string& uri, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
92 const Headers& headers, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
93 const std::string& body, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
94 Orthanc::IDynamicObject* payload, |
301 | 95 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback, |
96 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallback) = 0; | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
288
diff
changeset
|
97 |
269 | 98 }; |
57 | 99 } |