RTC Toolkit  1.0.0
commandRequestor.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_COMPONENTFRAMEWORK_COMMANDREQUESTOR_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_COMMANDREQUESTOR_HPP
14 
15 #include <Rtctkif.hpp>
16 
17 #include <mal/Cii.hpp>
18 #include <mal/utility/Uri.hpp>
19 
20 #include <chrono>
21 #include <memory>
22 #include <optional>
23 
24 namespace rtctk::componentFramework {
25 
30 public:
37  CommandRequestor(const elt::mal::Uri& uri,
38  std::optional<std::chrono::milliseconds> timeout = std::nullopt);
39 
40  virtual ~CommandRequestor() = default;
41 
48  std::string SendCommandSync(std::string const& id, std::string const& args);
55  elt::mal::future<std::string>
56  SendCommandAsync(std::string const& id, std::string const& args);
57 
58 protected:
65  template <typename T>
66  std::unique_ptr<T> MakeInterface(std::string const& name) {
67  return m_factory.getClient<T>(elt::mal::Uri(m_uri + name), m_qos, m_props);
68  }
69 
76  void RegisterCommand(std::string const& id,
77  std::function<elt::mal::future<std::string>(std::string const&)> fun);
78 
79 private:
80  std::string m_uri;
81  elt::mal::Mal::Properties m_props;
82  elt::mal::CiiFactory& m_factory;
83  std::vector<std::shared_ptr<elt::mal::rr::qos::QoS>> m_qos;
84 
85  std::map<std::string, std::function<elt::mal::future<std::string>(std::string const&)>> m_cmds;
86 
87  std::unique_ptr<stdif::StdCmdsAsync> stdif;
88  std::unique_ptr<rtctkif::UpdateCmdsAsync> ucif;
89  std::unique_ptr<rtctkif::FuncCmdsAsync> fcif;
90  std::unique_ptr<rtctkif::MeasCmdsAsync> mcif;
91  std::unique_ptr<rtctkif::OptCmdsAsync> ocif;
92  std::unique_ptr<rtctkif::LoopCmdsAsync> lcif;
93  std::unique_ptr<rtctkif::SuspCmdsAsync> lsif;
94 };
95 
96 } // namespace rtctk::componentFramework
97 
98 #endif // RTCTK_COMPONENTFRAMEWORK_COMMANDREQUESTOR_HPP
wscript.name
name
Definition: wscript:15
rtctk::componentFramework::CommandRequestor::~CommandRequestor
virtual ~CommandRequestor()=default
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::CommandRequestor
Extendable class that allows to send commands to components using MAL.
Definition: commandRequestor.hpp:29
rtctk::componentFramework::CommandRequestor::SendCommandAsync
elt::mal::future< std::string > SendCommandAsync(std::string const &id, std::string const &args)
Send asynchronous command to a component.
Definition: commandRequestor.cpp:84
rtctk::componentFramework::CommandRequestor::RegisterCommand
void RegisterCommand(std::string const &id, std::function< elt::mal::future< std::string >(std::string const &)> fun)
Register a new command.
Definition: commandRequestor.cpp:62
rtctk::componentFramework::CommandRequestor::MakeInterface
std::unique_ptr< T > MakeInterface(std::string const &name)
Make a new MAL interface.
Definition: commandRequestor.hpp:66
rtctk::componentFramework::CommandRequestor::CommandRequestor
CommandRequestor(const elt::mal::Uri &uri, std::optional< std::chrono::milliseconds > timeout=std::nullopt)
Create a new CommandRequestor object.
Definition: commandRequestor.cpp:23
stdif
Definition: statePublisher.hpp:24
rtctk::componentFramework::CommandRequestor::SendCommandSync
std::string SendCommandSync(std::string const &id, std::string const &args)
Send synchronous command to a component.
Definition: commandRequestor.cpp:72