RTI Routing Service  Version 6.0.0
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
DiscoveryStreamReaderForwarder.hpp
1 /*
2  * (c) Copyright, Real-Time Innovations, 2017.
3  * All rights reserved.
4  *
5  * No duplications, whole or partial, manual or electronic, may be made
6  * without express written permission. Any such copies, or
7  * revisions thereof, must display this notice unaltered.
8  * This code contains trade secrets of Real-Time Innovations, Inc.
9  */
10 
11 #ifndef RTI_ROUTING_ADAPTER_DETAIL_DISCOVERY_STREAM_READER_FORWARDER_HPP_
12 #define RTI_ROUTING_ADAPTER_DETAIL_DISCOVERY_STREAM_READER_FORWARDER_HPP_
13 
14 #include <rti/core/Exception.hpp>
15 
16 #include <routingservice/routingservice_adapter_new.h>
17 
19 #include <rti/routing/detail/ForwarderUtils.hpp>
20 
21 namespace rti { namespace routing { namespace adapter { namespace detail {
22 
23 
24 class DiscoveryStreamReaderForwarder {
25 public:
26  static void take(
27  void *native_stream_reader_data,
28  RTI_RoutingServiceSample **sample_array,
29  RTI_RoutingServiceSampleInfo **sample_info_array,
30  int *array_length,
31  RTI_RoutingServiceEnvironment *environment)
32  {
33  DiscoveryStreamReaderForwarder *forwarder =
34  static_cast<DiscoveryStreamReaderForwarder*>(native_stream_reader_data);
35 
36  *sample_info_array = NULL;
37  *array_length = 0;
38  try {
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]);
44  }
45  } catch (const std::exception& ex) {
46  RTI_RoutingServiceEnvironment_set_error(
47  environment,
48  "%s",
49  ex.what());
50  } catch (...) {
51  RTI_RoutingServiceEnvironment_set_error(
52  environment,
53  "unexpected exception");
54  }
55 
56  }
57 
58  static void return_loan(
59  void *native_stream_reader_data,
60  RTI_RoutingServiceSample *,
61  RTI_RoutingServiceSampleInfo *,
62  int,
63  RTI_RoutingServiceEnvironment *environment)
64  {
65  DiscoveryStreamReaderForwarder *forwarder =
66  static_cast<DiscoveryStreamReaderForwarder*> (native_stream_reader_data);
67 
68  try {
69  forwarder->stream_reader_->return_loan(forwarder->sample_seq_);
70  } catch (const std::exception& ex) {
71  RTI_RoutingServiceEnvironment_set_error(
72  environment,
73  "%s",
74  ex.what());
75  } catch (...) {
76  RTI_RoutingServiceEnvironment_set_error(
77  environment,
78  "unexpected exception");
79  return;
80  }
81  forwarder->sample_seq_.clear();
82  }
83 
84 
85  DiscoveryStreamReaderForwarder(
86  DiscoveryStreamReader *stream_reader) :
87  stream_reader_(stream_reader)
88  {
89  RTIOsapiMemory_zero(&native_, sizeof(native_));
90  native_.stream_reader_data =
91  static_cast<void *>(this);
92  native_.take =
93  DiscoveryStreamReaderForwarder::take;
94  native_.return_loan =
95  DiscoveryStreamReaderForwarder::return_loan;
96  }
97 
98 
99  ~DiscoveryStreamReaderForwarder()
100  {
101  }
102 
103 
104  static DiscoveryStreamReaderForwarder* from_native(
105  RTI_RoutingServiceStreamReaderExt *native)
106  {
107  return static_cast<DiscoveryStreamReaderForwarder*>(native->stream_reader_data);
108  }
109 
110  RTI_RoutingServiceStreamReaderExt * native()
111  {
112  return &native_;
113  }
114 
115 private:
116  RTI_RoutingServiceStreamReaderExt native_;
117  DiscoveryStreamReader *stream_reader_;
118  std::vector<StreamInfo*> sample_seq_;
119 };
120 
121 }}}}
122 
123 #endif // RTI_ROUTING_ADAPTER_DETAIL_DISCOVERY_STREAM_READER_FORWARDER_HPP_

RTI Routing Service Version 6.0.0 Copyright © Sun Mar 3 2019 Real-Time Innovations, Inc