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/routingservice_remote_config.h"
20#include "routingservice/ServiceAdmin.h"
22#include <rti/routing/ServiceProperty.hpp>
26#include <rti/routing/detail/ShutdownHookForwarder.hpp>
27#include <rti/idlgen/ServiceAdmin.hpp>
29namespace rti {
namespace routing {
30class RoutingServiceImpl
31 :
public rti::core::detail::RetainableType<RoutingServiceImpl> {
34 typedef RTI::Service::Admin::CommandRequest CommandRequest;
35 typedef RTI::Service::Admin::CommandReply CommandReply;
37 template <
typename HookFunc>
38 explicit RoutingServiceImpl(
39 const ServiceProperty& property,
40 HookFunc& shutdown_hook)
41 : native_(RTI_RoutingService_new(&property.native())),
43 new rti::routing::detail::ShutdownHookForwarder<HookFunc>(
46 rti::core::check_create_entity(native_,
"RoutingService");
47 RTI_RoutingService_set_remote_shutdown_hook(
49 shutdown_hook_fwd_->native());
52 explicit RoutingServiceImpl(
const ServiceProperty& property)
53 : native_(RTI_RoutingService_new(&property.native())),
54 shutdown_hook_fwd_(nullptr)
56 rti::core::check_create_entity(native_,
"RoutingService");
59 RoutingServiceImpl(
const RTI_RoutingServiceProperty& property)
60 : native_(RTI_RoutingService_new(&property)),
61 shutdown_hook_fwd_(NULL)
63 rti::core::check_create_entity(native_,
"RoutingService");
66 RoutingServiceImpl(RTI_RoutingService *native)
67 : native_(native), shutdown_hook_fwd_(NULL)
69 rti::core::check_create_entity(native_,
"RoutingService");
74 RTI_RoutingService_delete(native_);
75 delete shutdown_hook_fwd_;
80 if (!RTI_RoutingService_start(native_)) {
81 throw dds::core::Error(
"failed to start RoutingService");
87 if (!RTI_RoutingService_stop(native_)) {
88 throw dds::core::Error(
"failed to stop RoutingService");
92 void attach_adapter_plugin(
94 const std::string& registered_name)
96 RTI_RoutingServiceAdapterPluginExt *native_plugin =
97 adapter::detail::AdapterForwarder::create_plugin(adapter_plugin);
98 if (!RTI_RoutingService_attach_adapter_plugin(
101 registered_name.c_str())) {
102 throw dds::core::Error(
"failed to attach native adapter");
106 void attach_transformation_plugin(
108 const std::string& registered_name)
110 RTI_RoutingServiceTransformationPlugin *native_plugin =
111 transf::detail::TransformationPluginForwarder::create_plugin(
112 transformation_plugin);
113 if (!RTI_RoutingService_attach_transformation_plugin(
116 registered_name.c_str())) {
117 throw dds::core::Error(
"failed to attach native transformation");
121 void attach_processor_plugin(
123 const std::string& registered_name)
125 RTI_RoutingServiceProcessorPlugin *native_plugin =
126 processor::detail::ProcessorPluginForwarder::create_plugin(
128 if (!RTI_RoutingService_attach_processor_plugin(
131 registered_name.c_str())) {
132 throw dds::core::Error(
"failed to attach native processor");
136 CommandReply& execute_command(
138 const CommandRequest& request)
140 RTI_Service_Admin_CommandRequest native_request =
141 RTI_Service_Admin_CommandRequest_INITIALIZER;
142 RTI_Service_Admin_CommandReply *native_reply_ptr =
nullptr;
144 if (!RTI_Service_Admin_CommandRequest_initialize(&native_request)) {
145 RTI_Service_Admin_CommandRequest_finalize(&native_request);
146 throw dds::core::Error(
"failed to initialize CommandRequest");
148 std::shared_ptr<RTI_Service_Admin_CommandRequest> request_ptr(
150 [](RTI_Service_Admin_CommandRequest *native_req_ptr) {
151 RTI_Service_Admin_CommandRequest_finalize(native_req_ptr);
154 to_native(native_request, request);
155 RTI_RoutingService_execute_command(
159 from_native(reply, *native_reply_ptr);
160 RTI_RoutingService_return_reply(native_, native_reply_ptr);
164 CommandReply execute_command(
const CommandRequest& request)
167 return execute_command(reply, request);
171 RTI_RoutingService* native()
const
178 RTI_RoutingService *native_;
180 rti::routing::detail::AbstractShutdownHookForwarder *shutdown_hook_fwd_;
182 static RTI_Service_Admin_CommandRequest& to_native(
183 RTI_Service_Admin_CommandRequest& native,
184 const RTI::Service::Admin::CommandRequest& request)
186 native.action =
static_cast<RTI_Service_Admin_CommandActionKind
>(
188 if (request.application_name().is_set()) {
189 if (DDS_String_replace(
190 &native.application_name,
191 request.application_name().get().c_str()) == NULL) {
192 throw dds::core::Error(
"failed to set application name");
195 native.instance_id = request.instance_id();
196 if (DDS_String_replace(
197 &native.resource_identifier,
198 request.resource_identifier().c_str()) == NULL) {
199 throw dds::core::Error(
"failed to set resource identifier");
201 if (DDS_String_replace(
203 request.string_body().c_str()) == NULL) {
204 throw dds::core::Error(
"failed to set string body");
206 if (!DDS_OctetSeq_from_array(
208 (DDS_Octet *) request.octet_body().data(),
209 (DDS_Long) request.octet_body().size())) {
210 throw dds::core::Error(
"failed to set octet body");
215 static RTI::Service::Admin::CommandReply& from_native(
216 RTI::Service::Admin::CommandReply& reply,
217 const RTI_Service_Admin_CommandReply& native)
219 using namespace RTI::Service::Admin;
221 reply.retcode(
static_cast<CommandReplyRetcode
>(native.retcode));
222 reply.native_retcode(native.native_retcode);
223 DDS_Octet *native_octet_body = DDS_OctetSeq_get_contiguous_buffer(
224 (DDS_OctetSeq *) &native.octet_body);
225 if (DDS_OctetSeq_get_length(&native.octet_body) < 0) {
226 throw dds::core::Error(
"invalid octet_body length");
228 reply.octet_body().resize(
229 (
size_t) DDS_OctetSeq_get_length(&native.octet_body));
232 native_octet_body + DDS_OctetSeq_get_length(&native.octet_body),
233 reply.octet_body().begin());
234 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