RTI Recording Service  Version 6.0.1
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Groups
StorageDefs.hpp
1 /*
2  * (c) Copyright, Real-Time Innovations, 2018-.
3  * All rights reserved.
4  * No duplications, whole or partial, manual or electronic, may be made
5  * without express written permission. Any such copies, or
6  * revisions thereof, must display this notice unaltered.
7  * This code contains trade secrets of Real-Time Innovations, Inc.
8  */
9 
10 #ifndef HPP_RTI_RECORDING_STORAGE_STORAGEDEFS_HPP_
11 #define HPP_RTI_RECORDING_STORAGE_STORAGEDEFS_HPP_
12 
13 #ifndef dds_c_builtin_h
14 #include "dds_c/dds_c_builtin.h"
15 #endif
16 
17 #include <dds/core/Exception.hpp>
18 #include "rtiboost/smart_ptr/shared_ptr.hpp"
19 #include "rti/routing/PropertySet.hpp"
20 
21 #include "recordingservice/recordingservice_storagereader.h"
22 #include "recordingservice/recordingservice_storagewriter.h"
23 
24 namespace rti { namespace recording {
25 
26 // Writer-related defines
27 typedef rtiboost::shared_ptr<RTI_RecordingServiceStorageWriter>
28  StorageWriterSharedPtr;
29 typedef rtiboost::shared_ptr<RTI_RecordingServiceStorageStreamWriter>
30  StorageStreamWriterSharedPtr;
31 typedef rtiboost::shared_ptr<RTI_RecordingServiceStorageParticipantWriter>
32  StorageParticipantWriterSharedPtr;
33 typedef rtiboost::shared_ptr<RTI_RecordingServiceStoragePublicationWriter>
34  StoragePublicationWriterSharedPtr;
35 typedef rtiboost::shared_ptr<RTI_RecordingServiceStorageSubscriptionWriter>
36  StorageSubscriptionWriterSharedPtr;
37 
38 // Reader-related defines
39 typedef rtiboost::shared_ptr<RTI_RecordingServiceStorageReader>
40  StorageReaderSharedPtr;
41 typedef rtiboost::shared_ptr<RTI_RecordingServiceStorageStreamReader>
42  StorageStreamReaderSharedPtr;
43 typedef rtiboost::shared_ptr<RTI_RecordingServiceStorageStreamInfoReader>
44  StorageStreamInfoReaderSharedPtr;
45 
46 /*
47  * Helper classes to be used with the pointer definitions above, to create the
48  * smart pointers and use this class as a deleter (pointing to the () operator)
49  */
50 
51 class NativeStorageStreamWriterDeleter {
52 public:
53  NativeStorageStreamWriterDeleter(
54  RTI_RecordingServiceStorageWriter *storage_writer_parent)
55  : storage_writer_parent_(storage_writer_parent)
56  {
57  RTIBOOST_ASSERT(storage_writer_parent != NULL);
58  }
59 
60  void operator ()(RTI_RecordingServiceStorageStreamWriter *instance)
61  {
62  if (instance != NULL) {
63  storage_writer_parent_->delete_stream_writer(
64  storage_writer_parent_,
65  instance);
66  }
67  }
68 
69  void operator ()(RTI_RecordingServiceStorageParticipantWriter *instance)
70  {
71  // The delete participant writer operation is not required, better be
72  // safe than sorry
73  if (instance != NULL
74  && storage_writer_parent_->delete_participant_writer != NULL) {
75  storage_writer_parent_->delete_participant_writer(
76  storage_writer_parent_,
77  instance);
78  }
79  }
80 
81  void operator ()(RTI_RecordingServiceStoragePublicationWriter *instance)
82  {
83  // The delete publication writer operation is not required, better be
84  // safe than sorry
85  if (instance != NULL
86  && storage_writer_parent_->delete_publication_writer != NULL) {
87  storage_writer_parent_->delete_publication_writer(
88  storage_writer_parent_,
89  instance);
90  }
91  }
92 
93  void operator ()(RTI_RecordingServiceStorageSubscriptionWriter *instance)
94  {
95  // The delete subscription writer operation is not required, better be
96  // safe than sorry
97  if (instance != NULL
98  && storage_writer_parent_->delete_subscription_writer != NULL) {
99  storage_writer_parent_->delete_subscription_writer(
100  storage_writer_parent_,
101  instance);
102  }
103  }
104 
105 private:
106  RTI_RecordingServiceStorageWriter *storage_writer_parent_;
107 };
108 
109 class NativeStorageStreamInfoReaderDeleter {
110 public:
111  NativeStorageStreamInfoReaderDeleter(
112  RTI_RecordingServiceStorageReader *storage_reader_parent)
113  : storage_reader_parent_(storage_reader_parent)
114  {
115  RTIBOOST_ASSERT(storage_reader_parent != NULL);
116  }
117 
118  void operator ()(RTI_RecordingServiceStorageStreamInfoReader *instance)
119  {
120  if (instance != NULL) {
121  storage_reader_parent_->delete_stream_info_reader(
122  storage_reader_parent_,
123  instance);
124  }
125  }
126 
127 private:
128  RTI_RecordingServiceStorageReader *storage_reader_parent_;
129 };
130 
131 class NativeStorageStreamReaderDeleter {
132 public:
133  NativeStorageStreamReaderDeleter(
134  RTI_RecordingServiceStorageReader *storage_reader_parent)
135  : storage_reader_parent_(storage_reader_parent)
136  {
137  RTIBOOST_ASSERT(storage_reader_parent != NULL);
138  }
139 
140  void operator ()(RTI_RecordingServiceStorageStreamReader *instance)
141  {
142  if (instance != NULL) {
143  storage_reader_parent_->delete_stream_reader(
144  storage_reader_parent_,
145  instance);
146  }
147  }
148 
149 private:
150  RTI_RecordingServiceStorageReader *storage_reader_parent_;
151 };
152 
153 inline bool is_discovery_stream(const std::string& stream_name)
154 {
155  if (stream_name.compare(DDS_PARTICIPANT_TOPIC_NAME) == 0
156  || stream_name.compare(DDS_PUBLICATION_TOPIC_NAME) == 0
157  || stream_name.compare(DDS_SUBSCRIPTION_TOPIC_NAME) == 0) {
158  return true;
159  }
160  return false;
161 }
162 
163 inline std::string domain_id_property_name()
164 {
165  return RTI_RECORDING_SERVICE_DOMAIN_ID_PROPERTY_NAME;
166 }
167 
168 inline std::string start_timestamp_property_name()
169 {
170  return RTI_RECORDING_SERVICE_START_TIMESTAMP_PROPERTY_NAME;
171 }
172 
173 inline std::string end_timestamp_property_name()
174 {
175  return RTI_RECORDING_SERVICE_END_TIMESTAMP_PROPERTY_NAME;
176 }
177 
178 template <typename T>
179 inline T get_from_properties(
180  const rti::routing::PropertySet& properties,
181  const std::string& property_name)
182 {
183  rti::routing::PropertySet::const_iterator found =
184  properties.find(property_name);
185  if (found == properties.end()) {
186  throw dds::core::Error(
187  "!found property with name=" + property_name);
188  }
189  T value;
190  std::stringstream str_stream(found->second);
191  str_stream >> value;
192  if (str_stream.fail()) {
193  throw dds::core::Error(
194  "!parse value from property with name=" + property_name);
195  }
196  return value;
197 }
198 
199 template <typename T>
200 inline void add_to_properties(
201  rti::routing::PropertySet& properties,
202  const std::string& property_name,
203  const T value)
204 {
205  rti::routing::PropertySet::const_iterator found =
206  properties.find(property_name);
207  if (found != properties.end()) {
208  return;
209  }
210  std::stringstream str_stream;
211  str_stream << value;
212  if (str_stream.fail()) {
213  throw dds::core::Error(
214  "!add value for property with name=" + property_name);
215  }
216  properties[property_name] = str_stream.str();
217 }
218 
219 
220 } } /* namespace rti::recording */
221 
222 #endif /* HPP_RTI_RECORDING_STORAGE_STORAGEDEFS_HPP_ */

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