RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
introspectionImpl.hpp
Go to the documentation of this file.
1#ifndef RTCTK_COMPONENTFRAMEWORK_INTROSPECTIONIMPL_HPP
2#define RTCTK_COMPONENTFRAMEWORK_INTROSPECTIONIMPL_HPP
13
14#include <Introspectionif.hpp>
15#include <Stdif.hpp>
17#include <rtctk/componentFramework/events.rad.hpp>
21
22#include <mal/Cii.hpp>
23
24#include <fmt/core.h>
25#include <memory>
26#include <nlohmann/json.hpp>
27#include <string>
28
30
36class IntrospectionImpl : public virtual introspectionif::AsyncIntrospection {
37public:
38 static void Register(CommandReplier& replier, StateMachineEngine& engine) {
39 std::shared_ptr<elt::mal::rr::RrEntity> rr_service =
40 std::make_shared<IntrospectionImpl>(engine, replier);
41 replier.RegisterService<introspectionif::AsyncIntrospection>("Introspection", rr_service);
42 }
43
45 : m_engine(engine), m_replier(replier) {
46 }
47
48 ::elt::mal::future<std::string> GetInterfaces(const std::string& service) override {
49 LOG4CPLUS_TRACE(GetLogger(), "Received command 'GetInterfaces'");
50 boost::promise<std::string> promise;
51
52 // Request IF XMLs from server
53 auto xmls_vector = this->m_replier.GetServiceDescriptions(service);
54 try {
55 ::nlohmann::json ret_json = ::nlohmann::json::object({});
56 for (const auto& xml : xmls_vector) {
57 ret_json += ::nlohmann::json::object_t::value_type(xml.first, xml.second);
58 }
59 promise.set_value(ret_json.dump());
60 } catch (::nlohmann::json::type_error& ex) {
61 std::string msg =
62 fmt::format("Error while creating JSON reply: \nmessage: {}\nexception id: {}",
63 ex.what(),
64 ex.id);
65 LOG4CPLUS_ERROR(GetLogger(), msg);
66 auto new_exception =
67 stdif::ExceptionErr(msg, 3002); // ErrCode 3002 -> Could not create JSON reply
68 promise.set_exception(new_exception);
69 }
70
71 return promise.get_future();
72 }
73
74 ::elt::mal::future<std::string> GetTopics(const std::string& topic) override {
75 LOG4CPLUS_TRACE(GetLogger(), "Received command 'GetTopics'");
76 boost::promise<std::string> promise;
77 LOG4CPLUS_INFO(GetLogger(), "NOT IMPLEMENTED");
78 auto new_exception =
79 stdif::ExceptionErr("NOT IMPLEMENTED", 3001); // ErrCode 3001 -> Not implemented
80 promise.set_exception(new_exception);
81 return promise.get_future();
82 }
83
84 ::elt::mal::future<std::string> GetOldbPrefix() override {
85 LOG4CPLUS_TRACE(GetLogger(), "Received command 'GetOldbPrefix'");
86 boost::promise<std::string> promise;
87 LOG4CPLUS_INFO(GetLogger(), "NOT IMPLEMENTED");
88 auto new_exception = stdif::ExceptionErr("NOT IMPLEMENTED", 3001);
89 promise.set_exception(new_exception);
90 return promise.get_future();
91 }
92
93private:
94 StateMachineEngine& m_engine;
95 CommandReplier& m_replier;
96};
97
98} // namespace rtctk::componentFramework
99
100#endif // RTCTK_COMPONENTFRAMEWORK_INTROSPECTIONIMPL_HPP
Class that handles reception of commands using MAL.
Definition commandReplier.hpp:29
void RegisterService(const std::string &name, std::shared_ptr< elt::mal::rr::RrEntity > &service)
Definition commandReplier.hpp:36
static void Register(CommandReplier &replier, StateMachineEngine &engine)
Definition introspectionImpl.hpp:38
::elt::mal::future< std::string > GetInterfaces(const std::string &service) override
Definition introspectionImpl.hpp:48
IntrospectionImpl(StateMachineEngine &engine, CommandReplier &replier)
Definition introspectionImpl.hpp:44
::elt::mal::future< std::string > GetOldbPrefix() override
Definition introspectionImpl.hpp:84
::elt::mal::future< std::string > GetTopics(const std::string &topic) override
Definition introspectionImpl.hpp:74
Definition stateMachineEngine.hpp:34
Receive commands via MAL.
log4cplus::Logger & GetLogger(const std::string &name="app")
Get handle to a specific logger.
Definition logger.cpp:191
Logging Support Library based on log4cplus.
Provides core functionality of an RTC Component.
Definition commandReplier.cpp:21
Wrapper around the SCXML State Machine Engine.