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

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