RTI Recording Service Version 7.7.0
StorageWriterForwarder.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_WRITER_FORWARDER_HPP_
12#define RTI_RECORDING_STORAGE_DETAIL_STORAGE_WRITER_FORWARDER_HPP_
13
14#include <map>
15#include <string>
16
17#include "log/log_common.h"
18#include "rti/routing/detail/ForwarderUtils.hpp"
19#include "rti/routing/ServiceProperty.hpp"
20
21#include "recordingservice/recordingservice_storagewriter.h"
22#include "rti/recording/storage/StorageDefs.hpp"
23#include "rti/recording/storage/detail/StorageStreamWriterForwarder.hpp"
24
25namespace rti { namespace recording { namespace storage { namespace detail {
26
27class StorageWriterForwarder : public RTI_RecordingServiceStorageWriter {
28public:
29
30 StorageWriterForwarder(StorageWriter *storage_writer) :
31 storage_writer_(storage_writer)
32 {
33 // User-data stream creation function
34 create_stream_writer = StorageWriterForwarder::create_stream_writer_fwd;
35 // Discovery stream creation functions
36 create_participant_writer =
37 StorageWriterForwarder::create_participant_writer_fwd;
38 create_publication_writer =
39 StorageWriterForwarder::create_publication_writer_fwd;
40 create_subscription_writer =
41 StorageWriterForwarder::create_subscription_writer_fwd;
42 // User-data stream deletion function
43 delete_stream_writer = StorageWriterForwarder::delete_stream_writer_fwd;
44 // Discovery stream deletion functions
45 delete_participant_writer =
46 StorageWriterForwarder::delete_participant_writer_fwd;
47 delete_publication_writer =
48 StorageWriterForwarder::delete_publication_writer_fwd;
49 delete_subscription_writer =
50 StorageWriterForwarder::delete_subscription_writer_fwd;
51 // Delete storage writer instance method
52 delete_instance = StorageWriterForwarder::delete_instance_fwd;
53
54 storage_writer_data = this;
55 }
56
57 ~StorageWriterForwarder()
58 {
59 }
60
61 static void delete_instance_fwd(
62 struct RTI_RecordingServiceStorageWriter *storage_writer)
63 {
64 try {
65 StorageWriterForwarder *forwarder =
66 static_cast<StorageWriterForwarder *>(storage_writer);
67 delete forwarder;
68 } catch (const std::exception& ex) {
69 RecorderPrint_exception(
70 &RTI_LOG_ANY_s,
71 ex.what());
72 } catch (...) {
73 RecorderPrint_exception(
74 &RTI_LOG_ANY_s,
75 "unknown exception");
76 }
77 }
78
79 static RTI_RecordingServiceStorageStreamWriter * create_stream_writer_fwd(
80 void *storage_writer,
81 const RTI_RoutingServiceStreamInfo *native_stream_info,
82 const RTI_RoutingServiceProperties *native_properties)
83 {
84 RTI_CHECK_PRECONDITION(!rti::recording::is_discovery_stream(
85 std::string(native_stream_info->stream_name)));
86 try {
87 StorageWriterForwarder *forwarder =
88 static_cast<StorageWriterForwarder *>(storage_writer);
89 rti::routing::StreamInfo stream_info(*native_stream_info);
90 rti::routing::PropertySet properties;
91 rti::routing::PropertyAdapter::add_properties_from_native(
92 properties,
93 native_properties);
94 StorageStreamWriterForwarder *stream_writer_forwarder =
95 new StorageStreamWriterForwarder(
96 forwarder->storage_writer_->create_stream_writer(
97 stream_info,
98 properties),
99 forwarder->storage_writer_.get());
100 return stream_writer_forwarder;
101 } catch (const std::exception& ex) {
102 RecorderPrint_exception(
103 &RTI_LOG_ANY_s,
104 ex.what());
105 } catch (...) {
106 RecorderPrint_exception(
107 &RTI_LOG_ANY_s,
108 "unknown exception");
109 }
110 return NULL;
111 }
112
113 static RTI_RecordingServiceStorageParticipantWriter *
114 create_participant_writer_fwd(void *storage_writer)
115 {
116 try {
117 StorageWriterForwarder *forwarder =
118 static_cast<StorageWriterForwarder *>(storage_writer);
119 StorageParticipantWriterForwarder *stream_writer_forwarder =
120 new StorageParticipantWriterForwarder(
121 forwarder->storage_writer_->create_participant_writer(),
122 forwarder->storage_writer_.get());
123 return stream_writer_forwarder;
124 } catch (const std::exception& ex) {
125 RecorderPrint_exception(
126 &RTI_LOG_ANY_s,
127 ex.what());
128 } catch (...) {
129 RecorderPrint_exception(
130 &RTI_LOG_ANY_s,
131 "unknown exception");
132 }
133 return NULL;
134 }
135
136 static RTI_RecordingServiceStoragePublicationWriter *
137 create_publication_writer_fwd(void *storage_writer)
138 {
139 try {
140 StorageWriterForwarder *forwarder =
141 static_cast<StorageWriterForwarder *>(storage_writer);
142 StoragePublicationWriterForwarder *stream_writer_forwarder =
143 new StoragePublicationWriterForwarder(
144 forwarder->storage_writer_->create_publication_writer(),
145 forwarder->storage_writer_.get());
146 return stream_writer_forwarder;
147 } catch (const std::exception& ex) {
148 RecorderPrint_exception(
149 &RTI_LOG_ANY_s,
150 ex.what());
151 } catch (...) {
152 RecorderPrint_exception(
153 &RTI_LOG_ANY_s,
154 "unknown exception");
155 }
156 return NULL;
157 }
158
159 static RTI_RecordingServiceStorageSubscriptionWriter *
160 create_subscription_writer_fwd(void *storage_writer)
161 {
162 try {
163 StorageWriterForwarder *forwarder =
164 static_cast<StorageWriterForwarder *>(storage_writer);
165 StorageSubscriptionWriterForwarder *stream_writer_forwarder =
166 new StorageSubscriptionWriterForwarder(
167 forwarder->storage_writer_->create_subscription_writer(),
168 forwarder->storage_writer_.get());
169 return stream_writer_forwarder;
170 } catch (const std::exception& ex) {
171 RecorderPrint_exception(
172 &RTI_LOG_ANY_s,
173 ex.what());
174 } catch (...) {
175 RecorderPrint_exception(
176 &RTI_LOG_ANY_s,
177 "unknown exception");
178 }
179 return NULL;
180 }
181
182 static void delete_stream_writer_fwd(
183 void *,
184 RTI_RecordingServiceStorageStreamWriter *storage_stream_writer)
185 {
186 try {
187 StorageStreamWriterForwarder *stream_writer_forwarder =
188 static_cast<StorageStreamWriterForwarder *>(
189 storage_stream_writer);
190 delete stream_writer_forwarder;
191 } catch (const std::exception& ex) {
192 RecorderPrint_exception(
193 &RTI_LOG_ANY_s,
194 ex.what());
195 } catch (...) {
196 RecorderPrint_exception(
197 &RTI_LOG_ANY_s,
198 "unknown exception");
199 }
200 }
201
202 static void delete_participant_writer_fwd(
203 void *,
204 RTI_RecordingServiceStorageParticipantWriter *stream_writer)
205 {
206 try {
207 StorageParticipantWriterForwarder *forwarder =
208 static_cast<StorageParticipantWriterForwarder *>(
209 stream_writer);
210 delete forwarder;
211 } catch (const std::exception& ex) {
212 RecorderPrint_exception(
213 &RTI_LOG_ANY_s,
214 ex.what());
215 } catch (...) {
216 RecorderPrint_exception(
217 &RTI_LOG_ANY_s,
218 "unknown exception");
219 }
220 }
221
222 static void delete_publication_writer_fwd(
223 void *,
224 RTI_RecordingServiceStoragePublicationWriter *stream_writer)
225 {
226 try {
227 StoragePublicationWriterForwarder *forwarder =
228 static_cast<StoragePublicationWriterForwarder *>(
229 stream_writer);
230 delete forwarder;
231 } catch (const std::exception& ex) {
232 RecorderPrint_exception(
233 &RTI_LOG_ANY_s,
234 ex.what());
235 } catch (...) {
236 RecorderPrint_exception(
237 &RTI_LOG_ANY_s,
238 "unknown exception");
239 }
240 }
241
242 static void delete_subscription_writer_fwd(
243 void *,
244 RTI_RecordingServiceStorageSubscriptionWriter *stream_writer)
245 {
246 try {
247 StorageSubscriptionWriterForwarder *forwarder =
248 static_cast<StorageSubscriptionWriterForwarder *>(
249 stream_writer);
250 delete forwarder;
251 } catch (const std::exception& ex) {
252 RecorderPrint_exception(
253 &RTI_LOG_ANY_s,
254 ex.what());
255 } catch (...) {
256 RecorderPrint_exception(
257 &RTI_LOG_ANY_s,
258 "unknown exception");
259 }
260 }
261
262private:
263
264 std::shared_ptr<StorageWriter> storage_writer_;
265
266};
267
268} } } } // rti::recording::storage::namespace
269
270#endif // RTI_RECORDING_STORAGE_DETAIL_STORAGE_WRITER_FORWARDER_HPP_
The RTI namespace.
Definition: RecordingServiceImpl.hpp:22