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)
43 using rti::routing::detail::ScopedForwarder;
46 std::map<std::string, std::string> properties;
47 rti::routing::PropertyAdapter::add_properties_from_native(
51 ConnectionForwarder *forwarder =
new ConnectionForwarder(
52 native_output_stream_listener,
53 native_input_stream_listener);
54 ScopedForwarder<AdapterPlugin, ConnectionForwarder> scoped(
59 forwarder->connection_ = adapter->create_connection(
60 &forwarder->input_discovery_listener_,
61 &forwarder->output_discovery_listener_,
63 RTI_ROUTING_THROW_ON_NULL(forwarder->connection_);
66 forwarder->input_stream_discovery_forwarder_ =
new DiscoveryStreamReaderForwarder(
67 forwarder->connection_->input_stream_discovery_reader());
69 forwarder->output_stream_discovery_forwarder_ =
new DiscoveryStreamReaderForwarder(
70 forwarder->connection_->output_stream_discovery_reader());
73 return forwarder->native();
74 }
catch (
const std::exception& ex) {
75 RTI_RoutingServiceEnvironment_set_error(
81 RTI_RoutingServiceEnvironment_set_error(
83 "unexpected exception");
88 static void delete_native(
89 AdapterPlugin *adapter,
90 RTI_RoutingServiceConnectionExt *native_connection,
91 RTI_RoutingServiceEnvironment *environment)
93 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
94 native_connection->connection_data);
97 delete forwarder->input_stream_discovery_forwarder_;
98 delete forwarder->output_stream_discovery_forwarder_;
101 if (forwarder->connection_ != NULL) {
102 adapter->delete_connection(forwarder->connection_);
103 forwarder->connection_ = NULL;
105 }
catch(
const std::exception& ex) {
106 RTI_RoutingServiceEnvironment_set_error(
117 static RTI_RoutingServiceStreamReaderExt *
118 get_input_stream_discovery_reader(
119 void *native_connection_data,
120 RTI_RoutingServiceEnvironment *)
122 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
123 native_connection_data);
124 return forwarder->input_stream_discovery_forwarder_->native();
127 static RTI_RoutingServiceStreamReaderExt *
128 get_output_stream_discovery_reader(
129 void *native_connection_data,
130 RTI_RoutingServiceEnvironment *)
132 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
133 native_connection_data);
134 return forwarder->output_stream_discovery_forwarder_->native();
137 static RTI_RoutingServiceSessionExt * create_session(
138 void *native_connection_data,
139 const struct RTI_RoutingServiceProperties * native_properties,
140 RTI_RoutingServiceEnvironment *environment)
143 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
144 native_connection_data);
146 return SessionForwarder::create_native(
147 forwarder->connection_,
152 static void delete_session(
153 void *native_connection_data,
154 RTI_RoutingServiceSessionExt *native_session,
155 RTI_RoutingServiceEnvironment *environment)
157 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
> (
158 native_connection_data);
160 SessionForwarder::delete_native(
161 forwarder->connection_,
166 static RTI_RoutingServiceStreamReaderExt* create_stream_reader(
167 void *native_connection_data,
168 void *native_session_data,
169 const struct RTI_RoutingServiceStreamInfo *native_stream_info,
170 const struct RTI_RoutingServiceProperties *native_properties,
171 const struct RTI_RoutingServiceStreamReaderListenerExt *native_listener,
172 RTI_RoutingServiceEnvironment *environment)
174 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
175 native_connection_data);
176 SessionForwarder *session_forwarder =
static_cast<SessionForwarder*
>(
177 native_session_data);
179 return StreamReaderForwarder::create_native(
180 forwarder->connection_,
181 session_forwarder->session(),
188 static void delete_stream_reader(
189 void *native_connection_data,
190 RTI_RoutingServiceStreamReaderExt *native_reader,
191 RTI_RoutingServiceEnvironment *environment)
193 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
194 native_connection_data);
195 StreamReaderForwarder::delete_native(
196 forwarder->connection_,
201 static RTI_RoutingServiceStreamWriterExt* create_stream_writer(
202 void *native_connection_data,
203 void *native_session_data,
204 const struct RTI_RoutingServiceStreamInfo *native_stream_info,
205 const struct RTI_RoutingServiceProperties *native_properties,
206 const struct RTI_RoutingServiceStreamWriterListenerExt *,
207 RTI_RoutingServiceEnvironment *environment)
209 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
210 native_connection_data);
211 SessionForwarder *session_forwarder =
static_cast<SessionForwarder*
>(
212 native_session_data);
214 return StreamWriterForwarder::create_native(
215 forwarder->connection_,
216 session_forwarder->session(),
222 static void delete_stream_writer(
223 void *native_connection_data,
224 RTI_RoutingServiceStreamWriterExt *native_writer,
225 RTI_RoutingServiceEnvironment *environment)
227 ConnectionForwarder *forwarder =
static_cast<ConnectionForwarder*
>(
228 native_connection_data);
229 StreamWriterForwarder::delete_native(
230 forwarder->connection_,
236 void *native_connection_data,
237 const struct RTI_RoutingServiceProperties *native_properties,
238 RTI_RoutingServiceEnvironment *environment)
240 ConnectionForwarder *forwarder =
241 static_cast<ConnectionForwarder*
> (native_connection_data);
243 rti::routing::detail::UpdatableEntityForwarder::update(
244 forwarder->connection_,
250 Connection * connection()
255 RTI_RoutingServiceConnectionExt* native()
257 return &this->native_;
260 RTI_RoutingServiceStreamReaderExt* native_input_discovery_reader()
262 return input_stream_discovery_forwarder_->native();
265 RTI_RoutingServiceStreamReaderExt* native_output_discovery_reader()
267 return output_stream_discovery_forwarder_->native();
273 const RTI_RoutingServiceStreamReaderListenerExt *native_output_stream_listener,
274 const RTI_RoutingServiceStreamReaderListenerExt *native_input_stream_listener) :
276 output_stream_discovery_forwarder_(NULL),
277 output_discovery_listener_(native_output_stream_listener),
278 input_stream_discovery_forwarder_(NULL),
279 input_discovery_listener_(native_input_stream_listener)
281 RTIOsapiMemory_zero(&native_,
sizeof(native_));
282 native_.connection_data =
283 static_cast<void*
>(
this);
284 native_.create_session =
285 ConnectionForwarder::create_session;
286 native_.delete_session =
287 ConnectionForwarder::delete_session;
288 native_.create_stream_reader =
289 ConnectionForwarder::create_stream_reader;
290 native_.delete_stream_reader =
291 ConnectionForwarder::delete_stream_reader;
292 native_.create_stream_writer =
293 ConnectionForwarder::create_stream_writer;
294 native_.delete_stream_writer =
295 ConnectionForwarder::delete_stream_writer;
296 native_.get_input_stream_discovery_reader =
297 ConnectionForwarder::get_input_stream_discovery_reader;
298 native_.get_output_stream_discovery_reader =
299 ConnectionForwarder::get_output_stream_discovery_reader;
301 ConnectionForwarder::update;
304 ~ConnectionForwarder()
309 RTI_RoutingServiceConnectionExt native_;
310 Connection *connection_;
311 DiscoveryStreamReaderForwarder *output_stream_discovery_forwarder_;
312 StreamReaderListener output_discovery_listener_;
313 DiscoveryStreamReaderForwarder *input_stream_discovery_forwarder_;
314 StreamReaderListener input_discovery_listener_;
320 #endif // RTI_ROUTING_ADAPTER_DETAIL_CONNECTION_FORWARDER_HPP_