11 #ifndef RTI_ROUTING_ADAPTER_DETAIL_CONNECTION_FORWARDER_HPP_
12 #define RTI_ROUTING_ADAPTER_DETAIL_CONNECTION_FORWARDER_HPP_
14 #include <rti/core/Exception.hpp>
16 #include <osapi/osapi_heap.h>
17 #include <routingservice/routingservice_adapter_new.h>
20 #include <rti/routing/adapter/detail/SessionForwarder.hpp>
21 #include <rti/routing/adapter/detail/StreamReaderForwarder.hpp>
22 #include <rti/routing/adapter/detail/StreamWriterForwarder.hpp>
23 #include <rti/routing/adapter/detail/DiscoveryStreamReaderForwarder.hpp>
24 #include <rti/routing/detail/UpdatableEntityForwarder.hpp>
25 #include <rti/routing/detail/ForwarderUtils.hpp>
27 namespace rti {
namespace routing {
namespace adapter {
namespace detail {
29 class ConnectionForwarder {
31 static RTI_RoutingServiceConnectionExt * create_native(
32 AdapterPlugin *adapter,
35 const RTI_RoutingServiceStreamReaderListenerExt *native_output_stream_listener,
36 const RTI_RoutingServiceStreamReaderListenerExt *native_input_stream_listener,
37 const RTI_RoutingServiceTypeInfo **,
39 const RTI_RoutingServiceProperties *native_properties,
40 RTI_RoutingServiceEnvironment *environment)
44 std::map<std::string, std::string> properties;
45 rti::routing::PropertyAdapter::add_properties_from_native(
49 ConnectionForwarder *forwarder =
new ConnectionForwarder(
50 native_output_stream_listener,
51 native_input_stream_listener);
52 ScopedForwarder<AdapterPlugin, ConnectionForwarder> scoped(
57 forwarder->connection_ = adapter->create_connection(
58 &forwarder->input_discovery_listener_,
59 &forwarder->output_discovery_listener_,
61 RTI_ROUTING_THROW_ON_NULL(forwarder->connection_);
64 forwarder->input_stream_discovery_forwarder_ =
new DiscoveryStreamReaderForwarder(
65 forwarder->connection_->input_stream_discovery_reader());
67 forwarder->output_stream_discovery_forwarder_ =
new DiscoveryStreamReaderForwarder(
68 forwarder->connection_->output_stream_discovery_reader());
71 return forwarder->native();
72 }
catch (
const std::exception& ex) {
73 RTI_RoutingServiceEnvironment_set_error(
79 RTI_RoutingServiceEnvironment_set_error(
81 "unexpected exception");
86 static void delete_native(
87 AdapterPlugin *adapter,
88 RTI_RoutingServiceConnectionExt *native_connection,
89 RTI_RoutingServiceEnvironment *environment)
91 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
92 native_connection->connection_data);
95 delete forwarder->input_stream_discovery_forwarder_;
96 delete forwarder->output_stream_discovery_forwarder_;
99 if (forwarder->connection_ != NULL) {
100 adapter->delete_connection(forwarder->connection_);
101 forwarder->connection_ = NULL;
103 }
catch(
const std::exception& ex) {
104 RTI_RoutingServiceEnvironment_set_error(
115 static RTI_RoutingServiceStreamReaderExt *
116 get_input_stream_discovery_reader(
117 void *native_connection_data,
118 RTI_RoutingServiceEnvironment *)
120 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
121 native_connection_data);
122 return forwarder->input_stream_discovery_forwarder_->native();
125 static RTI_RoutingServiceStreamReaderExt *
126 get_output_stream_discovery_reader(
127 void *native_connection_data,
128 RTI_RoutingServiceEnvironment *)
130 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
131 native_connection_data);
132 return forwarder->output_stream_discovery_forwarder_->native();
135 static RTI_RoutingServiceSessionExt * create_session(
136 void *native_connection_data,
137 const struct RTI_RoutingServiceProperties * native_properties,
138 RTI_RoutingServiceEnvironment *environment)
141 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
142 native_connection_data);
144 return SessionForwarder::create_native(
145 forwarder->connection_,
150 static void delete_session(
151 void *native_connection_data,
152 RTI_RoutingServiceSessionExt *native_session,
153 RTI_RoutingServiceEnvironment *environment)
155 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
> (
156 native_connection_data);
158 SessionForwarder::delete_native(
159 forwarder->connection_,
164 static RTI_RoutingServiceStreamReaderExt* create_stream_reader(
165 void *native_connection_data,
166 void *native_session_data,
167 const struct RTI_RoutingServiceStreamInfo *native_stream_info,
168 const struct RTI_RoutingServiceProperties *native_properties,
169 const struct RTI_RoutingServiceStreamReaderListenerExt *native_listener,
170 RTI_RoutingServiceEnvironment *environment)
172 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
173 native_connection_data);
174 SessionForwarder *session_forwarder =
static_cast<SessionForwarder*
>(
175 native_session_data);
177 return StreamReaderForwarder::create_native(
178 forwarder->connection_,
179 session_forwarder->session(),
186 static void delete_stream_reader(
187 void *native_connection_data,
188 RTI_RoutingServiceStreamReaderExt *native_reader,
189 RTI_RoutingServiceEnvironment *environment)
191 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
192 native_connection_data);
193 StreamReaderForwarder::delete_native(
194 forwarder->connection_,
199 static RTI_RoutingServiceStreamWriterExt* create_stream_writer(
200 void *native_connection_data,
201 void *native_session_data,
202 const struct RTI_RoutingServiceStreamInfo *native_stream_info,
203 const struct RTI_RoutingServiceProperties *native_properties,
204 const struct RTI_RoutingServiceStreamWriterListenerExt *,
205 RTI_RoutingServiceEnvironment *environment)
207 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
208 native_connection_data);
209 SessionForwarder *session_forwarder =
static_cast<SessionForwarder*
>(
210 native_session_data);
212 return StreamWriterForwarder::create_native(
213 forwarder->connection_,
214 session_forwarder->session(),
220 static void delete_stream_writer(
221 void *native_connection_data,
222 RTI_RoutingServiceStreamWriterExt *native_writer,
223 RTI_RoutingServiceEnvironment *environment)
225 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
226 native_connection_data);
227 StreamWriterForwarder::delete_native(
228 forwarder->connection_,
234 void *native_connection_data,
235 const struct RTI_RoutingServiceProperties *native_properties,
236 RTI_RoutingServiceEnvironment *environment)
238 ConnectionForwarder *forwarder =
239 static_cast<ConnectionForwarder*
> (native_connection_data);
241 rti::routing::detail::UpdatableEntityForwarder::update(
242 forwarder->connection_,
248 Connection * connection()
253 RTI_RoutingServiceConnectionExt* native()
255 return &this->native_;
258 RTI_RoutingServiceStreamReaderExt* native_input_discovery_reader()
260 return input_stream_discovery_forwarder_->native();
263 RTI_RoutingServiceStreamReaderExt* native_output_discovery_reader()
265 return output_stream_discovery_forwarder_->native();
271 const RTI_RoutingServiceStreamReaderListenerExt *native_output_stream_listener,
272 const RTI_RoutingServiceStreamReaderListenerExt *native_input_stream_listener) :
274 output_stream_discovery_forwarder_(NULL),
275 output_discovery_listener_(native_output_stream_listener),
276 input_stream_discovery_forwarder_(NULL),
277 input_discovery_listener_(native_input_stream_listener)
279 RTIOsapiMemory_zero(&native_,
sizeof(native_));
280 native_.connection_data =
281 static_cast<void*
>(
this);
282 native_.create_session =
283 ConnectionForwarder::create_session;
284 native_.delete_session =
285 ConnectionForwarder::delete_session;
286 native_.create_stream_reader =
287 ConnectionForwarder::create_stream_reader;
288 native_.delete_stream_reader =
289 ConnectionForwarder::delete_stream_reader;
290 native_.create_stream_writer =
291 ConnectionForwarder::create_stream_writer;
292 native_.delete_stream_writer =
293 ConnectionForwarder::delete_stream_writer;
294 native_.get_input_stream_discovery_reader =
295 ConnectionForwarder::get_input_stream_discovery_reader;
296 native_.get_output_stream_discovery_reader =
297 ConnectionForwarder::get_output_stream_discovery_reader;
299 ConnectionForwarder::update;
302 ~ConnectionForwarder()
307 RTI_RoutingServiceConnectionExt native_;
308 Connection *connection_;
309 DiscoveryStreamReaderForwarder *output_stream_discovery_forwarder_;
310 StreamReaderListener output_discovery_listener_;
311 DiscoveryStreamReaderForwarder *input_stream_discovery_forwarder_;
312 StreamReaderListener input_discovery_listener_;
318 #endif // RTI_ROUTING_ADAPTER_DETAIL_CONNECTION_FORWARDER_HPP_