RTC Toolkit 5.1.0
Loading...
Searching...
No Matches
commandRequestor.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_COMMANDREQUESTOR_HPP
14#define RTCTK_COMPONENTFRAMEWORK_COMMANDREQUESTOR_HPP
15
16#include <Introspectionif.hpp>
17#include <Rtctkif.hpp>
18#include <Stdif.hpp>
19
20#include <mal/Cii.hpp>
21#include <mal/utility/Uri.hpp>
22
23#include <chrono>
24#include <memory>
25#include <optional>
26
28
35public:
42 explicit CommandRequestor(const elt::mal::Uri& uri,
43 std::optional<std::chrono::milliseconds> timeout = std::nullopt);
44
45 virtual ~CommandRequestor() = default;
46
53 std::string SendCommandSync(const std::string& id, const std::string& args);
60 elt::mal::future<std::string> SendCommandAsync(const std::string& id, const std::string& args);
61
62protected:
69 template <typename T>
70 std::unique_ptr<T> MakeInterface(const std::string& name) {
71 return m_factory.getClient<T>(elt::mal::Uri(m_uri + name), m_qos, m_props);
72 }
73
80 void RegisterCommand(const std::string& id,
81 std::function<elt::mal::future<std::string>(const std::string&)> fun);
82
83private:
84 std::string m_uri;
85 elt::mal::Mal::Properties m_props;
86 elt::mal::CiiFactory& m_factory;
87 std::vector<std::shared_ptr<elt::mal::rr::qos::QoS>> m_qos;
88
89 // cppcheck-suppress unusedStructMember
90 std::map<std::string, std::function<elt::mal::future<std::string>(const std::string&)>> m_cmds;
91
92 std::unique_ptr<introspectionif::IntrospectionAsync> insif;
93 std::unique_ptr<stdif::StdCmdsAsync> stdif;
94 std::unique_ptr<rtctkif::RecoverCmdsAsync> rcif;
95 std::unique_ptr<rtctkif::AlertCmdsAsync> acif;
96 std::unique_ptr<rtctkif::UpdateCmdsAsync> ucif;
97 std::unique_ptr<rtctkif::FuncCmdsAsync> fcif;
98 std::unique_ptr<rtctkif::MeasCmdsAsync> mcif;
99 std::unique_ptr<rtctkif::OptCmdsAsync> ocif;
100 std::unique_ptr<rtctkif::LoopCmdsAsync> lcif;
101 std::unique_ptr<rtctkif::SuspCmdsAsync> lsif;
102 std::unique_ptr<rtctkif::ModeCmdsAsync> smif;
103 std::unique_ptr<rtctkif::WriteBackCmdsAsync> wbif;
104};
105
106} // namespace rtctk::componentFramework
107
108#endif // RTCTK_COMPONENTFRAMEWORK_COMMANDREQUESTOR_HPP
Extendable class that allows to send commands to components using MAL.
Definition commandRequestor.hpp:34
std::string SendCommandSync(const std::string &id, const std::string &args)
Send synchronous command to a component.
Definition commandRequestor.cpp:96
void RegisterCommand(const std::string &id, std::function< elt::mal::future< std::string >(const std::string &)> fun)
Register a new command.
Definition commandRequestor.cpp:88
CommandRequestor(const elt::mal::Uri &uri, std::optional< std::chrono::milliseconds > timeout=std::nullopt)
Create a new CommandRequestor object.
Definition commandRequestor.cpp:24
elt::mal::future< std::string > SendCommandAsync(const std::string &id, const std::string &args)
Send asynchronous command to a component.
Definition commandRequestor.cpp:112
std::unique_ptr< T > MakeInterface(const std::string &name)
Make a new MAL interface.
Definition commandRequestor.hpp:70
Definition commandReplier.cpp:22
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Definition statePublisher.hpp:25