RTC Toolkit 4.0.2
Loading...
Searching...
No Matches
rtcObject.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_RTCSUPERVISOR_RTCOBJECT_HPP
14#define RTCTK_RTCSUPERVISOR_RTCOBJECT_HPP
15
17
18#include <Rtctkif.hpp>
19#include <Stdif.hpp>
20
21#include <optional>
22#include <string>
23
24#include <fmt/format.h>
25
26namespace rtctk::rtcSupervisor {
27
36 std::string name;
37
39 std::string rr_uri;
40
42 std::string ps_uri;
43};
44
51enum class RtcCommand {
52 STOP,
53 INIT,
54 RESET,
55 ENABLE,
56 DISABLE,
57 EXIT,
60 UPDATE,
61};
62
70public:
71 virtual ~RtcObjectIf() = default;
72
78 virtual RtcObjectInfo GetInfo() const = 0;
79
85 virtual void RunAsync(RtcCommand cmd) = 0;
86
93 virtual std::string WaitAsync(std::optional<unsigned> timeout) = 0;
94};
95
102class RtcObject : public RtcObjectIf {
103public:
109 RtcObject(RtcObjectInfo const& obj_info);
110 virtual ~RtcObject() = default;
111 RtcObjectInfo GetInfo() const override;
112 void RunAsync(RtcCommand cmd) override;
113 std::string WaitAsync(std::optional<unsigned> timeout) override;
114
115private:
116 log4cplus::Logger& m_logger;
117
119 RtcObjectInfo m_info;
120 // reference to the name for convenience purpose
121 std::string const& m_name;
122
124 std::shared_ptr<stdif::StdCmdsAsync> m_stdif_async;
125 std::shared_ptr<rtctkif::UpdateCmdsAsync> m_ucif_async;
126
128 elt::mal::future<std::string> m_reply_future;
129
131 bool m_component_caused_exception;
132};
133
134} // namespace rtctk::rtcSupervisor
135
142template <>
143struct fmt::formatter<rtctk::rtcSupervisor::RtcCommand> : formatter<string_view> {
144 template <typename FormatContext>
145 auto format(rtctk::rtcSupervisor::RtcCommand c, FormatContext& ctx) const {
146 string_view name = "unknown";
147 switch (c) {
149 name = "STOP";
150 break;
152 name = "INIT";
153 break;
155 name = "RESET";
156 break;
158 name = "ENABLE";
159 break;
161 name = "DISABLE";
162 break;
164 name = "EXIT";
165 break;
167 name = "GET_STATE";
168 break;
170 name = "GET_VERSION";
171 break;
173 name = "UPDATE";
174 break;
175 }
176 return formatter<string_view>::format(name, ctx);
177 } // format
178}; // struct fmt::formatter
179
180#endif // RTCTK_RTCSUPERVISOR_RTCOBJECT_HPP
Interface class for RtcObject.
Definition: rtcObject.hpp:69
virtual std::string WaitAsync(std::optional< unsigned > timeout)=0
Weits for a previously started command request to conclude.
virtual void RunAsync(RtcCommand cmd)=0
Starts an async command request.
virtual RtcObjectInfo GetInfo() const =0
Get basic object information.
Concrete RtcObject implementation.
Definition: rtcObject.hpp:102
RtcObjectInfo GetInfo() const override
Get basic object information.
Definition: rtcObject.cpp:99
void RunAsync(RtcCommand cmd) override
Starts an async command request.
Definition: rtcObject.cpp:103
std::string WaitAsync(std::optional< unsigned > timeout) override
Weits for a previously started command request to conclude.
Definition: rtcObject.cpp:160
Logging Support Library based on log4cplus.
Definition: rtcSupervisor.cpp:21
RtcCommand
List of commands that can be issued by the RtcSupervisor.
Definition: rtcObject.hpp:51
Definition: commandReplier.cpp:22
auto format(rtctk::rtcSupervisor::RtcCommand c, FormatContext &ctx) const
Definition: rtcObject.hpp:145
Basic information necessary to construct an RtcObject.
Definition: rtcObject.hpp:34
std::string ps_uri
publish/subscribe uri
Definition: rtcObject.hpp:42
std::string rr_uri
request/response uri
Definition: rtcObject.hpp:39
std::string name
component name
Definition: rtcObject.hpp:36