11 #ifndef RTI_ROUTING_ADAPTER_DETAIL_STREAM_WRITER_FORWARDER_HPP_
12 #define RTI_ROUTING_ADAPTER_DETAIL_STREAM_WRITER_FORWARDER_HPP_
14 #include <rti/core/Exception.hpp>
16 #include <rti/routing/adapter/StreamWriter.hpp>
17 #include <rti/routing/detail/UpdatableEntityForwarder.hpp>
18 #include <rti/routing/detail/ForwarderUtils.hpp>
20 namespace rti {
namespace routing {
namespace adapter {
namespace detail {
23 class StreamWriterForwarder {
26 static RTI_RoutingServiceStreamWriterExt* create_native(
27 Connection *connection,
29 const struct RTI_RoutingServiceStreamInfo *native_stream_info,
30 const struct RTI_RoutingServiceProperties *native_properties,
31 RTI_RoutingServiceEnvironment *environment)
34 using rti::routing::detail::ScopedForwarder;
36 StreamInfo stream_info(*native_stream_info);
38 std::map<std::string, std::string> properties;
39 rti::routing::PropertyAdapter::add_properties_from_native(
43 StreamWriterForwarder *forwarder =
new StreamWriterForwarder(
45 ScopedForwarder<Connection, StreamWriterForwarder> scoped(
49 forwarder->stream_writer_ = connection->create_stream_writer(
53 RTI_ROUTING_THROW_ON_NULL(forwarder->stream_writer_);
56 return forwarder->native();
58 }
catch(
const std::exception& ex) {
59 RTI_RoutingServiceEnvironment_set_error(
65 RTI_RoutingServiceEnvironment_set_error(
67 "unexpected exception");
73 static void delete_native(
74 Connection *connection,
75 RTI_RoutingServiceStreamWriterExt *native_stream_writer,
76 RTI_RoutingServiceEnvironment *environment)
78 StreamWriterForwarder *stream_writer_forwarder =
79 static_cast<StreamWriterForwarder*
>(
80 native_stream_writer->stream_writer_data);
82 if (stream_writer_forwarder->stream_writer_ != NULL) {
83 connection->delete_stream_writer(
84 stream_writer_forwarder->stream_writer_);
85 stream_writer_forwarder->stream_writer_ = NULL;
87 }
catch(
const std::exception& ex) {
88 RTI_RoutingServiceEnvironment_set_error(
95 delete stream_writer_forwarder;
100 void *native_stream_writer_data,
101 const RTI_RoutingServiceSample *sample_array,
102 const RTI_RoutingServiceSampleInfo *sample_info_array,
104 RTI_RoutingServiceEnvironment *environment)
107 StreamWriterForwarder *forwarder =
108 static_cast<StreamWriterForwarder*
>(native_stream_writer_data);
111 RTI_ROUTING_SAMPLE_VECTOR_COPY_FROM_NATIVE(
112 forwarder->sample_seq_,
115 if (sample_info_array != NULL) {
116 RTI_ROUTING_SAMPLE_VECTOR_COPY_FROM_NATIVE(
117 forwarder->info_seq_,
121 forwarder->info_seq_.clear();
123 return forwarder->stream_writer_->write(
124 forwarder->sample_seq_,
125 forwarder->info_seq_);
126 }
catch (
const std::exception& ex) {
127 RTI_RoutingServiceEnvironment_set_error(
132 RTI_RoutingServiceEnvironment_set_error(
134 "unexpected exception");
141 void *native_stream_writer_data,
142 const struct RTI_RoutingServiceProperties * native_properties,
143 RTI_RoutingServiceEnvironment * environment)
146 StreamWriterForwarder *stream_writer_forwarder =
147 static_cast<StreamWriterForwarder*
> (native_stream_writer_data);
149 rti::routing::detail::UpdatableEntityForwarder::update(
150 stream_writer_forwarder->stream_writer_,
155 RTI_RoutingServiceStreamWriterExt* native()
157 return &this->native_;
162 StreamWriterForwarder(
163 StreamWriter *stream_writer) :
164 stream_writer_(stream_writer)
166 RTIOsapiMemory_zero(&native_,
sizeof(native_));
167 native_.stream_writer_data =
168 static_cast<void*
>(
this);
170 StreamWriterForwarder::write;
172 StreamWriterForwarder::update;
176 ~StreamWriterForwarder()
181 RTI_RoutingServiceStreamWriterExt native_;
182 StreamWriter *stream_writer_;
183 std::vector<StreamWriter::SamplePtr> sample_seq_;
184 std::vector<StreamWriter::InfoPtr> info_seq_;
190 #endif // RTI_ROUTING_ADAPTER_DETAIL_STREAM_WRITER_FORWARDER_HPP_