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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
1 /**
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
6 *
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
11 *
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
16 *
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
19 **/
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
20
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
21
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
22 #include "WebServiceCommandBase.h"
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
23
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
24 #include <Core/HttpClient.h>
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
25
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
26 namespace OrthancStone
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
27 {
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
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
87376a645ee1 renaming
am@osimis.io
parents: 274
diff changeset
34 NativeStoneApplicationContext& context) :
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
35 IObservable(broker),
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
36 callback_(callback),
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
37 parameters_(parameters),
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
38 uri_(uri),
257
9afafb192180 using PAM
am@osimis.io
parents: 251
diff changeset
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
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
42 {
267
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 258
diff changeset
43 DeclareEmittableMessage(MessageType_HttpRequestError);
89d02de83c03 added declaretion of messages handled/emitted
am@osimis.io
parents: 258
diff changeset
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
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
46 }
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
47
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
48
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
49 void WebServiceCommandBase::Commit()
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
50 {
291
87376a645ee1 renaming
am@osimis.io
parents: 274
diff changeset
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
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
53 if (success_)
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
54 {
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
55 IWebService::ICallback::HttpRequestSuccessMessage message(uri_, answer_.c_str(), answer_.size(), payload_.release());
258
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
56 EmitMessage(message);
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
57 }
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
58 else
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
59 {
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
60 IWebService::ICallback::HttpRequestErrorMessage message(uri_, payload_.release());
258
e5a9b3d03478 first very basic version of SmartLoader
am@osimis.io
parents: 257
diff changeset
61 EmitMessage(message);
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
62 }
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
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
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents:
diff changeset
100 }