11#ifndef RTI_ROUTING_ROUTING_SERVICE_IMPL_HPP_
12#define RTI_ROUTING_ROUTING_SERVICE_IMPL_HPP_
14#include <dds/core/refmacros.hpp>
15#include <rti/core/detail/SelfReference.hpp>
16#include "routingservice/routingservice_adapter.h"
17#include "routingservice/routingservice_service.h"
18#include "routingservice/routingservice_log.h"
19#include "routingservice/ServiceAdmin.h"
21#include <rti/routing/ServiceProperty.hpp>
25#include <rti/routing/detail/ShutdownHookForwarder.hpp>
26#include <rti/idlgen/ServiceAdmin.hpp>
28namespace rti {
namespace routing {
29class RoutingServiceImpl
30 :
public rti::core::detail::RetainableType<RoutingServiceImpl> {
33 typedef RTI::Service::Admin::CommandRequest CommandRequest;
34 typedef RTI::Service::Admin::CommandReply CommandReply;
36 template <
typename HookFunc>
37 explicit RoutingServiceImpl(
38 const ServiceProperty& property,
39 HookFunc& shutdown_hook)
40 : native_(RTI_RoutingService_new(&property.native())),
42 new rti::routing::detail::ShutdownHookForwarder<HookFunc>(
45 rti::core::check_create_entity(native_,
"RoutingService");
46 RTI_RoutingService_set_remote_shutdown_hook(
48 shutdown_hook_fwd_->native());
51 explicit RoutingServiceImpl(
const ServiceProperty& property)
52 : native_(RTI_RoutingService_new(&property.native())),
53 shutdown_hook_fwd_(nullptr)
55 rti::core::check_create_entity(native_,
"RoutingService");
58 RoutingServiceImpl(
const RTI_RoutingServiceProperty& property)
59 : native_(RTI_RoutingService_new(&property)),
60 shutdown_hook_fwd_(NULL)
62 rti::core::check_create_entity(native_,
"RoutingService");
65 RoutingServiceImpl(RTI_RoutingService *native)
66 : native_(native), shutdown_hook_fwd_(NULL)
68 rti::core::check_create_entity(native_,
"RoutingService");
73 RTI_RoutingService_delete(native_);
74 delete shutdown_hook_fwd_;
79 if (!RTI_RoutingService_start(native_)) {
80 throw dds::core::Error(
"failed to start RoutingService");
86 if (!RTI_RoutingService_stop(native_)) {
87 throw dds::core::Error(
"failed to stop RoutingService");
91 void attach_adapter_plugin(
93 const std::string& registered_name)
95 RTI_RoutingServiceAdapterPluginExt *native_plugin =
96 adapter::detail::AdapterForwarder::create_plugin(adapter_plugin);
97 if (!RTI_RoutingService_attach_adapter_plugin(
100 registered_name.c_str())) {
101 throw dds::core::Error(
"failed to attach native adapter");
105 void attach_transformation_plugin(
107 const std::string& registered_name)
109 RTI_RoutingServiceTransformationPlugin *native_plugin =
110 transf::detail::TransformationPluginForwarder::create_plugin(
111 transformation_plugin);
112 if (!RTI_RoutingService_attach_transformation_plugin(
115 registered_name.c_str())) {
116 throw dds::core::Error(
"failed to attach native transformation");
120 void attach_processor_plugin(
122 const std::string& registered_name)
124 RTI_RoutingServiceProcessorPlugin *native_plugin =
125 processor::detail::ProcessorPluginForwarder::create_plugin(
127 if (!RTI_RoutingService_attach_processor_plugin(
130 registered_name.c_str())) {
131 throw dds::core::Error(
"failed to attach native processor");
135 CommandReply& execute_command(
137 const CommandRequest& request)
139 RTI_Service_Admin_CommandRequest native_request;
140 RTI_Service_Admin_CommandReply *native_reply_ptr =
nullptr;
142 if (!RTI_Service_Admin_CommandRequest_initialize(&native_request)) {
143 RTI_Service_Admin_CommandRequest_finalize(&native_request);
144 throw dds::core::Error(
"failed to initialize CommandRequest");
146 std::shared_ptr<RTI_Service_Admin_CommandRequest> request_ptr(
148 [](RTI_Service_Admin_CommandRequest *native_req_ptr) {
149 RTI_Service_Admin_CommandRequest_finalize(native_req_ptr);
152 to_native(native_request, request);
153 RTI_RoutingService_execute_command(
157 from_native(reply, *native_reply_ptr);
158 RTI_RoutingService_return_reply(native_, native_reply_ptr);
162 CommandReply execute_command(
const CommandRequest& request)
165 return execute_command(reply, request);
169 RTI_RoutingService* native()
const
176 RTI_RoutingService *native_;
178 rti::routing::detail::AbstractShutdownHookForwarder *shutdown_hook_fwd_;
180 static RTI_Service_Admin_CommandRequest& to_native(
181 RTI_Service_Admin_CommandRequest& native,
182 const RTI::Service::Admin::CommandRequest& request)
184 native.action =
static_cast<RTI_Service_Admin_CommandActionKind
>(
186 if (request.application_name().is_set()) {
187 if (DDS_String_replace(
188 &native.application_name,
189 request.application_name().get().c_str()) == NULL) {
190 throw dds::core::Error(
"failed to set application name");
193 native.instance_id = request.instance_id();
194 if (DDS_String_replace(
195 &native.resource_identifier,
196 request.resource_identifier().c_str()) == NULL) {
197 throw dds::core::Error(
"failed to set resource identifier");
199 if (DDS_String_replace(
201 request.string_body().c_str()) == NULL) {
202 throw dds::core::Error(
"failed to set string body");
204 if (!DDS_OctetSeq_from_array(
206 (DDS_Octet *) request.octet_body().data(),
207 (DDS_Long) request.octet_body().size())) {
208 throw dds::core::Error(
"failed to set octet body");
213 static RTI::Service::Admin::CommandReply& from_native(
214 RTI::Service::Admin::CommandReply& reply,
215 const RTI_Service_Admin_CommandReply& native)
217 using namespace RTI::Service::Admin;
219 reply.retcode(
static_cast<CommandReplyRetcode
>(native.retcode));
220 reply.native_retcode(native.native_retcode);
221 DDS_Octet *native_octet_body = DDS_OctetSeq_get_contiguous_buffer(
222 (DDS_OctetSeq *) &native.octet_body);
223 if (DDS_OctetSeq_get_length(&native.octet_body) < 0) {
224 throw dds::core::Error(
"invalid octet_body length");
226 reply.octet_body().resize(
227 (
size_t) DDS_OctetSeq_get_length(&native.octet_body));
230 native_octet_body + DDS_OctetSeq_get_length(&native.octet_body),
231 reply.octet_body().begin());
232 reply.string_body(native.string_body);
RTI Routing Service C++ Adapter API.
RTI Routing Service C++ Processor API.
The top-level plug-in class.
Definition: AdapterPlugin.hpp:34
The top-level plug-in class.
Definition: ProcessorPlugin.hpp:202