9#ifndef RAD_MAL_REQUESTOR_HPP
10#define RAD_MAL_REQUESTOR_HPP
20#include <mal/utility/LoadMal.hpp>
21#include <mal/rr/qos/QoS.hpp>
22#include <mal/rr/qos/ReplyTime.hpp>
23#include <mal/rr/qos/ConnectionTime.hpp>
41template <
typename INTERFACE_TYPE>
53 const std::vector<std::shared_ptr<elt::mal::rr::qos::QoS>>& qos,
54 const std::optional<elt::mal::Mal::Properties> mal_properties = {})
58 m_client = elt::mal::CiiFactory::getInstance().getClient<INTERFACE_TYPE>(
59 uri, qos, mal_properties.value_or(elt::mal::Mal::Properties()));
60 LOG4CPLUS_DEBUG(
GetLogger(),
"Created MAL client for <" << uri <<
">");
70 const std::optional<elt::mal::Mal::Properties> mal_properties = {})
71 :
Requestor(uri, elt::mal::rr::qos::QoS::DEFAULT, mal_properties) {}
89 std::shared_ptr<INTERFACE_TYPE> m_client;
103template <
class EVENT,
class T>
105 ::elt::mal::future<T> fut = ami->next();
106 fut.then([=, &sm](::elt::mal::future<T> fut) {
109 "Received async partial reply, triggering associated event <"
110 <<
typeid(EVENT).name() <<
">");
111 sm.
PostEvent(std::make_unique<EVENT>(fut.get()));
113 "Received async partial reply, triggering associated event - done!");
114 if (ami->isDone() ==
false) {
115 RoutePartialReply<EVENT, T>(ami, sm);
117 "Invoked RoutePartialReply for the next partial/final reply");
120 LOG4CPLUS_ERROR(
GetLogger(),
"Unknown exception when receiving partial reply");
123 LOG4CPLUS_DEBUG(log4cplus::Logger::getInstance(
rad::LOGGER_NAME),
"Installed AMI continuation");
137template <
class EVENT,
class FUT>
140 rep_future.then([&](FUT res) {
145 LOG4CPLUS_DEBUG(GetLogger(),
"Received async reply, triggering associated event <"
146 << typeid(EVENT).name() <<
">");
147 sm.PostEvent(std::make_unique<EVENT>(res));
148 LOG4CPLUS_DEBUG(GetLogger(),
149 "Received async reply, triggering associated event - done!");
151 LOG4CPLUS_ERROR(
GetLogger(),
"Unknown exception when receiving the reply");
154 LOG4CPLUS_DEBUG(
GetLogger(),
"Installed future continuation");
170template <
class EVENT,
class EVENT_ERR,
class FUT>
173 rep_future.then([&, token](FUT res) {
178 if (res.has_value()) {
180 if constexpr (std::is_void<typename FUT::value_type>::value) {
181 LOG4CPLUS_DEBUG(GetLogger(),
182 "Received async VOID reply, triggering associated event <"
183 << typeid(EVENT).name() <<
">");
184 sm.PostEvent(std::make_unique<EVENT>());
188 LOG4CPLUS_DEBUG(GetLogger(),
189 "Received async reply, triggering associated event <"
190 << typeid(EVENT).name() <<
">");
191 sm.PostEvent(std::make_unique<EVENT>(res.get()));
193 LOG4CPLUS_DEBUG(GetLogger(),
194 "Received async reply, triggering associated event - done!");
195 }
else if (res.has_exception()) {
196 LOG4CPLUS_DEBUG(GetLogger(),
"Exception waiting for reply");
197 sm.PostEvent(std::make_unique<EVENT_ERR>(res.get_exception_ptr()));
202 LOG4CPLUS_ERROR(
GetLogger(),
"Unknown exception when receiving the reply");
205 LOG4CPLUS_DEBUG(
GetLogger(),
"Installed future continuation");
223template <
class EVENT,
class EVENT_TIMEOUT,
class EVENT_ERR,
class FUT>
226 rep_future.then([&, token](FUT res) {
231 if (res.has_value()) {
233 if constexpr (std::is_void<typename FUT::value_type>::value) {
234 LOG4CPLUS_DEBUG(GetLogger(),
235 "Received async VOID reply, triggering associated event <"
236 << typeid(EVENT).name() <<
">");
237 sm.PostEvent(std::make_unique<EVENT>());
241 LOG4CPLUS_DEBUG(GetLogger(),
242 "Received async reply, triggering associated event <"
243 << typeid(EVENT).name() <<
">");
244 sm.PostEvent(std::make_unique<EVENT>(res.get()));
246 LOG4CPLUS_DEBUG(GetLogger(),
247 "Received async reply, triggering associated event - done!");
248 }
else if (res.has_exception()) {
249 LOG4CPLUS_DEBUG(GetLogger(),
"Received exception as reply, rethrowing it.");
250 boost::rethrow_exception(res.get_exception_ptr());
254 }
catch (
const elt::mal::TimeoutException& e) {
255 LOG4CPLUS_DEBUG(
GetLogger(),
"ExceptionTimeout while waiting for reply");
256 sm.
PostEvent(std::make_unique<EVENT_TIMEOUT>());
258 LOG4CPLUS_DEBUG(
GetLogger(),
"Received exception as reply, post associated event <"
259 <<
typeid(EVENT).name() <<
">");
260 sm.
PostEvent(std::make_unique<EVENT_ERR>(res.get_exception_ptr()));
263 LOG4CPLUS_DEBUG(
GetLogger(),
"Installed future continuation");
Definition smAdapter.hpp:60
void PostEvent(SharedEvent e)
Definition smAdapter.cpp:296
bool IsCancelled() const
Definition utils.hpp:89
Definition requestor.hpp:42
Requestor(const elt::mal::Uri &uri, const std::vector< std::shared_ptr< elt::mal::rr::qos::QoS > > &qos, const std::optional< elt::mal::Mal::Properties > mal_properties={})
Definition requestor.hpp:52
std::shared_ptr< INTERFACE_TYPE > & GetInterface()
Definition requestor.hpp:80
Requestor(const Requestor &)=delete
Requestor & operator=(const Requestor &)=delete
Requestor(const elt::mal::Uri &uri, const std::optional< elt::mal::Mal::Properties > mal_properties={})
Definition requestor.hpp:69
#define RAD_TRACE(logger)
Definition logger.hpp:21
CancellationToken RouteReplyWithTimeout(FUT &&rep_future, rad::SMAdapter &sm)
Definition requestor.hpp:224
void RoutePartialReply(std::shared_ptr<::elt::mal::rr::Ami< T > > ami, rad::SMAdapter &sm)
Definition requestor.hpp:104
CancellationToken RouteReply(FUT &&rep_future, rad::SMAdapter &sm)
Definition requestor.hpp:138
Definition actionsApp.cpp:23
const std::string LOGGER_NAME
Definition logger.hpp:76
log4cplus::Logger & GetLogger()
Definition logger.cpp:72
SMAdapter class header file.