/src/Fast-DDS/include/fastdds/rtps/security/common/ParticipantGenericMessage.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | /*! |
16 | | * @file ParticipantGenericMessage.h |
17 | | */ |
18 | | #ifndef _FASTDDS_RTPS_SECURITY_COMMON_PARTICIPANTGENERICMESSAGE_H_ |
19 | | #define _FASTDDS_RTPS_SECURITY_COMMON_PARTICIPANTGENERICMESSAGE_H_ |
20 | | |
21 | | #include <fastdds/rtps/common/Guid.h> |
22 | | #include <fastdds/rtps/common/Token.h> |
23 | | |
24 | | namespace eprosima { |
25 | | namespace fastrtps { |
26 | | namespace rtps { |
27 | | namespace security { |
28 | | |
29 | | class MessageIdentity |
30 | | { |
31 | | public: |
32 | | |
33 | 0 | MessageIdentity() : sequence_number_(0) {} |
34 | | |
35 | | MessageIdentity(const MessageIdentity& mi) : |
36 | | source_guid_(mi.source_guid_), |
37 | | sequence_number_(mi.sequence_number_) |
38 | 0 | { |
39 | 0 | } |
40 | | |
41 | | MessageIdentity(MessageIdentity&& mi) : |
42 | | source_guid_(std::move(mi.source_guid_)), |
43 | | sequence_number_(mi.sequence_number_) |
44 | 0 | { |
45 | 0 | } |
46 | | |
47 | | MessageIdentity& operator=(const MessageIdentity& mi) |
48 | 0 | { |
49 | 0 | source_guid_ = mi.source_guid_; |
50 | 0 | sequence_number_ = mi.sequence_number_; |
51 | 0 | return *this; |
52 | 0 | } |
53 | | |
54 | | MessageIdentity& operator=(MessageIdentity&& mi) |
55 | 0 | { |
56 | 0 | source_guid_ = std::move(mi.source_guid_); |
57 | 0 | sequence_number_ = mi.sequence_number_; |
58 | 0 | return *this; |
59 | 0 | } |
60 | | |
61 | | void source_guid(const GUID_t& source_guid) |
62 | 0 | { |
63 | 0 | source_guid_ = source_guid; |
64 | 0 | } |
65 | | |
66 | | void source_guid(GUID_t&& source_guid) |
67 | 0 | { |
68 | 0 | source_guid_ = std::move(source_guid); |
69 | 0 | } |
70 | | |
71 | | const GUID_t& source_guid() const |
72 | 0 | { |
73 | 0 | return source_guid_; |
74 | 0 | } |
75 | | |
76 | | GUID_t& source_guid() |
77 | 0 | { |
78 | 0 | return source_guid_; |
79 | 0 | } |
80 | | |
81 | | void sequence_number(int64_t sequence_number) |
82 | 0 | { |
83 | 0 | sequence_number_ = sequence_number; |
84 | 0 | } |
85 | | |
86 | | int64_t sequence_number() const |
87 | 0 | { |
88 | 0 | return sequence_number_; |
89 | 0 | } |
90 | | |
91 | | int64_t& sequence_number() |
92 | 0 | { |
93 | 0 | return sequence_number_; |
94 | 0 | } |
95 | | |
96 | | private: |
97 | | |
98 | | GUID_t source_guid_; |
99 | | int64_t sequence_number_; |
100 | | }; |
101 | | |
102 | | class MessageIdentityHelper |
103 | | { |
104 | | public: |
105 | | |
106 | | static size_t serialized_size(const MessageIdentity& /*message*/, size_t current_alignment = 0) |
107 | 0 | { |
108 | 0 | size_t initial_alignment = current_alignment; |
109 | 0 |
|
110 | 0 | current_alignment += 16; |
111 | 0 | current_alignment += alignment(current_alignment, 8) + 8; |
112 | 0 |
|
113 | 0 | return current_alignment - initial_alignment; |
114 | 0 | } |
115 | | |
116 | | private: |
117 | | |
118 | 0 | inline static size_t alignment(size_t current_alignment, size_t dataSize) { return (dataSize - (current_alignment % dataSize)) & (dataSize-1);} |
119 | | }; |
120 | | |
121 | | class ParticipantGenericMessage |
122 | | { |
123 | | public: |
124 | | |
125 | 0 | ParticipantGenericMessage() {} |
126 | | |
127 | | ParticipantGenericMessage(const ParticipantGenericMessage& message) : |
128 | | message_identity_(message.message_identity_), |
129 | | related_message_identity_(message.related_message_identity_), |
130 | | destination_participant_key_(message.destination_participant_key_), |
131 | | destination_endpoint_key_(message.destination_endpoint_key_), |
132 | | source_endpoint_key_(message.source_endpoint_key_), |
133 | | message_class_id_(message.message_class_id_), |
134 | | message_data_(message.message_data_) |
135 | 0 | {} |
136 | | |
137 | | ParticipantGenericMessage(ParticipantGenericMessage&& message) : |
138 | | message_identity_(std::move(message.message_identity_)), |
139 | | related_message_identity_(std::move(message.related_message_identity_)), |
140 | | destination_participant_key_(std::move(message.destination_participant_key_)), |
141 | | destination_endpoint_key_(std::move(message.destination_endpoint_key_)), |
142 | | source_endpoint_key_(std::move(message.source_endpoint_key_)), |
143 | | message_class_id_(std::move(message.message_class_id_)), |
144 | | message_data_(std::move(message.message_data_)) |
145 | 0 | {} |
146 | | |
147 | | ParticipantGenericMessage& operator=(const ParticipantGenericMessage& message) |
148 | 0 | { |
149 | 0 | message_identity_ = message.message_identity_; |
150 | 0 | related_message_identity_ = message.related_message_identity_; |
151 | 0 | destination_participant_key_ = message.destination_participant_key_; |
152 | 0 | destination_endpoint_key_ = message.destination_endpoint_key_; |
153 | 0 | source_endpoint_key_ = message.source_endpoint_key_; |
154 | 0 | message_class_id_ = message.message_class_id_; |
155 | 0 | message_data_ = message.message_data_; |
156 | 0 | return *this; |
157 | 0 | } |
158 | | |
159 | | ParticipantGenericMessage& operator=(ParticipantGenericMessage&& message) |
160 | 0 | { |
161 | 0 | message_identity_ = std::move(message.message_identity_); |
162 | 0 | related_message_identity_ = std::move(message.related_message_identity_); |
163 | 0 | destination_participant_key_ = std::move(message.destination_participant_key_); |
164 | 0 | destination_endpoint_key_ = std::move(message.destination_endpoint_key_); |
165 | 0 | source_endpoint_key_ = std::move(message.source_endpoint_key_); |
166 | 0 | message_class_id_ = std::move(message.message_class_id_); |
167 | 0 | message_data_ = std::move(message.message_data_); |
168 | 0 | return *this; |
169 | 0 | } |
170 | | |
171 | | void message_identity(const MessageIdentity& message_identity) |
172 | 0 | { |
173 | 0 | message_identity_ = message_identity; |
174 | 0 | } |
175 | | |
176 | | void message_identity(MessageIdentity&& message_identity) |
177 | 0 | { |
178 | 0 | message_identity_ = std::move(message_identity); |
179 | 0 | } |
180 | | |
181 | | const MessageIdentity& message_identity() const |
182 | 0 | { |
183 | 0 | return message_identity_; |
184 | 0 | } |
185 | | |
186 | | MessageIdentity& message_identity() |
187 | 0 | { |
188 | 0 | return message_identity_; |
189 | 0 | } |
190 | | |
191 | | void related_message_identity(const MessageIdentity& related_message_identity) |
192 | 0 | { |
193 | 0 | related_message_identity_ = related_message_identity; |
194 | 0 | } |
195 | | |
196 | | void related_message_identity(MessageIdentity&& related_message_identity) |
197 | 0 | { |
198 | 0 | related_message_identity_ = std::move(related_message_identity); |
199 | 0 | } |
200 | | |
201 | | const MessageIdentity& related_message_identity() const |
202 | 0 | { |
203 | 0 | return related_message_identity_; |
204 | 0 | } |
205 | | |
206 | | MessageIdentity& related_message_identity() |
207 | 0 | { |
208 | 0 | return related_message_identity_; |
209 | 0 | } |
210 | | |
211 | | void destination_participant_key(const GUID_t& destination_participant_key) |
212 | 0 | { |
213 | 0 | destination_participant_key_ = destination_participant_key; |
214 | 0 | } |
215 | | |
216 | | void destination_participant_key(GUID_t&& destination_participant_key) |
217 | 0 | { |
218 | 0 | destination_participant_key_ = std::move(destination_participant_key); |
219 | 0 | } |
220 | | |
221 | | const GUID_t& destination_participant_key() const |
222 | 0 | { |
223 | 0 | return destination_participant_key_; |
224 | 0 | } |
225 | | |
226 | | GUID_t& destination_participant_key() |
227 | 0 | { |
228 | 0 | return destination_participant_key_; |
229 | 0 | } |
230 | | |
231 | | void destination_endpoint_key(const GUID_t& destination_endpoint_key) |
232 | 0 | { |
233 | 0 | destination_endpoint_key_ = destination_endpoint_key; |
234 | 0 | } |
235 | | |
236 | | void destination_endpoint_key(GUID_t&& destination_endpoint_key) |
237 | 0 | { |
238 | 0 | destination_endpoint_key_ = std::move(destination_endpoint_key); |
239 | 0 | } |
240 | | |
241 | | const GUID_t& destination_endpoint_key() const |
242 | 0 | { |
243 | 0 | return destination_endpoint_key_; |
244 | 0 | } |
245 | | |
246 | | GUID_t& destination_endpoint_key() |
247 | 0 | { |
248 | 0 | return destination_endpoint_key_; |
249 | 0 | } |
250 | | |
251 | | void source_endpoint_key(const GUID_t& source_endpoint_key) |
252 | 0 | { |
253 | 0 | source_endpoint_key_ = source_endpoint_key; |
254 | 0 | } |
255 | | |
256 | | void source_endpoint_key(GUID_t&& source_endpoint_key) |
257 | 0 | { |
258 | 0 | source_endpoint_key_ = std::move(source_endpoint_key); |
259 | 0 | } |
260 | | |
261 | | const GUID_t& source_endpoint_key() const |
262 | 0 | { |
263 | 0 | return source_endpoint_key_; |
264 | 0 | } |
265 | | |
266 | | GUID_t& source_endpoint_key() |
267 | 0 | { |
268 | 0 | return source_endpoint_key_; |
269 | 0 | } |
270 | | |
271 | | void message_class_id(const std::string& message_class_id) |
272 | 0 | { |
273 | 0 | message_class_id_ = message_class_id; |
274 | 0 | } |
275 | | |
276 | | void message_class_id(std::string&& message_class_id) |
277 | 0 | { |
278 | 0 | message_class_id_ = std::move(message_class_id); |
279 | 0 | } |
280 | | |
281 | | const std::string& message_class_id() const |
282 | 0 | { |
283 | 0 | return message_class_id_; |
284 | 0 | } |
285 | | |
286 | | std::string& message_class_id() |
287 | 0 | { |
288 | 0 | return message_class_id_; |
289 | 0 | } |
290 | | |
291 | | void message_data(const DataHolderSeq& message_data) |
292 | 0 | { |
293 | 0 | message_data_ = message_data; |
294 | 0 | } |
295 | | |
296 | | void message_data(DataHolderSeq&& message_data) |
297 | 0 | { |
298 | 0 | message_data_ = std::move(message_data); |
299 | 0 | } |
300 | | |
301 | | const DataHolderSeq& message_data() const |
302 | 0 | { |
303 | 0 | return message_data_; |
304 | 0 | } |
305 | | |
306 | | DataHolderSeq& message_data() |
307 | 0 | { |
308 | 0 | return message_data_; |
309 | 0 | } |
310 | | |
311 | | private: |
312 | | |
313 | | MessageIdentity message_identity_; |
314 | | MessageIdentity related_message_identity_; |
315 | | GUID_t destination_participant_key_; |
316 | | GUID_t destination_endpoint_key_; |
317 | | GUID_t source_endpoint_key_; |
318 | | std::string message_class_id_; |
319 | | DataHolderSeq message_data_; |
320 | | }; |
321 | | |
322 | | class ParticipantGenericMessageHelper |
323 | | { |
324 | | public: |
325 | | |
326 | | static size_t serialized_size(const ParticipantGenericMessage& message, size_t current_alignment = 0) |
327 | 0 | { |
328 | 0 | size_t initial_alignment = current_alignment; |
329 | 0 |
|
330 | 0 | current_alignment += MessageIdentityHelper::serialized_size(message.message_identity(), current_alignment); |
331 | 0 | current_alignment += MessageIdentityHelper::serialized_size(message.related_message_identity(), current_alignment); |
332 | 0 | current_alignment += 16 * 3; |
333 | 0 | current_alignment += 4 + alignment(current_alignment, 4) + message.message_class_id().size() + 1; |
334 | 0 | current_alignment += DataHolderHelper::serialized_size(message.message_data(), current_alignment); |
335 | 0 |
|
336 | 0 | return current_alignment - initial_alignment; |
337 | 0 | } |
338 | | |
339 | | private: |
340 | | |
341 | 0 | inline static size_t alignment(size_t current_alignment, size_t dataSize) { return (dataSize - (current_alignment % dataSize)) & (dataSize-1);} |
342 | | }; |
343 | | |
344 | | } //namespace security |
345 | | } //namespace rtps |
346 | | } //namespace fastrtps |
347 | | } //namespace eprosima |
348 | | |
349 | | #endif // _FASTDDS_RTPS_SECURITY_COMMON_PARTICIPANTGENERICMESSAGE_H_ |