ifw-slm 0.1.2
 
Loading...
Searching...
No Matches
malRequestActivity.hpp
Go to the documentation of this file.
1
14#ifndef IFWSLM_MAL_REQUEST_ACTIVITY_HPP
15#define IFWSLM_MAL_REQUEST_ACTIVITY_HPP
16
19
20#include <rad/mal/requestor.hpp>
21
22#include <memory>
23#include <string>
24
25namespace ifw::slm {
26
32template<class Interface>
34public:
41 MalRequestLoopActivity(const std::string& id,
42 rad::SMAdapter& sm,
43 DataContext& data,
44 int loop_index,
45 LoopCompletionHandler* completion_handler = nullptr,
46 const std::string& endpoint_param = "params/cmd_endpoint",
47 int connect_timeout_ms = 5000,
48 int reply_timeout_ms = 20000)
49 : BaseLoopExecuteActivity(id, sm, data, loop_index, completion_handler),
50 m_endpoint_param(endpoint_param),
51 m_connect_timeout_ms(connect_timeout_ms),
52 m_reply_timeout_ms(reply_timeout_ms) {
53 // Capture the raw endpoint spec on the construction (main/config)
54 // thread. The service name is resolved to a live URI later, at first
55 // use (HTTP resolution is thread-safe).
56 m_endpoint_spec = GetLoopParam<std::string>(m_endpoint_param, std::string(""));
57 }
58
59protected:
65 std::string Endpoint() const {
66 // WriteSecondaryLoopConfig echoes the per-loop params to OLDB, so an
67 // operator can retarget the loop at runtime by writing this key. Prefer
68 // that live value and fall back to the configured spec captured at
69 // construction.
70 std::string spec;
71 if (!ReadLoopOldb<std::string>(m_endpoint_param, spec) || spec.empty()) {
72 spec = m_endpoint_spec;
73 }
74 return ResolveEndpoint(spec, m_resolver, m_namespace);
75 }
76
78 auto Remote() {
79 return Requestor().GetInterface();
80 }
81
83 rad::cii::Requestor<Interface>& Requestor() {
84 if (!m_requestor) {
85 m_endpoint = Endpoint();
86 elt::mal::Mal::Properties props;
87 props["zpb.rr.ConnectTimeoutMs"] = std::to_string(m_connect_timeout_ms);
88 props["zpb.rr.ReplyTimeoutMs"] = std::to_string(m_reply_timeout_ms);
89 m_requestor = std::make_unique<rad::cii::Requestor<Interface>>(
90 elt::mal::Uri(m_endpoint), props);
91 LOG4CPLUS_INFO(m_logger, "Loop " << m_loop_index
92 << " MAL requestor created for " << m_endpoint);
93 }
94 return *m_requestor;
95 }
96
97private:
98 std::string m_endpoint_param;
99 std::string m_endpoint_spec;
100 std::string m_endpoint;
101 int m_connect_timeout_ms;
102 int m_reply_timeout_ms;
103 ServiceResolver m_resolver;
104 std::string m_namespace{ServiceResolver::DefaultNamespace()};
105 std::unique_ptr<rad::cii::Requestor<Interface>> m_requestor;
106};
107
108} // namespace ifw::slm
109
110#endif // IFWSLM_MAL_REQUEST_ACTIVITY_HPP
Base action classes for loop control actions.
log4cplus::Logger m_logger
Definition baseLoopActions.hpp:195
int m_loop_index
Definition baseLoopActions.hpp:190
bool ReadLoopOldb(const std::string &name, T &out) const
Definition baseLoopActions.hpp:168
BaseLoopExecuteActivity(const std::string &id, rad::SMAdapter &sm, DataContext &data, int loop_index, LoopCompletionHandler *completion_handler=nullptr)
Definition baseLoopActions.cpp:297
T GetLoopParam(const std::string &name) const
Definition baseLoopActions.hpp:149
Definition dataContext.hpp:29
Interface for handling loop completion events.
Definition loopCompletionHandler.hpp:32
auto Remote()
Definition malRequestActivity.hpp:78
rad::cii::Requestor< Interface > & Requestor()
Definition malRequestActivity.hpp:83
MalRequestLoopActivity(const std::string &id, rad::SMAdapter &sm, DataContext &data, int loop_index, LoopCompletionHandler *completion_handler=nullptr, const std::string &endpoint_param="params/cmd_endpoint", int connect_timeout_ms=5000, int reply_timeout_ms=20000)
Definition malRequestActivity.hpp:41
std::string Endpoint() const
Definition malRequestActivity.hpp:65
Definition serviceResolver.hpp:25
static std::string DefaultNamespace()
Default namespace from $NOMAD_NAMESPACE, else "default".
Definition serviceResolver.cpp:108
Definition actionMgr.cpp:29
std::string ResolveEndpoint(const std::string &spec, const ServiceResolver &resolver, const std::string &name_space=ServiceResolver::DefaultNamespace())
Definition serviceResolver.cpp:160
Runtime resolution of a registered service NAME into a MAL URI.