Mercurial > hg > orthanc-stone
annotate Platforms/Generic/WebServiceCommandBase.cpp @ 299:3897f9f28cfa am-callable-and-promise
backup work in progress: updated messaging framework with ICallable
author | am@osimis.io |
---|---|
date | Fri, 14 Sep 2018 16:44:01 +0200 |
parents | 87376a645ee1 |
children | b4abaeb783b1 |
rev | line source |
---|---|
251 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
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. | |
16 * | |
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 #include "WebServiceCommandBase.h" | |
23 | |
24 #include <Core/HttpClient.h> | |
25 | |
26 namespace OrthancStone | |
27 { | |
28 WebServiceCommandBase::WebServiceCommandBase(MessageBroker& broker, | |
271
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
267
diff
changeset
|
29 IWebService::ICallback& callback, |
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
267
diff
changeset
|
30 const Orthanc::WebServiceParameters& parameters, |
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
267
diff
changeset
|
31 const std::string& uri, |
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
267
diff
changeset
|
32 const IWebService::Headers& headers, |
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
267
diff
changeset
|
33 Orthanc::IDynamicObject* payload /* takes ownership */, |
291 | 34 NativeStoneApplicationContext& context) : |
251 | 35 IObservable(broker), |
36 callback_(callback), | |
37 parameters_(parameters), | |
38 uri_(uri), | |
257 | 39 headers_(headers), |
271
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
267
diff
changeset
|
40 payload_(payload), |
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
267
diff
changeset
|
41 context_(context) |
251 | 42 { |
267 | 43 DeclareEmittableMessage(MessageType_HttpRequestError); |
44 DeclareEmittableMessage(MessageType_HttpRequestSuccess); | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
45 // TODO ? RegisterObserver(callback); |
251 | 46 } |
47 | |
48 | |
49 void WebServiceCommandBase::Commit() | |
50 { | |
291 | 51 NativeStoneApplicationContext::GlobalMutexLocker lock(context_); // we want to make sure that, i.e, the UpdateThread is not triggered while we are updating the "model" with the result of a WebServiceCommand |
271
46c5296d867e
OracleWebService and BasicSdlApplicationContext using the same global mutex
am@osimis.io
parents:
267
diff
changeset
|
52 |
251 | 53 if (success_) |
54 { | |
55 IWebService::ICallback::HttpRequestSuccessMessage message(uri_, answer_.c_str(), answer_.size(), payload_.release()); | |
258 | 56 EmitMessage(message); |
251 | 57 } |
58 else | |
59 { | |
60 IWebService::ICallback::HttpRequestErrorMessage message(uri_, payload_.release()); | |
258 | 61 EmitMessage(message); |
251 | 62 } |
63 } | |
299
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
64 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
65 NewWebServiceCommandBase::NewWebServiceCommandBase(MessageBroker& broker, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
66 MessageHandler<IWebService::NewHttpRequestSuccessMessage>* successCallback, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
67 MessageHandler<IWebService::NewHttpRequestErrorMessage>* failureCallback, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
68 const Orthanc::WebServiceParameters& parameters, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
69 const std::string& uri, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
70 const IWebService::Headers& headers, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
71 Orthanc::IDynamicObject* payload /* takes ownership */, |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
72 NativeStoneApplicationContext& context) : |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
73 IObservable(broker), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
74 successCallback_(successCallback), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
75 failureCallback_(failureCallback), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
76 parameters_(parameters), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
77 uri_(uri), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
78 headers_(headers), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
79 payload_(payload), |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
80 context_(context) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
81 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
82 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
83 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
84 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
85 void NewWebServiceCommandBase::Commit() |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
86 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
87 NativeStoneApplicationContext::GlobalMutexLocker lock(context_); // we want to make sure that, i.e, the UpdateThread is not triggered while we are updating the "model" with the result of a WebServiceCommand |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
88 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
89 if (success_ && successCallback_.get() != NULL) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
90 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
91 successCallback_->Apply(IWebService::NewHttpRequestSuccessMessage(uri_, answer_.c_str(), answer_.size(), payload_.release())); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
92 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
93 else if (!success_ && failureCallback_.get() != NULL) |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
94 { |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
95 successCallback_->Apply(IWebService::NewHttpRequestErrorMessage(uri_, payload_.release())); |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
96 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
97 |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
98 } |
3897f9f28cfa
backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents:
291
diff
changeset
|
99 |
251 | 100 } |