RTI Recording Service Version 7.7.0
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#include <sstream>
14#include <memory>
15
16#ifndef dds_c_builtin_h
17#include "dds_c/dds_c_builtin.h"
18#endif
19
20#include <rti/core/Exception.hpp>
21#include "rti/recording/PropertySet.hpp"
22
23#include "recordingservice/recordingservice_storagereader.h"
24#include "recordingservice/recordingservice_storagewriter.h"
25
26namespace rti { namespace recording {
27
28// Writer-related defines
29
30typedef std::shared_ptr<RTI_RecordingServiceStorageWriter>
31 StorageWriterSharedPtr;
32typedef std::shared_ptr<RTI_RecordingServiceStorageStreamWriter>
33 StorageStreamWriterSharedPtr;
34typedef std::shared_ptr<RTI_RecordingServiceStorageParticipantWriter>
35 StorageParticipantWriterSharedPtr;
36typedef std::shared_ptr<RTI_RecordingServiceStoragePublicationWriter>
37 StoragePublicationWriterSharedPtr;
38typedef std::shared_ptr<RTI_RecordingServiceStorageSubscriptionWriter>
39 StorageSubscriptionWriterSharedPtr;
40
41// Reader-related defines
42typedef std::shared_ptr<RTI_RecordingServiceStorageReader>
43 StorageReaderSharedPtr;
44typedef std::shared_ptr<RTI_RecordingServiceStorageStreamReader>
45 StorageStreamReaderSharedPtr;
46typedef std::shared_ptr<RTI_RecordingServiceStorageStreamInfoReader>
47 StorageStreamInfoReaderSharedPtr;
48
49/*
50 * Helper classes to be used with the pointer definitions above, to create the
51 * smart pointers and use this class as a deleter (pointing to the () operator)
52 */
53
54class NativeStorageStreamWriterDeleter {
55public:
56 NativeStorageStreamWriterDeleter(
57 RTI_RecordingServiceStorageWriter *storage_writer_parent)
58 : storage_writer_parent_(storage_writer_parent)
59 {
60 RTI_CHECK_PRECONDITION(storage_writer_parent != NULL);
61 }
62
63 void operator ()(RTI_RecordingServiceStorageStreamWriter *instance)
64 {
65 if (instance != NULL) {
66 storage_writer_parent_->delete_stream_writer(
67 storage_writer_parent_,
68 instance);
69 }
70 }
71
72 void operator ()(RTI_RecordingServiceStorageParticipantWriter *instance)
73 {
74 // The delete participant writer operation is not required, better be
75 // safe than sorry
76 if (instance != NULL
77 && storage_writer_parent_->delete_participant_writer != NULL) {
78 storage_writer_parent_->delete_participant_writer(
79 storage_writer_parent_,
80 instance);
81 }
82 }
83
84 void operator ()(RTI_RecordingServiceStoragePublicationWriter *instance)
85 {
86 // The delete publication writer operation is not required, better be
87 // safe than sorry
88 if (instance != NULL
89 && storage_writer_parent_->delete_publication_writer != NULL) {
90 storage_writer_parent_->delete_publication_writer(
91 storage_writer_parent_,
92 instance);
93 }
94 }
95
96 void operator ()(RTI_RecordingServiceStorageSubscriptionWriter *instance)
97 {
98 // The delete subscription writer operation is not required, better be
99 // safe than sorry
100 if (instance != NULL
101 && storage_writer_parent_->delete_subscription_writer != NULL) {
102 storage_writer_parent_->delete_subscription_writer(
103 storage_writer_parent_,
104 instance);
105 }
106 }
107
108private:
109 RTI_RecordingServiceStorageWriter *storage_writer_parent_;
110};
111
112class NativeStorageStreamInfoReaderDeleter {
113public:
114 NativeStorageStreamInfoReaderDeleter(
115 RTI_RecordingServiceStorageReader *storage_reader_parent)
116 : storage_reader_parent_(storage_reader_parent)
117 {
118 RTI_CHECK_PRECONDITION(storage_reader_parent != NULL);
119 }
120
121 void operator ()(RTI_RecordingServiceStorageStreamInfoReader *instance)
122 {
123 if (instance != NULL) {
124 storage_reader_parent_->delete_stream_info_reader(
125 storage_reader_parent_,
126 instance);
127 }
128 }
129
130private:
131 RTI_RecordingServiceStorageReader *storage_reader_parent_;
132};
133
134class NativeStorageStreamReaderDeleter {
135public:
136 NativeStorageStreamReaderDeleter(
137 RTI_RecordingServiceStorageReader *storage_reader_parent)
138 : storage_reader_parent_(storage_reader_parent)
139 {
140 RTI_CHECK_PRECONDITION(storage_reader_parent != NULL);
141 }
142
143 void operator ()(RTI_RecordingServiceStorageStreamReader *instance)
144 {
145 if (instance != NULL) {
146 storage_reader_parent_->delete_stream_reader(
147 storage_reader_parent_,
148 instance);
149 }
150 }
151
152private:
153 RTI_RecordingServiceStorageReader *storage_reader_parent_;
154};
155
156inline bool is_discovery_stream(const std::string& stream_name)
157{
158 if (stream_name.compare(DDS_PARTICIPANT_TOPIC_NAME) == 0
159 || stream_name.compare(DDS_PUBLICATION_TOPIC_NAME) == 0
160 || stream_name.compare(DDS_SUBSCRIPTION_TOPIC_NAME) == 0) {
161 return true;
162 }
163 return false;
164}
165
166inline std::string domain_id_property_name()
167{
168 return RTI_RECORDING_SERVICE_DOMAIN_ID_PROPERTY_NAME;
169}
170
171inline std::string start_timestamp_property_name()
172{
173 return RTI_RECORDING_SERVICE_START_TIMESTAMP_PROPERTY_NAME;
174}
175
176inline std::string end_timestamp_property_name()
177{
178 return RTI_RECORDING_SERVICE_END_TIMESTAMP_PROPERTY_NAME;
179}
180
181inline std::string jump_timestamp_property_name()
182{
183 return RTI_RECORDING_SERVICE_JUMP_TIMESTAMP_PROPERTY_NAME;
184}
185
186inline std::string sample_order_property_name()
187{
188 return RTI_RECORDING_SERVICE_PLAYBACK_SAMPLE_ORDER_PROPERTY_NAME;
189}
190
191inline std::string reverse_mode_property_name()
192{
193 return RTI_RECORDING_SERVICE_PLAYBACK_REVERSE_MODE_PROPERTY_NAME;
194}
195
196template <typename T>
197inline T get_from_properties(
198 const rti::recording::PropertySet& properties,
199 const std::string& property_name)
200{
201 rti::recording::PropertySet::const_iterator found =
202 properties.find(property_name);
203 if (found == properties.end()) {
204 throw dds::core::Error(
205 "!found property with name=" + property_name);
206 }
207 T value;
208 std::stringstream str_stream(found->second);
209 str_stream >> value;
210 if (str_stream.fail()) {
211 throw dds::core::Error(
212 "!parse value from property with name=" + property_name);
213 }
214 return value;
215}
216
217template <typename T>
218inline void add_to_properties(
219 rti::recording::PropertySet& properties,
220 const std::string& property_name,
221 const T value)
222{
223 rti::recording::PropertySet::const_iterator found =
224 properties.find(property_name);
225 if (found != properties.end()) {
226 return;
227 }
228 std::stringstream str_stream;
229 str_stream << value;
230 if (str_stream.fail()) {
231 throw dds::core::Error(
232 "!add value for property with name=" + property_name);
233 }
234 properties[property_name] = str_stream.str();
235}
236
237namespace detail {
238
239#define RecorderPrint_exception(...) \
240 RTILogMessage_print( \
241 RTI_LOG_PRINT_FORMAT_MASK_ALL, \
242 RTI_LOG_BIT_EXCEPTION, \
243 MODULE_RECORDER, \
244 __VA_ARGS__)
245
246} /* namespace rti::recording::detail */
247
248
249} } /* namespace rti::recording */
250
251#endif /* HPP_RTI_RECORDING_STORAGE_STORAGEDEFS_HPP_ */
The RTI namespace.
Definition: RecordingServiceImpl.hpp:22