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