Fast DDS  Version 3.0.0
Fast DDS
Loading...
Searching...
No Matches
EntityId_t.hpp
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
19#ifndef FASTDDS_RTPS_COMMON__ENTITYID_T_HPP
20#define FASTDDS_RTPS_COMMON__ENTITYID_T_HPP
21
22#include <fastdds/fastdds_dll.hpp>
23#include <fastdds/rtps/common/Types.hpp>
24
25#include <cstdint>
26#include <cstring>
27#include <sstream>
28
29namespace eprosima {
30namespace fastdds {
31namespace rtps {
32
33
34#define ENTITYID_UNKNOWN 0x00000000
35#define ENTITYID_RTPSParticipant 0x000001c1
36#define ENTITYID_SEDP_BUILTIN_TOPIC_WRITER 0x000002c2
37#define ENTITYID_SEDP_BUILTIN_TOPIC_READER 0x000002c7
38#define ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER 0x000003c2
39#define ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER 0x000003c7
40#define ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER 0x000004c2
41#define ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER 0x000004c7
42#define ENTITYID_SPDP_BUILTIN_RTPSParticipant_WRITER 0x000100c2
43#define ENTITYID_SPDP_BUILTIN_RTPSParticipant_READER 0x000100c7
44#define ENTITYID_P2P_BUILTIN_RTPSParticipant_MESSAGE_WRITER 0x000200C2
45#define ENTITYID_P2P_BUILTIN_RTPSParticipant_MESSAGE_READER 0x000200C7
46#define ENTITYID_P2P_BUILTIN_PARTICIPANT_STATELESS_WRITER 0x000201C3
47#define ENTITYID_P2P_BUILTIN_PARTICIPANT_STATELESS_READER 0x000201C4
48
49#define ENTITYID_TL_SVC_REQ_WRITER 0x000300C3
50#define ENTITYID_TL_SVC_REQ_READER 0x000300C4
51#define ENTITYID_TL_SVC_REPLY_WRITER 0x000301C3
52#define ENTITYID_TL_SVC_REPLY_READER 0x000301C4
53
54#if HAVE_SECURITY
55#define ENTITYID_SEDP_BUILTIN_PUBLICATIONS_SECURE_WRITER 0xff0003c2
56#define ENTITYID_SEDP_BUILTIN_PUBLICATIONS_SECURE_READER 0xff0003c7
57#define ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_SECURE_WRITER 0xff0004c2
58#define ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_SECURE_READER 0xff0004c7
59#define ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_SECURE_WRITER 0xff0200c2
60#define ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_SECURE_READER 0xff0200c7
61#define ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_MESSAGE_SECURE_WRITER 0xff0202C3
62#define ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_MESSAGE_SECURE_READER 0xff0202C4
63#define ENTITYID_SPDP_RELIABLE_BUILTIN_PARTICIPANT_SECURE_WRITER 0xff0101c2
64#define ENTITYID_SPDP_RELIABLE_BUILTIN_PARTICIPANT_SECURE_READER 0xff0101c7
65#endif // if HAVE_SECURITY
66
67#define ENTITYID_DS_SERVER_VIRTUAL_WRITER 0x00030073
68#define ENTITYID_DS_SERVER_VIRTUAL_READER 0x00030074
69
70#ifdef FASTDDS_STATISTICS
71#define ENTITYID_MONITOR_SERVICE_WRITER 0x004000D2
72#endif // ifdef FASTDDS_STATISTICS
73
76struct FASTDDS_EXPORTED_API EntityId_t
77{
78 static constexpr unsigned int size = 4;
79 octet value[size];
82 {
83 *this = ENTITYID_UNKNOWN;
84 }
85
91 uint32_t id)
92 {
93 memcpy(value, &id, size);
94#if !FASTDDS_IS_BIG_ENDIAN_TARGET
95 reverse();
96#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
97 }
98
103 const EntityId_t& id)
104 {
105 memcpy(value, id.value, size);
106 }
107
112 EntityId_t&& id)
113 {
114 memmove(value, id.value, size);
115 }
116
117 EntityId_t& operator =(
118 const EntityId_t& id)
119 {
120 memcpy(value, id.value, size);
121 return *this;
122 }
123
124 EntityId_t& operator =(
125 EntityId_t&& id)
126 {
127 memmove(value, id.value, size);
128 return *this;
129 }
130
135 EntityId_t& operator =(
136 uint32_t id)
137 {
138 memcpy(value, &id, size);
139#if !FASTDDS_IS_BIG_ENDIAN_TARGET
140 reverse();
141#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
142 return *this;
143 //return id;
144 }
145
146#if !FASTDDS_IS_BIG_ENDIAN_TARGET
148 void reverse()
149 {
150 octet oaux;
151 oaux = value[3];
152 value[3] = value[0];
153 value[0] = oaux;
154 oaux = value[2];
155 value[2] = value[1];
156 value[1] = oaux;
157 }
158
159#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
160
165 uint32_t to_uint32() const
166 {
167 uint32_t res = *reinterpret_cast<const uint32_t*>(value);
168
169#if !FASTDDS_IS_BIG_ENDIAN_TARGET
170 res = ( res >> 24 ) |
171 (0x0000ff00 & ( res >> 8)) |
172 (0x00ff0000 & ( res << 8)) |
173 ( res << 24 );
174#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
175
176 return res;
177 }
178
180 {
181 return EntityId_t();
182 }
183
184 bool is_reader() const
185 {
186 // RTPS Standard table 9.1
187 return 0x4u & to_uint32();
188 }
189
190 bool is_writer() const
191 {
192 // RTPS Standard table 9.1
193 return 0x2u & to_uint32() && !is_reader();
194 }
195
201 bool operator <(
202 const EntityId_t& other) const
203 {
204 return std::memcmp(value, other.value, size) < 0;
205 }
206
217 static int cmp(
218 const EntityId_t& entity1,
219 const EntityId_t& entity2)
220 {
221 return std::memcmp(entity1.value, entity2.value, size);
222 }
223
224};
225
226#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
227
234inline bool operator ==(
235 EntityId_t& id1,
236 const uint32_t id2)
237{
238#if !FASTDDS_IS_BIG_ENDIAN_TARGET
239 id1.reverse();
240#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
241 const bool result = 0 == memcmp(id1.value, &id2, sizeof(id2));
242#if !FASTDDS_IS_BIG_ENDIAN_TARGET
243 id1.reverse();
244#endif // if !FASTDDS_IS_BIG_ENDIAN_TARGET
245 return result;
246}
247
254inline bool operator ==(
255 const EntityId_t& id1,
256 const EntityId_t& id2)
257{
258 return EntityId_t::cmp(id1, id2) == 0;
259}
260
267inline bool operator !=(
268 const EntityId_t& id1,
269 const EntityId_t& id2)
270{
271 // Use == operator as it is faster enough.
272 // NOTE: this could be done comparing the entities backwards (starting in [3]) as it would probably be faster.
273 return !(operator ==(id1, id2));
274}
275
276#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
277
278inline std::ostream& operator <<(
279 std::ostream& output,
280 const EntityId_t& enI)
281{
282 std::stringstream ss;
283 ss << std::hex;
284 ss << (int)enI.value[0] << "." << (int)enI.value[1] << "." << (int)enI.value[2] << "." << (int)enI.value[3];
285 ss << std::dec;
286 return output << ss.str();
287}
288
289inline std::istream& operator >>(
290 std::istream& input,
291 EntityId_t& enP)
292{
293 std::istream::sentry s(input);
294
295 if (s)
296 {
297 char point;
298 unsigned short hex;
299 std::ios_base::iostate excp_mask = input.exceptions();
300
301 try
302 {
303 input.exceptions(excp_mask | std::ios_base::failbit | std::ios_base::badbit);
304 input >> std::hex >> hex;
305
306 if (hex > 255)
307 {
308 input.setstate(std::ios_base::failbit);
309 }
310
311 enP.value[0] = static_cast<octet>(hex);
312
313 for (int i = 1; i < 4; ++i)
314 {
315 input >> point >> hex;
316 if ( point != '.' || hex > 255 )
317 {
318 input.setstate(std::ios_base::failbit);
319 }
320 enP.value[i] = static_cast<octet>(hex);
321 }
322
323 input >> std::dec;
324 }
325 catch (std::ios_base::failure& )
326 {
327 }
328
329 input.exceptions(excp_mask);
330 }
331
332 return input;
333}
334
335const EntityId_t c_EntityId_Unknown = ENTITYID_UNKNOWN;
336const EntityId_t c_EntityId_SPDPReader = ENTITYID_SPDP_BUILTIN_RTPSParticipant_READER;
337const EntityId_t c_EntityId_SPDPWriter = ENTITYID_SPDP_BUILTIN_RTPSParticipant_WRITER;
338
339const EntityId_t c_EntityId_SEDPPubWriter = ENTITYID_SEDP_BUILTIN_PUBLICATIONS_WRITER;
340const EntityId_t c_EntityId_SEDPPubReader = ENTITYID_SEDP_BUILTIN_PUBLICATIONS_READER;
341const EntityId_t c_EntityId_SEDPSubWriter = ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_WRITER;
342const EntityId_t c_EntityId_SEDPSubReader = ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_READER;
343
344const EntityId_t c_EntityId_RTPSParticipant = ENTITYID_RTPSParticipant;
345
346const EntityId_t c_EntityId_WriterLiveliness = ENTITYID_P2P_BUILTIN_RTPSParticipant_MESSAGE_WRITER;
347const EntityId_t c_EntityId_ReaderLiveliness = ENTITYID_P2P_BUILTIN_RTPSParticipant_MESSAGE_READER;
348
349const EntityId_t participant_stateless_message_writer_entity_id = ENTITYID_P2P_BUILTIN_PARTICIPANT_STATELESS_WRITER;
350const EntityId_t participant_stateless_message_reader_entity_id = ENTITYID_P2P_BUILTIN_PARTICIPANT_STATELESS_READER;
351
352const EntityId_t c_EntityId_TypeLookup_request_writer = ENTITYID_TL_SVC_REQ_WRITER;
353const EntityId_t c_EntityId_TypeLookup_request_reader = ENTITYID_TL_SVC_REQ_READER;
354const EntityId_t c_EntityId_TypeLookup_reply_writer = ENTITYID_TL_SVC_REPLY_WRITER;
355const EntityId_t c_EntityId_TypeLookup_reply_reader = ENTITYID_TL_SVC_REPLY_READER;
356
357#if HAVE_SECURITY
358const EntityId_t sedp_builtin_publications_secure_writer = ENTITYID_SEDP_BUILTIN_PUBLICATIONS_SECURE_WRITER;
359const EntityId_t sedp_builtin_publications_secure_reader = ENTITYID_SEDP_BUILTIN_PUBLICATIONS_SECURE_READER;
360const EntityId_t sedp_builtin_subscriptions_secure_writer = ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_SECURE_WRITER;
361const EntityId_t sedp_builtin_subscriptions_secure_reader = ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_SECURE_READER;
362
363const EntityId_t participant_volatile_message_secure_writer_entity_id =
364 ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_MESSAGE_SECURE_WRITER;
365const EntityId_t participant_volatile_message_secure_reader_entity_id =
366 ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_MESSAGE_SECURE_READER;
367
368const EntityId_t c_EntityId_WriterLivelinessSecure = ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_SECURE_WRITER;
369const EntityId_t c_EntityId_ReaderLivelinessSecure = ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_SECURE_READER;
370
371const EntityId_t c_EntityId_spdp_reliable_participant_secure_reader =
372 ENTITYID_SPDP_RELIABLE_BUILTIN_PARTICIPANT_SECURE_READER;
373const EntityId_t c_EntityId_spdp_reliable_participant_secure_writer =
374 ENTITYID_SPDP_RELIABLE_BUILTIN_PARTICIPANT_SECURE_WRITER;
375#endif // if HAVE_SECURITY
376
377const EntityId_t ds_server_virtual_writer = ENTITYID_DS_SERVER_VIRTUAL_WRITER;
378const EntityId_t ds_server_virtual_reader = ENTITYID_DS_SERVER_VIRTUAL_READER;
379
380#ifdef FASTDDS_STATISTICS
381const EntityId_t monitor_service_status_writer = ENTITYID_MONITOR_SERVICE_WRITER;
382#endif // if FASTDDS_STATISTICS
383
384} // namespace rtps
385} // namespace fastdds
386} // namespace eprosima
387
388namespace std {
389template <>
390struct hash<eprosima::fastdds::rtps::EntityId_t>
391{
392 std::size_t operator ()(
394 {
395 return (static_cast<size_t>(k.value[0]) << 16) |
396 (static_cast<size_t>(k.value[1]) << 8) |
397 static_cast<size_t>(k.value[2]);
398 }
399
400};
401
402} // namespace std
403
404
405#endif // FASTDDS_RTPS_COMMON__ENTITYID_T_HPP
std::istream & operator>>(std::istream &input, EntityId_t &enP)
Definition EntityId_t.hpp:289
const EntityId_t c_EntityId_TypeLookup_request_reader
Definition EntityId_t.hpp:353
const EntityId_t c_EntityId_TypeLookup_request_writer
Definition EntityId_t.hpp:352
const EntityId_t ds_server_virtual_reader
Definition EntityId_t.hpp:378
bool operator==(const BuiltinTransportsOptions &bto1, const BuiltinTransportsOptions &bto2)
Equal to operator.
Definition BuiltinTransports.hpp:79
std::ostream & operator<<(std::ostream &output, BuiltinTransports transports)
Definition BuiltinTransports.hpp:117
const EntityId_t c_EntityId_SPDPReader
Definition EntityId_t.hpp:336
const EntityId_t c_EntityId_SEDPSubReader
Definition EntityId_t.hpp:342
unsigned char octet
Definition Types.hpp:83
const EntityId_t c_EntityId_RTPSParticipant
Definition EntityId_t.hpp:344
const EntityId_t c_EntityId_SPDPWriter
Definition EntityId_t.hpp:337
bool operator!=(const EntityId_t &id1, const EntityId_t &id2)
Guid prefix comparison operator.
Definition EntityId_t.hpp:267
const EntityId_t c_EntityId_TypeLookup_reply_reader
Definition EntityId_t.hpp:355
const EntityId_t participant_stateless_message_reader_entity_id
Definition EntityId_t.hpp:350
const EntityId_t c_EntityId_SEDPPubReader
Definition EntityId_t.hpp:340
const EntityId_t c_EntityId_WriterLiveliness
Definition EntityId_t.hpp:346
const EntityId_t c_EntityId_SEDPPubWriter
Definition EntityId_t.hpp:339
const EntityId_t participant_stateless_message_writer_entity_id
Definition EntityId_t.hpp:349
const EntityId_t c_EntityId_TypeLookup_reply_writer
Definition EntityId_t.hpp:354
const EntityId_t ds_server_virtual_writer
Definition EntityId_t.hpp:377
const EntityId_t c_EntityId_Unknown
Definition EntityId_t.hpp:335
const EntityId_t c_EntityId_ReaderLiveliness
Definition EntityId_t.hpp:347
const EntityId_t c_EntityId_SEDPSubWriter
Definition EntityId_t.hpp:341
eProsima namespace.
Definition EntityId_t.hpp:388
Structure EntityId_t, entity id part of GUID_t.
Definition EntityId_t.hpp:77
EntityId_t(EntityId_t &&id)
Move constructor.
Definition EntityId_t.hpp:111
void reverse()
Definition EntityId_t.hpp:148
EntityId_t()
Default constructor. Unknown entity.
Definition EntityId_t.hpp:81
bool is_writer() const
Definition EntityId_t.hpp:190
bool is_reader() const
Definition EntityId_t.hpp:184
EntityId_t(uint32_t id)
Main constructor.
Definition EntityId_t.hpp:90
static EntityId_t unknown()
Definition EntityId_t.hpp:179
octet value[size]
Definition EntityId_t.hpp:79
EntityId_t(const EntityId_t &id)
Copy constructor.
Definition EntityId_t.hpp:102
uint32_t to_uint32() const
conversion to uint32_t
Definition EntityId_t.hpp:165
static int cmp(const EntityId_t &entity1, const EntityId_t &entity2)
Entity Id compare static method.
Definition EntityId_t.hpp:217