RTI Recording Service  Version 6.0.1
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Groups
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 
25 namespace rti { namespace recording { namespace storage { namespace detail {
26 
27 class StorageWriterForwarder : public RTI_RecordingServiceStorageWriter {
28 public:
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  RTILog_printContextAndMsg(
70  RTI_LOG_BIT_EXCEPTION,
71  RTI_FUNCTION_NAME,
72  &RTI_LOG_ANY_s,
73  ex.what());
74  } catch (...) {
75  RTILog_printContextAndMsg(
76  RTI_LOG_BIT_EXCEPTION,
77  RTI_FUNCTION_NAME,
78  &RTI_LOG_ANY_s,
79  "unknown exception");
80  }
81  }
82 
83  static RTI_RecordingServiceStorageStreamWriter * create_stream_writer_fwd(
84  void *storage_writer,
85  const RTI_RoutingServiceStreamInfo *native_stream_info,
86  const RTI_RoutingServiceProperties *native_properties)
87  {
88  RTIBOOST_ASSERT(!rti::recording::is_discovery_stream(
89  std::string(native_stream_info->stream_name)));
90  try {
91  StorageWriterForwarder *forwarder =
92  static_cast<StorageWriterForwarder *>(storage_writer);
93  rti::routing::StreamInfo stream_info(*native_stream_info);
94  rti::routing::PropertySet properties;
95  rti::routing::PropertyAdapter::add_properties_from_native(
96  properties,
97  native_properties);
98  StorageStreamWriterForwarder *stream_writer_forwarder =
99  new StorageStreamWriterForwarder(
100  forwarder->storage_writer_->create_stream_writer(
101  stream_info,
102  properties),
103  forwarder->storage_writer_.get());
104  return stream_writer_forwarder;
105  } catch (const std::exception& ex) {
106  RTILog_printContextAndMsg(
107  RTI_LOG_BIT_EXCEPTION,
108  RTI_FUNCTION_NAME,
109  &RTI_LOG_ANY_s,
110  ex.what());
111  } catch (...) {
112  RTILog_printContextAndMsg(
113  RTI_LOG_BIT_EXCEPTION,
114  RTI_FUNCTION_NAME,
115  &RTI_LOG_ANY_s,
116  "unknown exception");
117  }
118  return NULL;
119  }
120 
121  static RTI_RecordingServiceStorageParticipantWriter *
122  create_participant_writer_fwd(void *storage_writer)
123  {
124  try {
125  StorageWriterForwarder *forwarder =
126  static_cast<StorageWriterForwarder *>(storage_writer);
127  StorageParticipantWriterForwarder *stream_writer_forwarder =
128  new StorageParticipantWriterForwarder(
129  forwarder->storage_writer_->create_participant_writer(),
130  forwarder->storage_writer_.get());
131  return stream_writer_forwarder;
132  } catch (const std::exception& ex) {
133  RTILog_printContextAndMsg(
134  RTI_LOG_BIT_EXCEPTION,
135  RTI_FUNCTION_NAME,
136  &RTI_LOG_ANY_s,
137  ex.what());
138  } catch (...) {
139  RTILog_printContextAndMsg(
140  RTI_LOG_BIT_EXCEPTION,
141  RTI_FUNCTION_NAME,
142  &RTI_LOG_ANY_s,
143  "unknown exception");
144  }
145  return NULL;
146  }
147 
148  static RTI_RecordingServiceStoragePublicationWriter *
149  create_publication_writer_fwd(void *storage_writer)
150  {
151  try {
152  StorageWriterForwarder *forwarder =
153  static_cast<StorageWriterForwarder *>(storage_writer);
154  StoragePublicationWriterForwarder *stream_writer_forwarder =
155  new StoragePublicationWriterForwarder(
156  forwarder->storage_writer_->create_publication_writer(),
157  forwarder->storage_writer_.get());
158  return stream_writer_forwarder;
159  } catch (const std::exception& ex) {
160  RTILog_printContextAndMsg(
161  RTI_LOG_BIT_EXCEPTION,
162  RTI_FUNCTION_NAME,
163  &RTI_LOG_ANY_s,
164  ex.what());
165  } catch (...) {
166  RTILog_printContextAndMsg(
167  RTI_LOG_BIT_EXCEPTION,
168  RTI_FUNCTION_NAME,
169  &RTI_LOG_ANY_s,
170  "unknown exception");
171  }
172  return NULL;
173  }
174 
175  static RTI_RecordingServiceStorageSubscriptionWriter *
176  create_subscription_writer_fwd(void *storage_writer)
177  {
178  try {
179  StorageWriterForwarder *forwarder =
180  static_cast<StorageWriterForwarder *>(storage_writer);
181  StorageSubscriptionWriterForwarder *stream_writer_forwarder =
182  new StorageSubscriptionWriterForwarder(
183  forwarder->storage_writer_->create_subscription_writer(),
184  forwarder->storage_writer_.get());
185  return stream_writer_forwarder;
186  } catch (const std::exception& ex) {
187  RTILog_printContextAndMsg(
188  RTI_LOG_BIT_EXCEPTION,
189  RTI_FUNCTION_NAME,
190  &RTI_LOG_ANY_s,
191  ex.what());
192  } catch (...) {
193  RTILog_printContextAndMsg(
194  RTI_LOG_BIT_EXCEPTION,
195  RTI_FUNCTION_NAME,
196  &RTI_LOG_ANY_s,
197  "unknown exception");
198  }
199  return NULL;
200  }
201 
202  static void delete_stream_writer_fwd(
203  void *,
204  RTI_RecordingServiceStorageStreamWriter *storage_stream_writer)
205  {
206  try {
207  StorageStreamWriterForwarder *stream_writer_forwarder =
208  static_cast<StorageStreamWriterForwarder *>(
209  storage_stream_writer);
210  delete stream_writer_forwarder;
211  } catch (const std::exception& ex) {
212  RTILog_printContextAndMsg(
213  RTI_LOG_BIT_EXCEPTION,
214  RTI_FUNCTION_NAME,
215  &RTI_LOG_ANY_s,
216  ex.what());
217  } catch (...) {
218  RTILog_printContextAndMsg(
219  RTI_LOG_BIT_EXCEPTION,
220  RTI_FUNCTION_NAME,
221  &RTI_LOG_ANY_s,
222  "unknown exception");
223  }
224  }
225 
226  static void delete_participant_writer_fwd(
227  void *,
228  RTI_RecordingServiceStorageParticipantWriter *stream_writer)
229  {
230  try {
231  StorageParticipantWriterForwarder *forwarder =
232  static_cast<StorageParticipantWriterForwarder *>(
233  stream_writer);
234  delete forwarder;
235  } catch (const std::exception& ex) {
236  RTILog_printContextAndMsg(
237  RTI_LOG_BIT_EXCEPTION,
238  RTI_FUNCTION_NAME,
239  &RTI_LOG_ANY_s,
240  ex.what());
241  } catch (...) {
242  RTILog_printContextAndMsg(
243  RTI_LOG_BIT_EXCEPTION,
244  RTI_FUNCTION_NAME,
245  &RTI_LOG_ANY_s,
246  "unknown exception");
247  }
248  }
249 
250  static void delete_publication_writer_fwd(
251  void *,
252  RTI_RecordingServiceStoragePublicationWriter *stream_writer)
253  {
254  try {
255  StoragePublicationWriterForwarder *forwarder =
256  static_cast<StoragePublicationWriterForwarder *>(
257  stream_writer);
258  delete forwarder;
259  } catch (const std::exception& ex) {
260  RTILog_printContextAndMsg(
261  RTI_LOG_BIT_EXCEPTION,
262  RTI_FUNCTION_NAME,
263  &RTI_LOG_ANY_s,
264  ex.what());
265  } catch (...) {
266  RTILog_printContextAndMsg(
267  RTI_LOG_BIT_EXCEPTION,
268  RTI_FUNCTION_NAME,
269  &RTI_LOG_ANY_s,
270  "unknown exception");
271  }
272  }
273 
274  static void delete_subscription_writer_fwd(
275  void *,
276  RTI_RecordingServiceStorageSubscriptionWriter *stream_writer)
277  {
278  try {
279  StorageSubscriptionWriterForwarder *forwarder =
280  static_cast<StorageSubscriptionWriterForwarder *>(
281  stream_writer);
282  delete forwarder;
283  } catch (const std::exception& ex) {
284  RTILog_printContextAndMsg(
285  RTI_LOG_BIT_EXCEPTION,
286  RTI_FUNCTION_NAME,
287  &RTI_LOG_ANY_s,
288  ex.what());
289  } catch (...) {
290  RTILog_printContextAndMsg(
291  RTI_LOG_BIT_EXCEPTION,
292  RTI_FUNCTION_NAME,
293  &RTI_LOG_ANY_s,
294  "unknown exception");
295  }
296  }
297 
298 private:
299 
300  rtiboost::shared_ptr<StorageWriter> storage_writer_;
301 
302 };
303 
304 } } } } // rti::recording::storage::namespace
305 
306 #endif // RTI_RECORDING_STORAGE_DETAIL_STORAGE_WRITER_FORWARDER_HPP_

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