RTI Recording Service  Version 6.0.0
 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_FUNCTION_NAME,
107  &RTI_LOG_ANY_s,
108  ex.what());
109  } catch (...) {
110  RTILog_printContextAndMsg(
111  RTI_FUNCTION_NAME,
112  &RTI_LOG_ANY_s,
113  "unknown exception");
114  }
115  }
116 
117  static void return_loan_fwd(
118  void *stream_reader_data,
119  struct RTI_RoutingServiceStreamInfo **stream_info_array,
120  int array_length)
121  {
122  RTIOsapiUtility_unusedParameter(stream_info_array);
123  RTIOsapiUtility_unusedParameter(array_length);
124 
125  try {
126  StorageStreamInfoReaderForwarder *forwarder =
127  static_cast<StorageStreamInfoReaderForwarder *>(
128  stream_reader_data);
129  // Deleting what's inside the vectors (dynamic data objects) and any
130  // related objects is responsability of the implementation
131  forwarder->storage_stream_reader_->return_loan(
132  forwarder->sample_seq_);
133  // Clear our internal containers
134  forwarder->sample_seq_.clear();
135  forwarder->native_sample_seq_.clear();
136  } catch (const std::exception& ex) {
137  RTILog_printContextAndMsg(
138  RTI_FUNCTION_NAME,
139  &RTI_LOG_ANY_s,
140  ex.what());
141  } catch (...) {
142  RTILog_printContextAndMsg(
143  RTI_FUNCTION_NAME,
144  &RTI_LOG_ANY_s,
145  "unknown exception");
146  }
147  }
148 
149  static long long get_service_start_time_fwd(void *stream_reader_data)
150  {
151  try {
152  StorageStreamInfoReaderForwarder *forwarder =
153  static_cast<StorageStreamInfoReaderForwarder *>(
154  stream_reader_data);
155  return (long long)
156  forwarder->storage_stream_reader_->service_start_time();
157  } catch (const std::exception& ex) {
158  RTILog_printContextAndMsg(
159  RTI_FUNCTION_NAME,
160  &RTI_LOG_ANY_s,
161  ex.what());
162  } catch (...) {
163  RTILog_printContextAndMsg(
164  RTI_FUNCTION_NAME,
165  &RTI_LOG_ANY_s,
166  "unknown exception");
167  }
168  return 0;
169  }
170 
171  static long long get_service_stop_time_fwd(void *stream_reader_data)
172  {
173  try {
174  StorageStreamInfoReaderForwarder *forwarder =
175  static_cast<StorageStreamInfoReaderForwarder *>(
176  stream_reader_data);
177  return (long long)
178  forwarder->storage_stream_reader_->service_stop_time();
179  } catch (const std::exception& ex) {
180  RTILog_printContextAndMsg(
181  RTI_FUNCTION_NAME,
182  &RTI_LOG_ANY_s,
183  ex.what());
184  } catch (...) {
185  RTILog_printContextAndMsg(
186  RTI_FUNCTION_NAME,
187  &RTI_LOG_ANY_s,
188  "unknown exception");
189  }
190  return 0;
191  }
192 
193  static int finished_fwd(void *stream_reader_data)
194  {
195  try {
196  StorageStreamInfoReaderForwarder *forwarder =
197  static_cast<StorageStreamInfoReaderForwarder *>(
198  stream_reader_data);
199  return (forwarder->storage_stream_reader_->finished() ?
200  RTI_TRUE :
201  RTI_FALSE);
202  } catch (const std::exception& ex) {
203  RTILog_printContextAndMsg(
204  RTI_FUNCTION_NAME,
205  &RTI_LOG_ANY_s,
206  ex.what());
207  } catch (...) {
208  RTILog_printContextAndMsg(
209  RTI_FUNCTION_NAME,
210  &RTI_LOG_ANY_s,
211  "unknown exception");
212  }
213  return RTI_FALSE;
214  }
215 
216  static void reset_fwd(void *stream_reader_data)
217  {
218  try {
219  StorageStreamInfoReaderForwarder *forwarder =
220  static_cast<StorageStreamInfoReaderForwarder *>(
221  stream_reader_data);
222  forwarder->storage_stream_reader_->reset();
223  } catch (const std::exception& ex) {
224  RTILog_printContextAndMsg(
225  RTI_FUNCTION_NAME,
226  &RTI_LOG_ANY_s,
227  ex.what());
228  } catch (...) {
229  RTILog_printContextAndMsg(
230  RTI_FUNCTION_NAME,
231  &RTI_LOG_ANY_s,
232  "unknown exception");
233  }
234  }
235 
236  StorageStreamInfoReader * stream_reader()
237  {
238  return storage_stream_reader_.get();
239  }
240 
241 private:
242  rtiboost::shared_ptr<StorageStreamInfoReader> storage_stream_reader_;
243 
244  std::vector<rti::routing::StreamInfo *> sample_seq_;
245  std::vector<RTI_RoutingServiceStreamInfo *> native_sample_seq_;
246  std::vector<int32_t> domain_id_seq_;
247 
248 };
249 
250 } } } } // rti::recording::storage::detail
251 
252 #endif // RTI_RECORDING_STORAGE_DETAIL_STORAGE_DISC_STREAM_READER_FORWARDER_HPP_

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