RTC Toolkit 5.0.0
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
35 // cppcheck-suppress-begin unusedStructMember
36
38 std::string name;
39
41 std::string rr_uri;
42
44 std::string ps_uri;
45
46 // cppcheck-suppress-end unusedStructMember
47};
48
55enum class RtcCommand : uint8_t {
56 STOP,
57 INIT,
58 RESET,
59 ENABLE,
60 DISABLE,
61 EXIT,
64 UPDATE,
66 RECOVER, // optional command
67};
68
76public:
77 virtual ~RtcObjectIf() = default;
78
84 virtual RtcObjectInfo GetInfo() const = 0;
85
91 virtual void RunAsync(RtcCommand cmd) = 0;
92
99 virtual std::string WaitAsync(std::optional<unsigned> timeout) = 0;
100};
101
108class RtcObject : public RtcObjectIf {
109public:
115 explicit RtcObject(const RtcObjectInfo& obj_info);
116 ~RtcObject() override = default;
117 RtcObjectInfo GetInfo() const override;
118 void RunAsync(RtcCommand cmd) override;
119 std::string WaitAsync(std::optional<unsigned> timeout) override;
120
121private:
122 // cppcheck-suppress-begin unusedStructMember
123
124 log4cplus::Logger& m_logger;
125
127 RtcObjectInfo m_info;
128 // reference to the name for convenience purpose
129 const std::string& m_name;
130
132 std::shared_ptr<stdif::StdCmdsAsync> m_stdif_async;
133 std::shared_ptr<rtctkif::UpdateCmdsAsync> m_ucif_async;
134 std::shared_ptr<rtctkif::AlertCmdsAsync> m_acif_async;
135 std::shared_ptr<rtctkif::RecoverCmdsAsync> m_rcif_async;
136
138 elt::mal::future<std::string> m_reply_future;
139
140 // cppcheck-suppress-end unusedStructMember
141};
142
143} // namespace rtctk::rtcSupervisor
144
151template <>
152struct fmt::formatter<rtctk::rtcSupervisor::RtcCommand> : formatter<string_view> {
153 template <typename FormatContext>
154 auto format(rtctk::rtcSupervisor::RtcCommand c, FormatContext& ctx) const {
155 string_view name = "unknown";
156 switch (c) {
158 name = "STOP";
159 break;
161 name = "INIT";
162 break;
164 name = "RESET";
165 break;
167 name = "ENABLE";
168 break;
170 name = "DISABLE";
171 break;
173 name = "EXIT";
174 break;
176 name = "GET_STATE";
177 break;
179 name = "GET_VERSION";
180 break;
182 name = "UPDATE";
183 break;
185 name = "CLEAR_ALERTS";
186 break;
188 name = "RECOVER";
189 break;
190 }
191 return formatter<string_view>::format(name, ctx);
192 } // format
193}; // struct fmt::formatter
194
195#endif // RTCTK_RTCSUPERVISOR_RTCOBJECT_HPP
Interface class for RtcObject.
Definition rtcObject.hpp:75
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:108
RtcObjectInfo GetInfo() const override
Get basic object information.
Definition rtcObject.cpp:117
void RunAsync(RtcCommand cmd) override
Starts an async command request.
Definition rtcObject.cpp:121
~RtcObject() override=default
RtcObject(const RtcObjectInfo &obj_info)
Constructor for default RtcObject.
Definition rtcObject.cpp:59
std::string WaitAsync(std::optional< unsigned > timeout) override
Weits for a previously started command request to conclude.
Definition rtcObject.cpp:179
Logging Support Library based on log4cplus.
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Definition rtcSupervisor.cpp:24
RtcCommand
List of commands that can be issued by the RtcSupervisor.
Definition rtcObject.hpp:55
Definition commandReplier.cpp:22
auto format(rtctk::rtcSupervisor::RtcCommand c, FormatContext &ctx) const
Definition rtcObject.hpp:154
Basic information necessary to construct an RtcObject.
Definition rtcObject.hpp:34
std::string ps_uri
publish/subscribe uri
Definition rtcObject.hpp:44
std::string rr_uri
request/response uri
Definition rtcObject.hpp:41
std::string name
component name
Definition rtcObject.hpp:38