RTI Recording Service  Version 6.0.1
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Groups
StorageStreamInfoReaderForwarder.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_RECORDING_STORAGE_DETAIL_STORAGE_DISC_STREAM_READER_FORWARDER_HPP_
12 #define RTI_RECORDING_STORAGE_DETAIL_STORAGE_DISC_STREAM_READER_FORWARDER_HPP_
13 
14 #include <map>
15 #include <string>
16 
17 #include "rti/recording/storage/StorageStreamInfoReader.hpp"
18 #include "log/log_common.h"
19 #include "recordingservice/recordingservice_storagereader.h"
20 
21 #include "rtiboost/smart_ptr/shared_ptr.hpp"
22 #include "rti/routing/detail/ForwarderUtils.hpp"
23 
25 
26 namespace rti { namespace recording { namespace storage { namespace detail {
27 
34 public:
35  StorageStreamInfoReaderDeleter(StorageReader *storage_reader_parent)
36  : storage_reader_parent_(storage_reader_parent)
37  {
38  RTIBOOST_ASSERT(storage_reader_parent != NULL);
39  }
40 
41  void operator ()(StorageStreamInfoReader *stream_reader_instance)
42  {
43  RTIBOOST_ASSERT(stream_reader_instance != NULL);
44  storage_reader_parent_->delete_stream_info_reader(
45  stream_reader_instance);
46  }
47 
48 private:
49  StorageReader *storage_reader_parent_;
50 };
51 
52 class StorageStreamInfoReaderForwarder :
53  public RTI_RecordingServiceStorageStreamInfoReader {
54 public:
55 
56  StorageStreamInfoReaderForwarder(
57  StorageStreamInfoReader *stream_reader,
58  StorageReader *storage_reader_parent)
59  : storage_stream_reader_(
60  stream_reader,
61  StorageStreamInfoReaderDeleter(storage_reader_parent))
62  {
63  read = StorageStreamInfoReaderForwarder::read_fwd;
64  return_loan = StorageStreamInfoReaderForwarder::return_loan_fwd;
65  get_service_start_time =
66  StorageStreamInfoReaderForwarder::get_service_start_time_fwd;
67  get_service_stop_time =
68  StorageStreamInfoReaderForwarder::get_service_stop_time_fwd;
69  finished = StorageStreamInfoReaderForwarder::finished_fwd;
70  reset = StorageStreamInfoReaderForwarder::reset_fwd;
71  stream_reader_data = this;
72  }
73 
74  ~StorageStreamInfoReaderForwarder()
75  {
76  }
77 
78 
79  static void read_fwd(
80  void *stream_reader_data,
81  RTI_RoutingServiceStreamInfo ***stream_info_array,
82  int *array_length,
83  const struct RTI_RecordingServiceSelectorState *native_selector)
84  {
85  try {
86  StorageStreamInfoReaderForwarder *forwarder =
87  static_cast<StorageStreamInfoReaderForwarder *>(
88  stream_reader_data);
89  forwarder->storage_stream_reader_->read(
90  forwarder->sample_seq_,
91  SelectorState(*native_selector));
92 
93  *array_length = forwarder->sample_seq_.size();
94  if (*array_length > 0) {
95  forwarder->native_sample_seq_.resize(*array_length);
96  for (size_t i = 0; i < forwarder->sample_seq_.size(); i++) {
97  forwarder->native_sample_seq_[i] =
98  &(forwarder->sample_seq_[i]->native());
99  }
100  *stream_info_array =
101  reinterpret_cast<RTI_RoutingServiceStreamInfo **>(
102  forwarder->native_sample_seq_.data());
103  }
104  } catch (const std::exception& ex) {
105  RTILog_printContextAndMsg(
106  RTI_LOG_BIT_EXCEPTION,
107  RTI_FUNCTION_NAME,
108  &RTI_LOG_ANY_s,
109  ex.what());
110  } catch (...) {
111  RTILog_printContextAndMsg(
112  RTI_LOG_BIT_EXCEPTION,
113  RTI_FUNCTION_NAME,
114  &RTI_LOG_ANY_s,
115  "unknown exception");
116  }
117  }
118 
119  static void return_loan_fwd(
120  void *stream_reader_data,
121  struct RTI_RoutingServiceStreamInfo **stream_info_array,
122  int array_length)
123  {
124  RTIOsapiUtility_unusedParameter(stream_info_array);
125  RTIOsapiUtility_unusedParameter(array_length);
126 
127  try {
128  StorageStreamInfoReaderForwarder *forwarder =
129  static_cast<StorageStreamInfoReaderForwarder *>(
130  stream_reader_data);
131  // Deleting what's inside the vectors (dynamic data objects) and any
132  // related objects is responsability of the implementation
133  forwarder->storage_stream_reader_->return_loan(
134  forwarder->sample_seq_);
135  // Clear our internal containers
136  forwarder->sample_seq_.clear();
137  forwarder->native_sample_seq_.clear();
138  } catch (const std::exception& ex) {
139  RTILog_printContextAndMsg(
140  RTI_LOG_BIT_EXCEPTION,
141  RTI_FUNCTION_NAME,
142  &RTI_LOG_ANY_s,
143  ex.what());
144  } catch (...) {
145  RTILog_printContextAndMsg(
146  RTI_LOG_BIT_EXCEPTION,
147  RTI_FUNCTION_NAME,
148  &RTI_LOG_ANY_s,
149  "unknown exception");
150  }
151  }
152 
153  static long long get_service_start_time_fwd(void *stream_reader_data)
154  {
155  try {
156  StorageStreamInfoReaderForwarder *forwarder =
157  static_cast<StorageStreamInfoReaderForwarder *>(
158  stream_reader_data);
159  return (long long)
160  forwarder->storage_stream_reader_->service_start_time();
161  } catch (const std::exception& ex) {
162  RTILog_printContextAndMsg(
163  RTI_LOG_BIT_EXCEPTION,
164  RTI_FUNCTION_NAME,
165  &RTI_LOG_ANY_s,
166  ex.what());
167  } catch (...) {
168  RTILog_printContextAndMsg(
169  RTI_LOG_BIT_EXCEPTION,
170  RTI_FUNCTION_NAME,
171  &RTI_LOG_ANY_s,
172  "unknown exception");
173  }
174  return 0;
175  }
176 
177  static long long get_service_stop_time_fwd(void *stream_reader_data)
178  {
179  try {
180  StorageStreamInfoReaderForwarder *forwarder =
181  static_cast<StorageStreamInfoReaderForwarder *>(
182  stream_reader_data);
183  return (long long)
184  forwarder->storage_stream_reader_->service_stop_time();
185  } catch (const std::exception& ex) {
186  RTILog_printContextAndMsg(
187  RTI_LOG_BIT_EXCEPTION,
188  RTI_FUNCTION_NAME,
189  &RTI_LOG_ANY_s,
190  ex.what());
191  } catch (...) {
192  RTILog_printContextAndMsg(
193  RTI_LOG_BIT_EXCEPTION,
194  RTI_FUNCTION_NAME,
195  &RTI_LOG_ANY_s,
196  "unknown exception");
197  }
198  return 0;
199  }
200 
201  static int finished_fwd(void *stream_reader_data)
202  {
203  try {
204  StorageStreamInfoReaderForwarder *forwarder =
205  static_cast<StorageStreamInfoReaderForwarder *>(
206  stream_reader_data);
207  return (forwarder->storage_stream_reader_->finished() ?
208  RTI_TRUE :
209  RTI_FALSE);
210  } catch (const std::exception& ex) {
211  RTILog_printContextAndMsg(
212  RTI_LOG_BIT_EXCEPTION,
213  RTI_FUNCTION_NAME,
214  &RTI_LOG_ANY_s,
215  ex.what());
216  } catch (...) {
217  RTILog_printContextAndMsg(
218  RTI_LOG_BIT_EXCEPTION,
219  RTI_FUNCTION_NAME,
220  &RTI_LOG_ANY_s,
221  "unknown exception");
222  }
223  return RTI_FALSE;
224  }
225 
226  static void reset_fwd(void *stream_reader_data)
227  {
228  try {
229  StorageStreamInfoReaderForwarder *forwarder =
230  static_cast<StorageStreamInfoReaderForwarder *>(
231  stream_reader_data);
232  forwarder->storage_stream_reader_->reset();
233  } catch (const std::exception& ex) {
234  RTILog_printContextAndMsg(
235  RTI_LOG_BIT_EXCEPTION,
236  RTI_FUNCTION_NAME,
237  &RTI_LOG_ANY_s,
238  ex.what());
239  } catch (...) {
240  RTILog_printContextAndMsg(
241  RTI_LOG_BIT_EXCEPTION,
242  RTI_FUNCTION_NAME,
243  &RTI_LOG_ANY_s,
244  "unknown exception");
245  }
246  }
247 
248  StorageStreamInfoReader * stream_reader()
249  {
250  return storage_stream_reader_.get();
251  }
252 
253 private:
254  rtiboost::shared_ptr<StorageStreamInfoReader> storage_stream_reader_;
255 
256  std::vector<rti::routing::StreamInfo *> sample_seq_;
257  std::vector<RTI_RoutingServiceStreamInfo *> native_sample_seq_;
258  std::vector<int32_t> domain_id_seq_;
259 
260 };
261 
262 } } } } // rti::recording::storage::detail
263 
264 #endif // RTI_RECORDING_STORAGE_DETAIL_STORAGE_DISC_STREAM_READER_FORWARDER_HPP_

RTI Recording Service Version 6.0.1 Copyright © Sun Nov 17 2019 Real-Time Innovations, Inc