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 StreamInfo stream_info(*native_stream_info);
36 std::map<std::string, std::string> properties;
37 rti::routing::PropertyAdapter::add_properties_from_native(
41 StreamWriterForwarder *forwarder =
new StreamWriterForwarder(
43 ScopedForwarder<Connection, StreamWriterForwarder> scoped(
47 forwarder->stream_writer_ = connection->create_stream_writer(
51 RTI_ROUTING_THROW_ON_NULL(forwarder->stream_writer_);
54 return forwarder->native();
56 }
catch(
const std::exception& ex) {
57 RTI_RoutingServiceEnvironment_set_error(
63 RTI_RoutingServiceEnvironment_set_error(
65 "unexpected exception");
71 static void delete_native(
72 Connection *connection,
73 RTI_RoutingServiceStreamWriterExt *native_stream_writer,
74 RTI_RoutingServiceEnvironment *environment)
76 StreamWriterForwarder *stream_writer_forwarder =
77 static_cast<StreamWriterForwarder*
>(
78 native_stream_writer->stream_writer_data);
80 if (stream_writer_forwarder->stream_writer_ != NULL) {
81 connection->delete_stream_writer(
82 stream_writer_forwarder->stream_writer_);
83 stream_writer_forwarder->stream_writer_ = NULL;
85 }
catch(
const std::exception& ex) {
86 RTI_RoutingServiceEnvironment_set_error(
93 delete stream_writer_forwarder;
98 void *native_stream_writer_data,
99 const RTI_RoutingServiceSample *sample_array,
100 const RTI_RoutingServiceSampleInfo *sample_info_array,
102 RTI_RoutingServiceEnvironment *environment)
105 StreamWriterForwarder *forwarder =
106 static_cast<StreamWriterForwarder*
>(native_stream_writer_data);
109 RTI_ROUTING_SAMPLE_VECTOR_COPY_FROM_NATIVE(
110 forwarder->sample_seq_,
113 if (sample_info_array != NULL) {
114 RTI_ROUTING_SAMPLE_VECTOR_COPY_FROM_NATIVE(
115 forwarder->info_seq_,
119 forwarder->info_seq_.clear();
121 return forwarder->stream_writer_->write(
122 forwarder->sample_seq_,
123 forwarder->info_seq_);
124 }
catch (
const std::exception& ex) {
125 RTI_RoutingServiceEnvironment_set_error(
130 RTI_RoutingServiceEnvironment_set_error(
132 "unexpected exception");
139 void *native_stream_writer_data,
140 const struct RTI_RoutingServiceProperties * native_properties,
141 RTI_RoutingServiceEnvironment * environment)
144 StreamWriterForwarder *stream_writer_forwarder =
145 static_cast<StreamWriterForwarder*
> (native_stream_writer_data);
147 rti::routing::detail::UpdatableEntityForwarder::update(
148 stream_writer_forwarder->stream_writer_,
153 RTI_RoutingServiceStreamWriterExt* native()
155 return &this->native_;
160 StreamWriterForwarder(
161 StreamWriter *stream_writer) :
162 stream_writer_(stream_writer)
164 RTIOsapiMemory_zero(&native_,
sizeof(native_));
165 native_.stream_writer_data =
166 static_cast<void*
>(
this);
168 StreamWriterForwarder::write;
170 StreamWriterForwarder::update;
174 ~StreamWriterForwarder()
179 RTI_RoutingServiceStreamWriterExt native_;
180 StreamWriter *stream_writer_;
181 std::vector<StreamWriter::SamplePtr> sample_seq_;
182 std::vector<StreamWriter::InfoPtr> info_seq_;
188 #endif // RTI_ROUTING_ADAPTER_DETAIL_STREAM_WRITER_FORWARDER_HPP_