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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #pragma once
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
29 #include <Core/Logging.h>
57
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace OrthancStone
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
288
8c8da145fefa renamings and doc
am@osimis.io
parents: 269
diff changeset
33 // The IWebService performs HTTP requests.
8c8da145fefa renamings and doc
am@osimis.io
parents: 269
diff changeset
34 // Since applications can run in native or WASM environment and, since
8c8da145fefa renamings and doc
am@osimis.io
parents: 269
diff changeset
35 // in a WASM environment, the WebService is asynchronous, the IWebservice
8c8da145fefa renamings and doc
am@osimis.io
parents: 269
diff changeset
36 // also implements an asynchronous interface: you must schedule a request
8c8da145fefa renamings and doc
am@osimis.io
parents: 269
diff changeset
37 // and you'll be notified when the response/error is ready.
269
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
38 class IWebService
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
39 {
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
40 protected:
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
41 MessageBroker& broker_;
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
42 public:
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
43 typedef std::map<std::string, std::string> Headers;
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
44
301
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
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
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
47 const std::string& uri_;
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
48 const void* answer_;
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
49 size_t answerSize_;
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
50 Orthanc::IDynamicObject* payload_;
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
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
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
56 uri_(uri),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
57 answer_(answer),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
58 answerSize_(answerSize),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
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
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
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
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
65 const std::string& uri_;
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
66 Orthanc::IDynamicObject* payload_;
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
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
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
70 uri_(uri),
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
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
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
77 IWebService(MessageBroker& broker)
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
78 : broker_(broker)
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
79 {}
57
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
269
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
81 virtual ~IWebService()
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
82 {
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
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
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
88 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback,
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
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
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
95 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallback,
547e1cf7aa7b cleanup
am@osimis.io
parents: 300
diff changeset
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
0dfa83535cd7 indentation
am@osimis.io
parents: 268
diff changeset
98 };
57
d20e25cfcf3a IWebService
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }