9#ifndef RAD_MAL_REPLIER_HPP
10#define RAD_MAL_REPLIER_HPP
17#include <mal/utility/LoadMal.hpp>
37 explicit Replier(
const elt::mal::Uri& uri,
38 const std::optional<elt::mal::Mal::Properties> mal_properties = {})
42 m_server = elt::mal::CiiFactory::getInstance().createServer(
43 uri, elt::mal::rr::qos::QoS::DEFAULT,
44 mal_properties ? *mal_properties : elt::mal::Mal::Properties());
47 LOG4CPLUS_DEBUG(
GetLogger(),
"Created MAL server for <" << uri <<
">");
49 m_thread = std::thread([
this]() { m_server->run(); });
62 if (m_thread.joinable() ==
false) {
63 LOG4CPLUS_ERROR(
GetLogger(),
"Thread not joinable!");
68 LOG4CPLUS_ERROR(
GetLogger(),
"Unknown exception when closing MAL server!");
70 LOG4CPLUS_DEBUG(
GetLogger(),
"Terminated MAL server thread.");
80 template <
class SERVICE_TYPE>
81 void RegisterService(
const std::string& name, std::shared_ptr<SERVICE_TYPE> service) {
84 std::shared_ptr<elt::mal::rr::RrEntity> rrservice = service;
85 m_server->registerService<SERVICE_TYPE,
false>(name, rrservice);
86 LOG4CPLUS_DEBUG(
GetLogger(),
"Registered service <" << name <<
">");
97 m_server->unregisterService(name);
98 LOG4CPLUS_DEBUG(
GetLogger(),
"Unregistered service <" << name <<
">");
105 m_thread = std::thread(&Replier::Run,
this);
106 LOG4CPLUS_DEBUG(
GetLogger(),
"Started MAL server thread.");
118 m_mal_server->close();
119 if (m_thread.joinable() ==
false) {
120 LOG4CPLUS_ERROR(
GetLogger(),
"Thread not joinable!");
124 LOG4CPLUS_DEBUG(
GetLogger(),
"Terminated MAL server thread.");
132 std::unique_ptr<elt::mal::rr::Server> m_server;
133 std::thread m_thread;
137template<
typename SERVICE_TYPE,
typename INTERFACE_TYPE>
140 Replier(
const std::string& serverUri,
141 const std::string& malType,
142 const std::string& serviceName,
146 elt::mal::CiiFactory& factory = elt::mal::CiiFactory::getInstance();
148 elt::mal::Mal::Properties mal_properties;
149 auto malInstance = elt::mal::loadMal(malType, mal_properties);
151 elt::mal::Uri sUri = elt::mal::Uri(serverUri);
152 std::string scheme = sUri.scheme().to_string();
153 factory.registerMal(scheme, malInstance);
154 LOG4CPLUS_DEBUG(
GetLogger(),
"Registered MAL.");
156 m_mal_server = factory.createServer(sUri, elt::mal::rr::qos::QoS::DEFAULT, mal_properties);
158 std::shared_ptr<elt::mal::rr::RrEntity> serviceImpl = std::make_shared<INTERFACE_TYPE>(sm);
159 m_mal_server->registerService<SERVICE_TYPE,
false>(serviceName, serviceImpl);
161 LOG4CPLUS_DEBUG(
GetLogger(),
"Registered MAL <" << malType <<
"> service <" << serviceName <<
"> on <" << sUri <<
">");
167 if (m_mal_server !=
nullptr) {
168 m_thread = std::thread(&Replier::Run,
this);
169 LOG4CPLUS_DEBUG(
GetLogger(),
"Started MAL server thread.");
176 if (m_mal_server !=
nullptr) {
184 if (m_mal_server !=
nullptr) {
185 m_mal_server->close();
186 if (m_thread.joinable() ==
false) {
187 std::cout <<
"Thread not joinable!\n";
191 LOG4CPLUS_DEBUG(
GetLogger(),
"Terminated MAL server thread.");
199 std::unique_ptr<elt::mal::rr::Server> m_server;
200 std::thread m_thread;
#define RAD_ASSERTPTR(a)
Definition assert.hpp:19
Definition smAdapter.hpp:60
Definition replier.hpp:29
void UnregisterService(const std::string &name)
Definition replier.hpp:94
Replier(const elt::mal::Uri &uri, const std::optional< elt::mal::Mal::Properties > mal_properties={})
Definition replier.hpp:37
Replier(const Replier &)=delete
void RegisterService(const std::string &name, std::shared_ptr< SERVICE_TYPE > service)
Definition replier.hpp:81
~Replier()
Definition replier.hpp:56
Replier & operator=(const Replier &)=delete
#define RAD_TRACE(logger)
Definition logger.hpp:21
Definition actionsApp.cpp:23
log4cplus::Logger & GetLogger()
Definition logger.cpp:72