Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/IWebService.h @ 254:abc1c6231947 am-2
cleanup
author | am@osimis.io |
---|---|
date | Tue, 03 Jul 2018 11:49:02 +0200 |
parents | 40b21c1f8b8d |
children | 9afafb192180 |
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" |
57 | 26 #include <string> |
252 | 27 #include <Core/Logging.h> |
57 | 28 |
29 namespace OrthancStone | |
30 { | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
31 class IWebService |
57 | 32 { |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
33 protected: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
34 MessageBroker& broker_; |
57 | 35 public: |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
36 class ICallback : public IObserver |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
37 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
38 public: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
39 struct HttpRequestSuccessMessage: public IMessage |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
40 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
41 const std::string& Uri; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
42 const void* Answer; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
43 size_t AnswerSize; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
44 Orthanc::IDynamicObject* Payload; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
45 HttpRequestSuccessMessage(const std::string& uri, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
46 const void* answer, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
47 size_t answerSize, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
48 Orthanc::IDynamicObject* payload) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
49 : IMessage(MessageType_HttpRequestSuccess), |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
50 Uri(uri), |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
51 Answer(answer), |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
52 AnswerSize(answerSize), |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
53 Payload(payload) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
54 {} |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
55 }; |
57 | 56 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
57 struct HttpRequestErrorMessage: public IMessage |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
58 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
59 const std::string& Uri; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
60 Orthanc::IDynamicObject* Payload; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
61 HttpRequestErrorMessage(const std::string& uri, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
62 Orthanc::IDynamicObject* payload) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
63 : IMessage(MessageType_HttpRequestError), |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
64 Uri(uri), |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
65 Payload(payload) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
66 {} |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
67 }; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
68 |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
69 ICallback(MessageBroker& broker) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
70 : IObserver(broker) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
71 {} |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
72 virtual ~ICallback() |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
73 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
74 } |
57 | 75 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
76 virtual void HandleMessage(IObservable& from, const IMessage& message) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
77 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
78 switch(message.GetType()) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
79 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
80 case MessageType_HttpRequestError: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
81 { const HttpRequestErrorMessage& msg = dynamic_cast<const HttpRequestErrorMessage&>(message); |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
82 OnHttpRequestError(msg.Uri, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
83 msg.Payload); |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
84 }; break; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
85 |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
86 case MessageType_HttpRequestSuccess: |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
87 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
88 const HttpRequestSuccessMessage& msg = dynamic_cast<const HttpRequestSuccessMessage&>(message); |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
89 OnHttpRequestSuccess(msg.Uri, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
90 msg.Answer, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
91 msg.AnswerSize, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
92 msg.Payload); |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
93 }; break; |
252 | 94 default: |
95 VLOG("unhandled message type" << message.GetType()); | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
96 } |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
97 } |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
98 |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
99 virtual void OnHttpRequestError(const std::string& uri, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
100 Orthanc::IDynamicObject* payload) = 0; |
57 | 101 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
102 virtual void OnHttpRequestSuccess(const std::string& uri, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
103 const void* answer, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
104 size_t answerSize, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
105 Orthanc::IDynamicObject* payload) = 0; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
106 }; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
107 |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
108 IWebService(MessageBroker& broker) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
109 : broker_(broker) |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
110 {} |
57 | 111 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
112 virtual ~IWebService() |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
113 { |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
114 } |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
115 |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
116 virtual void ScheduleGetRequest(ICallback& callback, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
117 const std::string& uri, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
118 Orthanc::IDynamicObject* payload) = 0; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
119 |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
120 virtual void SchedulePostRequest(ICallback& callback, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
121 const std::string& uri, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
122 const std::string& body, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
123 Orthanc::IDynamicObject* payload) = 0; |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
212
diff
changeset
|
124 }; |
57 | 125 } |