11 #ifndef RTI_ROUTING_ADAPTER_DETAIL_DISCOVERY_STREAM_READER_FORWARDER_HPP_
12 #define RTI_ROUTING_ADAPTER_DETAIL_DISCOVERY_STREAM_READER_FORWARDER_HPP_
14 #include <rti/core/Exception.hpp>
16 #include <routingservice/routingservice_adapter_new.h>
19 #include <rti/routing/detail/ForwarderUtils.hpp>
21 namespace rti {
namespace routing {
namespace adapter {
namespace detail {
24 class DiscoveryStreamReaderForwarder {
27 void *native_stream_reader_data,
28 RTI_RoutingServiceSample **sample_array,
29 RTI_RoutingServiceSampleInfo **sample_info_array,
31 RTI_RoutingServiceEnvironment *environment)
33 DiscoveryStreamReaderForwarder *forwarder =
34 static_cast<DiscoveryStreamReaderForwarder*
>(native_stream_reader_data);
36 *sample_info_array = NULL;
39 forwarder->stream_reader_->take(forwarder->sample_seq_);
40 *array_length = forwarder->sample_seq_.size();
41 if (*array_length > 0) {
42 *sample_array =
reinterpret_cast<RTI_RoutingServiceSample*
> (
43 &forwarder->sample_seq_[0]);
45 }
catch (
const std::exception& ex) {
46 RTI_RoutingServiceEnvironment_set_error(
51 RTI_RoutingServiceEnvironment_set_error(
53 "unexpected exception");
58 static void return_loan(
59 void *native_stream_reader_data,
60 RTI_RoutingServiceSample *,
61 RTI_RoutingServiceSampleInfo *,
63 RTI_RoutingServiceEnvironment *environment)
65 DiscoveryStreamReaderForwarder *forwarder =
66 static_cast<DiscoveryStreamReaderForwarder*
> (native_stream_reader_data);
69 forwarder->stream_reader_->return_loan(forwarder->sample_seq_);
70 }
catch (
const std::exception& ex) {
71 RTI_RoutingServiceEnvironment_set_error(
76 RTI_RoutingServiceEnvironment_set_error(
78 "unexpected exception");
81 forwarder->sample_seq_.clear();
85 DiscoveryStreamReaderForwarder(
86 DiscoveryStreamReader *stream_reader) :
87 stream_reader_(stream_reader)
89 RTIOsapiMemory_zero(&native_,
sizeof(native_));
90 native_.stream_reader_data =
91 static_cast<void *
>(
this);
93 DiscoveryStreamReaderForwarder::take;
95 DiscoveryStreamReaderForwarder::return_loan;
99 ~DiscoveryStreamReaderForwarder()
104 static DiscoveryStreamReaderForwarder* from_native(
105 RTI_RoutingServiceStreamReaderExt *native)
107 return static_cast<DiscoveryStreamReaderForwarder*
>(native->stream_reader_data);
110 RTI_RoutingServiceStreamReaderExt * native()
116 RTI_RoutingServiceStreamReaderExt native_;
117 DiscoveryStreamReader *stream_reader_;
118 std::vector<StreamInfo*> sample_seq_;
123 #endif // RTI_ROUTING_ADAPTER_DETAIL_DISCOVERY_STREAM_READER_FORWARDER_HPP_