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