RTI Recording Service Version 7.7.0
StorageStreamWriterForwarder.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_STREAM_WRITER_FORWARDER_HPP_
12#define RTI_RECORDING_STORAGE_DETAIL_STORAGE_STREAM_WRITER_FORWARDER_HPP_
13
14#include <map>
15#include <string>
16
17#include "log/log_common.h"
18#include "recordingservice/recordingservice_storagewriter.h"
19
20#include <memory>
21#include "rti/routing/detail/ForwarderUtils.hpp"
22
23#include "rti/recording/storage/StorageStreamWriter.hpp"
24
25namespace rti { namespace recording { namespace storage { namespace detail {
26
33public:
34 StorageStreamWriterDeleter(StorageWriter *storage_writer_parent)
35 : storage_writer_parent_(storage_writer_parent)
36 {
37 RTI_CHECK_PRECONDITION(storage_writer_parent != NULL);
38 }
39
40 void operator ()(StorageStreamWriter *stream_writer_instance)
41 {
42 if (stream_writer_instance != NULL) {
43 storage_writer_parent_->delete_stream_writer(
44 stream_writer_instance);
45 }
46 }
47
48private:
49 StorageWriter *storage_writer_parent_;
50};
51
52class StorageStreamWriterForwarder :
53 public RTI_RecordingServiceStorageStreamWriter {
54public:
55
56 StorageStreamWriterForwarder(
57 StorageStreamWriter *stream_writer,
58 StorageWriter *storage_writer_parent)
59 : storage_stream_writer_(
60 stream_writer,
61 StorageStreamWriterDeleter(storage_writer_parent))
62 {
63 store = StorageStreamWriterForwarder::store_fwd;
64 stream_writer_data = this;
65 }
66
67 ~StorageStreamWriterForwarder()
68 {
69 }
70
71 static void store_fwd(
72 void *stream_writer_data,
73 const RTI_RoutingServiceSample *samples,
74 const RTI_RoutingServiceSampleInfo *sample_infos,
75 const int count)
76 {
77 try {
78 StorageStreamWriterForwarder *forwarder =
79 static_cast<StorageStreamWriterForwarder *>(
80 stream_writer_data);
81 // Fill in internal vector with incoming samples
82 forwarder->sample_seq_.assign(samples, samples + count);
83 // Fill in internal vector with incoming sample infos, the sample
84 // info array is optional so check for validity before doing
85 // anything
86 if (sample_infos != NULL) {
87 forwarder->info_seq_.assign(sample_infos, sample_infos + count);
88 }
89 // Forward the call to the StorageStreamWriter implementation
90 forwarder->storage_stream_writer_->store(
91 forwarder->sample_seq_,
92 forwarder->info_seq_);
93 } catch (const std::exception& ex) {
94 RecorderPrint_exception(
95 &RTI_LOG_ANY_s,
96 ex.what());
97 } catch (...) {
98 RecorderPrint_exception(
99 &RTI_LOG_ANY_s,
100 "unknown exception");
101 }
102 }
103
104 StorageStreamWriter * stream_writer()
105 {
106 return storage_stream_writer_.get();
107 }
108
109private:
110 std::shared_ptr<StorageStreamWriter> storage_stream_writer_;
111
112 std::vector<StorageStreamWriter::SamplePtr> sample_seq_;
113 std::vector<StorageStreamWriter::InfoPtr> info_seq_;
114};
115
126template<typename NativeStreamWriterType, typename NativeStoredType>
127class StorageGenericStreamWriterForwarder : public NativeStreamWriterType {
128public:
129
131 StorageStreamWriter *stream_writer,
132 StorageWriter *storage_writer_parent)
133 : storage_stream_writer_(
134 stream_writer,
135 StorageStreamWriterDeleter(storage_writer_parent))
136 {
137 }
138
140 {
141 }
142
143 static void store_fwd(
144 void *stream_writer_data,
145 const NativeStoredType **samples,
146 const RTI_RoutingServiceSampleInfo *sample_infos,
147 const int count)
148 {
149 try {
152 stream_writer_data);
153 /*
154 * In the case of the generic stream writer forwarder, used for the
155 * built-in DDS discovery topics, we are not guaranteed that the
156 * stream writer will not be null. This can happen if the user
157 * doesn't override the default implementations, which return null.
158 * The user may not have interest in recording one or any of the
159 * topics. We should account for that case.
160 */
161 if (forwarder->storage_stream_writer_.get() == NULL) {
162 return;
163 }
164 // Fill in internal vector with incoming samples
165 StorageStreamWriter::SamplePtr *untyped_samples =
166 (StorageStreamWriter::SamplePtr *) samples;
167 forwarder->sample_seq_.assign(
168 untyped_samples,
169 untyped_samples + count);
170 /*
171 * Fill in internal vector with incoming sample infos, the sample
172 * info array is optional so check for validity before doing
173 * anything
174 */
175 if (sample_infos != NULL) {
176 forwarder->info_seq_.assign(sample_infos, sample_infos + count);
177 }
178 // Forward the call to the StorageStreamWriter implementation
179 forwarder->storage_stream_writer_->store(
180 forwarder->sample_seq_,
181 forwarder->info_seq_);
182 } catch (const std::exception& ex) {
183 RecorderPrint_exception(
184 &RTI_LOG_ANY_s,
185 ex.what());
186 } catch (...) {
187 RecorderPrint_exception(
188 &RTI_LOG_ANY_s,
189 "unknown exception");
190 }
191 }
192
193 StorageStreamWriter * stream_writer()
194 {
195 return storage_stream_writer_.get();
196 }
197
198private:
199 std::shared_ptr<StorageStreamWriter> storage_stream_writer_;
200
201 std::vector<StorageStreamWriter::SamplePtr> sample_seq_;
202 std::vector<StorageStreamWriter::InfoPtr> info_seq_;
203
204};
205
206class StorageParticipantWriterForwarder :
208 RTI_RecordingServiceStorageParticipantWriter,
209 DDS_ParticipantBuiltinTopicData> {
210public:
211
212 StorageParticipantWriterForwarder(
213 StorageStreamWriter *stream_writer,
214 StorageWriter *storage_writer_parent) :
216 RTI_RecordingServiceStorageParticipantWriter,
217 DDS_ParticipantBuiltinTopicData>(
218 stream_writer,
219 storage_writer_parent)
220 {
221 store = store_fwd;
222 stream_writer_data = this;
223 }
224};
225
226class StoragePublicationWriterForwarder :
227 public StorageGenericStreamWriterForwarder<
228 RTI_RecordingServiceStoragePublicationWriter,
229 DDS_PublicationBuiltinTopicData> {
230public:
231
232 StoragePublicationWriterForwarder(
233 StorageStreamWriter *stream_writer,
234 StorageWriter *storage_writer_parent) :
235 StorageGenericStreamWriterForwarder<
236 RTI_RecordingServiceStoragePublicationWriter,
237 DDS_PublicationBuiltinTopicData>(
238 stream_writer,
239 storage_writer_parent)
240 {
241 store = store_fwd;
242 stream_writer_data = this;
243 }
244};
245
246class StorageSubscriptionWriterForwarder :
247 public StorageGenericStreamWriterForwarder<
248 RTI_RecordingServiceStorageSubscriptionWriter,
249 DDS_SubscriptionBuiltinTopicData> {
250public:
251
252 StorageSubscriptionWriterForwarder(
253 StorageStreamWriter *stream_writer,
254 StorageWriter *storage_writer_parent) :
255 StorageGenericStreamWriterForwarder<
256 RTI_RecordingServiceStorageSubscriptionWriter,
257 DDS_SubscriptionBuiltinTopicData>(
258 stream_writer,
259 storage_writer_parent)
260 {
261 store = store_fwd;
262 stream_writer_data = this;
263 }
264};
265
266} } } } // rti::recording::storage::detail
267
268#endif // RTI_RECORDING_STORAGE_DETAIL_STORAGE_STREAM_WRITER_FORWARDER_HPP_
Storage stream writer.
Definition: StorageStreamWriter.hpp:28
Storage writer.
Definition: StorageWriter.hpp:36
virtual void delete_stream_writer(StorageStreamWriter *writer)=0
RTI Recording Service calls this to delete a stream writer. This method should be able to work with a...
Definition: StorageStreamWriterForwarder.hpp:127
Definition: StorageStreamWriterForwarder.hpp:32
The RTI namespace.
Definition: RecordingServiceImpl.hpp:22