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