RTI Routing Service  Version 6.0.1
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
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 
25 
26 namespace rti { namespace routing {
27 
28 class RoutingServiceImpl
29  : public rti::core::detail::RetainableType<RoutingServiceImpl> {
30 public:
31  explicit RoutingServiceImpl(const ServiceProperty& property)
32  {
33  native_ = RTI_RoutingService_new(&property.native());
34  rti::core::check_create_entity(native_, "RoutingService");
35  }
36 
37  RoutingServiceImpl(const RTI_RoutingServiceProperty& property)
38  : native_(NULL)
39  {
40  native_ = RTI_RoutingService_new(&property);
41  rti::core::check_create_entity(native_, "RoutingService");
42  }
43 
44  RoutingServiceImpl(RTI_RoutingService *native)
45  : native_(native)
46  {
47  rti::core::check_create_entity(native_, "RoutingService");
48  }
49 
50  ~RoutingServiceImpl()
51  {
52  RTI_RoutingService_delete(native_);
53  }
54 
55  void start()
56  {
57  if (!RTI_RoutingService_start(native_)) {
58  throw dds::core::Error("failed to start RoutingService");
59  }
60  }
61 
62  void stop()
63  {
64  if (!RTI_RoutingService_stop(native_)) {
65  throw dds::core::Error("failed to stop RoutingService");
66  }
67  }
68 
69  void attach_adapter_plugin(
71  const std::string& registered_name)
72  {
73  RTI_RoutingServiceAdapterPluginExt *native_plugin =
74  adapter::detail::AdapterForwarder::create_plugin(adapter_plugin);
75  if (!RTI_RoutingService_attach_adapter_plugin(
76  native_,
77  native_plugin,
78  registered_name.c_str())) {
79  throw dds::core::Error("failed to attach native adapter");
80  }
81  }
82 
83  void attach_transformation_plugin(
84  rti::routing::transf::TransformationPlugin *transformation_plugin,
85  const std::string& registered_name)
86  {
87  RTI_RoutingServiceTransformationPlugin *native_plugin =
88  transf::detail::TransformationPluginForwarder::create_plugin(
89  transformation_plugin);
90  if (!RTI_RoutingService_attach_transformation_plugin(
91  native_,
92  native_plugin,
93  registered_name.c_str())) {
94  throw dds::core::Error("failed to attach native transformation");
95  }
96  }
97 
98  void attach_processor_plugin(
100  const std::string& registered_name)
101  {
102  RTI_RoutingServiceProcessorPlugin *native_plugin =
103  processor::detail::ProcessorPluginForwarder::create_plugin(
104  processor_plugin);
105  if (!RTI_RoutingService_attach_processor_plugin(
106  native_,
107  native_plugin,
108  registered_name.c_str())) {
109  throw dds::core::Error("failed to attach native processor");
110  }
111  }
112 
113  RTI_RoutingService* native() const
114  {
115  return native_;
116  }
117 
118  static void finalize_globals()
119  {
120  if (!RTI_RoutingService_finalize_globals()) {
121  throw dds::core::Error("failed to finalize global state");
122  }
123  }
124 
125 private:
126  RTI_RoutingService *native_;
127 };
128 
129 }}
130 
131 #endif // RTI_ROUTINGv_ROUTING_SERVICE_IMPL_HPP_

RTI Routing Service Version 6.0.1 Copyright © Sun Nov 17 2019 Real-Time Innovations, Inc