RTI Routing Service Version 7.2.0
RoutingServiceImpl.hpp
1/*
2 * (c) Copyright, Real-Time Innovations, 2017.
3 * All rights reserved.
4 *
5 * No duplications, whole or partial, manual or electronic, may be made
6 * without express written permission. Any such copies, or
7 * revisions thereof, must display this notice unaltered.
8 * This code contains trade secrets of Real-Time Innovations, Inc.
9 */
10
11#ifndef RTI_ROUTING_ROUTING_SERVICE_IMPL_HPP_
12#define RTI_ROUTING_ROUTING_SERVICE_IMPL_HPP_
13
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
20#include <rti/routing/ServiceProperty.hpp>
21#include <rti/routing/adapter/detail/AdapterForwarder.hpp>
22#include <rti/routing/transf/detail/TransformationPluginForwarder.hpp>
23#include <rti/routing/processor/detail/ProcessorPluginForwarder.hpp>
24#include <rti/routing/detail/ShutdownHookForwarder.hpp>
25
26namespace rti { namespace routing {
27
28class RoutingServiceImpl
29 : public rti::core::detail::RetainableType<RoutingServiceImpl> {
30public:
31
32 template <typename HookFunc>
33 explicit RoutingServiceImpl(
34 const ServiceProperty& property,
35 HookFunc& shutdown_hook)
36 : native_(RTI_RoutingService_new(&property.native())),
37 shutdown_hook_fwd_(
38 new rti::routing::detail::ShutdownHookForwarder<HookFunc>(
39 shutdown_hook))
40 {
41 rti::core::check_create_entity(native_, "RoutingService");
42 RTI_RoutingService_set_remote_shutdown_hook(
43 native_,
44 shutdown_hook_fwd_->native());
45 }
46
47 explicit RoutingServiceImpl(const ServiceProperty& property)
48 : native_(RTI_RoutingService_new(&property.native())),
49 shutdown_hook_fwd_(nullptr)
50 {
51 rti::core::check_create_entity(native_, "RoutingService");
52 }
53
54 RoutingServiceImpl(const RTI_RoutingServiceProperty& property)
55 : native_(RTI_RoutingService_new(&property)),
56 shutdown_hook_fwd_(NULL)
57 {
58 rti::core::check_create_entity(native_, "RoutingService");
59 }
60
61 RoutingServiceImpl(RTI_RoutingService *native)
62 : native_(native), shutdown_hook_fwd_(NULL)
63 {
64 rti::core::check_create_entity(native_, "RoutingService");
65 }
66
67 ~RoutingServiceImpl()
68 {
69 RTI_RoutingService_delete(native_);
70 delete shutdown_hook_fwd_;
71 }
72
73 void start()
74 {
75 if (!RTI_RoutingService_start(native_)) {
76 throw dds::core::Error("failed to start RoutingService");
77 }
78 }
79
80 void stop()
81 {
82 if (!RTI_RoutingService_stop(native_)) {
83 throw dds::core::Error("failed to stop RoutingService");
84 }
85 }
86
87 void attach_adapter_plugin(
89 const std::string& registered_name)
90 {
91 RTI_RoutingServiceAdapterPluginExt *native_plugin =
92 adapter::detail::AdapterForwarder::create_plugin(adapter_plugin);
93 if (!RTI_RoutingService_attach_adapter_plugin(
94 native_,
95 native_plugin,
96 registered_name.c_str())) {
97 throw dds::core::Error("failed to attach native adapter");
98 }
99 }
100
101 void attach_transformation_plugin(
102 rti::routing::transf::TransformationPlugin *transformation_plugin,
103 const std::string& registered_name)
104 {
105 RTI_RoutingServiceTransformationPlugin *native_plugin =
106 transf::detail::TransformationPluginForwarder::create_plugin(
107 transformation_plugin);
108 if (!RTI_RoutingService_attach_transformation_plugin(
109 native_,
110 native_plugin,
111 registered_name.c_str())) {
112 throw dds::core::Error("failed to attach native transformation");
113 }
114 }
115
116 void attach_processor_plugin(
118 const std::string& registered_name)
119 {
120 RTI_RoutingServiceProcessorPlugin *native_plugin =
121 processor::detail::ProcessorPluginForwarder::create_plugin(
122 processor_plugin);
123 if (!RTI_RoutingService_attach_processor_plugin(
124 native_,
125 native_plugin,
126 registered_name.c_str())) {
127 throw dds::core::Error("failed to attach native processor");
128 }
129 }
130
131 RTI_RoutingService* native() const
132 {
133 return native_;
134 }
135
136private:
137 RTI_RoutingService *native_;
138 rti::routing::detail::AbstractShutdownHookForwarder *shutdown_hook_fwd_;
139};
140
141}}
142
143#endif // RTI_ROUTINGv_ROUTING_SERVICE_IMPL_HPP_
The top-level plug-in class.
Definition: AdapterPlugin.hpp:34
The top-level plug-in class.
Definition: ProcessorPlugin.hpp:202
The top-level plug-in class.
Definition: TransformationPlugin.hpp:44