ReaderProxyData.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. * @file ReaderProxyData.h
  16. *
  17. */
  18. #ifndef _FASTDDS_RTPS_BUILTIN_DATA_READERPROXYDATA_H_
  19. #define _FASTDDS_RTPS_BUILTIN_DATA_READERPROXYDATA_H_
  20. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  21. #include <fastrtps/attributes/TopicAttributes.h>
  22. #include <fastrtps/qos/ReaderQos.h>
  23. #include <fastdds/rtps/attributes/WriterAttributes.h>
  24. #include <fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp>
  25. #if HAVE_SECURITY
  26. #include <fastdds/rtps/security/accesscontrol/EndpointSecurityAttributes.h>
  27. #endif
  28. #include <fastdds/rtps/common/RemoteLocators.hpp>
  29. namespace eprosima {
  30. namespace fastrtps {
  31. namespace rtps {
  32. struct CDRMessage_t;
  33. class NetworkFactory;
  34. /**
  35. * Class ReaderProxyData, used to represent all the information on a Reader (both local and remote) with the purpose of
  36. * implementing the discovery.
  37. * *@ingroup BUILTIN_MODULE
  38. */
  39. class ReaderProxyData
  40. {
  41. public:
  42. RTPS_DllAPI ReaderProxyData(
  43. const size_t max_unicast_locators,
  44. const size_t max_multicast_locators);
  45. RTPS_DllAPI ReaderProxyData(
  46. const size_t max_unicast_locators,
  47. const size_t max_multicast_locators,
  48. const VariableLengthDataLimits& data_limits);
  49. RTPS_DllAPI virtual ~ReaderProxyData();
  50. RTPS_DllAPI ReaderProxyData(
  51. const ReaderProxyData& readerInfo);
  52. RTPS_DllAPI ReaderProxyData& operator =(
  53. const ReaderProxyData& readerInfo);
  54. RTPS_DllAPI void guid(
  55. const GUID_t& guid)
  56. {
  57. m_guid = guid;
  58. }
  59. RTPS_DllAPI void guid(
  60. GUID_t&& guid)
  61. {
  62. m_guid = std::move(guid);
  63. }
  64. RTPS_DllAPI const GUID_t& guid() const
  65. {
  66. return m_guid;
  67. }
  68. RTPS_DllAPI GUID_t& guid()
  69. {
  70. return m_guid;
  71. }
  72. RTPS_DllAPI bool has_locators() const
  73. {
  74. return !remote_locators_.unicast.empty() || !remote_locators_.multicast.empty();
  75. }
  76. RTPS_DllAPI const RemoteLocatorList& remote_locators() const
  77. {
  78. return remote_locators_;
  79. }
  80. RTPS_DllAPI void add_unicast_locator(
  81. const Locator_t& locator);
  82. void set_announced_unicast_locators(
  83. const LocatorList_t& locators);
  84. void set_remote_unicast_locators(
  85. const LocatorList_t& locators,
  86. const NetworkFactory& network);
  87. RTPS_DllAPI void add_multicast_locator(
  88. const Locator_t& locator);
  89. void set_multicast_locators(
  90. const LocatorList_t& locators,
  91. const NetworkFactory& network);
  92. void set_locators(
  93. const RemoteLocatorList& locators);
  94. void set_remote_locators(
  95. const RemoteLocatorList& locators,
  96. const NetworkFactory& network,
  97. bool use_multicast_locators);
  98. RTPS_DllAPI void key(
  99. const InstanceHandle_t& key)
  100. {
  101. m_key = key;
  102. }
  103. RTPS_DllAPI void key(
  104. InstanceHandle_t&& key)
  105. {
  106. m_key = std::move(key);
  107. }
  108. RTPS_DllAPI InstanceHandle_t key() const
  109. {
  110. return m_key;
  111. }
  112. RTPS_DllAPI InstanceHandle_t& key()
  113. {
  114. return m_key;
  115. }
  116. RTPS_DllAPI void RTPSParticipantKey(
  117. const InstanceHandle_t& RTPSParticipantKey)
  118. {
  119. m_RTPSParticipantKey = RTPSParticipantKey;
  120. }
  121. RTPS_DllAPI void RTPSParticipantKey(
  122. InstanceHandle_t&& RTPSParticipantKey)
  123. {
  124. m_RTPSParticipantKey = std::move(RTPSParticipantKey);
  125. }
  126. RTPS_DllAPI InstanceHandle_t RTPSParticipantKey() const
  127. {
  128. return m_RTPSParticipantKey;
  129. }
  130. RTPS_DllAPI InstanceHandle_t& RTPSParticipantKey()
  131. {
  132. return m_RTPSParticipantKey;
  133. }
  134. RTPS_DllAPI void typeName(
  135. const string_255& typeName)
  136. {
  137. m_typeName = typeName;
  138. }
  139. RTPS_DllAPI void typeName(
  140. string_255&& typeName)
  141. {
  142. m_typeName = std::move(typeName);
  143. }
  144. RTPS_DllAPI const string_255& typeName() const
  145. {
  146. return m_typeName;
  147. }
  148. RTPS_DllAPI string_255& typeName()
  149. {
  150. return m_typeName;
  151. }
  152. RTPS_DllAPI void topicName(
  153. const string_255& topicName)
  154. {
  155. m_topicName = topicName;
  156. }
  157. RTPS_DllAPI void topicName(
  158. string_255&& topicName)
  159. {
  160. m_topicName = std::move(topicName);
  161. }
  162. RTPS_DllAPI const string_255& topicName() const
  163. {
  164. return m_topicName;
  165. }
  166. RTPS_DllAPI string_255& topicName()
  167. {
  168. return m_topicName;
  169. }
  170. RTPS_DllAPI void userDefinedId(
  171. uint16_t userDefinedId)
  172. {
  173. m_userDefinedId = userDefinedId;
  174. }
  175. RTPS_DllAPI uint16_t userDefinedId() const
  176. {
  177. return m_userDefinedId;
  178. }
  179. RTPS_DllAPI uint16_t& userDefinedId()
  180. {
  181. return m_userDefinedId;
  182. }
  183. RTPS_DllAPI void isAlive(
  184. bool isAlive)
  185. {
  186. m_isAlive = isAlive;
  187. }
  188. RTPS_DllAPI bool isAlive() const
  189. {
  190. return m_isAlive;
  191. }
  192. RTPS_DllAPI bool& isAlive()
  193. {
  194. return m_isAlive;
  195. }
  196. RTPS_DllAPI void topicKind(
  197. TopicKind_t topicKind)
  198. {
  199. m_topicKind = topicKind;
  200. }
  201. RTPS_DllAPI TopicKind_t topicKind() const
  202. {
  203. return m_topicKind;
  204. }
  205. RTPS_DllAPI TopicKind_t& topicKind()
  206. {
  207. return m_topicKind;
  208. }
  209. RTPS_DllAPI void type_id(
  210. const TypeIdV1& other_type_id)
  211. {
  212. type_id() = other_type_id;
  213. }
  214. RTPS_DllAPI const TypeIdV1& type_id() const
  215. {
  216. assert(m_type_id != nullptr);
  217. return *m_type_id;
  218. }
  219. RTPS_DllAPI TypeIdV1& type_id()
  220. {
  221. if (m_type_id == nullptr)
  222. {
  223. m_type_id = new TypeIdV1();
  224. }
  225. return *m_type_id;
  226. }
  227. RTPS_DllAPI bool has_type_id() const
  228. {
  229. return m_type_id != nullptr;
  230. }
  231. RTPS_DllAPI void type(
  232. const TypeObjectV1& other_type)
  233. {
  234. type() = other_type;
  235. }
  236. RTPS_DllAPI const TypeObjectV1& type() const
  237. {
  238. assert(m_type != nullptr);
  239. return *m_type;
  240. }
  241. RTPS_DllAPI TypeObjectV1& type()
  242. {
  243. if (m_type == nullptr)
  244. {
  245. m_type = new TypeObjectV1();
  246. }
  247. return *m_type;
  248. }
  249. RTPS_DllAPI bool has_type() const
  250. {
  251. return m_type != nullptr;
  252. }
  253. RTPS_DllAPI void type_information(
  254. const xtypes::TypeInformation& other_type_information)
  255. {
  256. type_information() = other_type_information;
  257. }
  258. RTPS_DllAPI const xtypes::TypeInformation& type_information() const
  259. {
  260. assert(m_type_information != nullptr);
  261. return *m_type_information;
  262. }
  263. RTPS_DllAPI xtypes::TypeInformation& type_information()
  264. {
  265. if (m_type_information == nullptr)
  266. {
  267. m_type_information = new xtypes::TypeInformation();
  268. }
  269. return *m_type_information;
  270. }
  271. RTPS_DllAPI bool has_type_information() const
  272. {
  273. return m_type_information != nullptr;
  274. }
  275. inline bool disable_positive_acks() const
  276. {
  277. return m_qos.m_disablePositiveACKs.enabled;
  278. }
  279. /**
  280. * Get the size in bytes of the CDR serialization of this object.
  281. * @param include_encapsulation Whether to include the size of the encapsulation info.
  282. * @return size in bytes of the CDR serialization.
  283. */
  284. uint32_t get_serialized_size(
  285. bool include_encapsulation) const;
  286. /**
  287. * Write as a parameter list on a CDRMessage_t
  288. * @return True on success
  289. */
  290. bool writeToCDRMessage(
  291. CDRMessage_t* msg,
  292. bool write_encapsulation) const;
  293. /**
  294. * Read the information from a CDRMessage_t. The position of the message must be in the beggining on the parameter list.
  295. * @param msg Pointer to the message.
  296. * @param network Reference to network factory for locator validation and transformation
  297. * @param is_shm_transport_available Indicates wether the Reader is reachable by SHM.
  298. * @return true on success
  299. */
  300. RTPS_DllAPI bool readFromCDRMessage(
  301. CDRMessage_t* msg,
  302. const NetworkFactory& network,
  303. bool is_shm_transport_available);
  304. //!
  305. bool m_expectsInlineQos;
  306. //!Reader Qos
  307. ReaderQos m_qos;
  308. #if HAVE_SECURITY
  309. //!EndpointSecurityInfo.endpoint_security_attributes
  310. security::EndpointSecurityAttributesMask security_attributes_;
  311. //!EndpointSecurityInfo.plugin_endpoint_security_attributes
  312. security::PluginEndpointSecurityAttributesMask plugin_security_attributes_;
  313. #endif
  314. /**
  315. * Clear (put to default) the information.
  316. */
  317. void clear();
  318. /**
  319. * Check if this object can be updated with the information on another object.
  320. * @param rdata ReaderProxyData object to be checked.
  321. * @return true if this object can be updated with the information on rdata.
  322. */
  323. bool is_update_allowed(
  324. const ReaderProxyData& rdata) const;
  325. /**
  326. * Update the information (only certain fields will be updated).
  327. * @param rdata Poitner to the object from which we are going to update.
  328. */
  329. void update(
  330. ReaderProxyData* rdata);
  331. /**
  332. * Copy ALL the information from another object.
  333. * @param rdata Pointer to the object from where the information must be copied.
  334. */
  335. void copy(
  336. ReaderProxyData* rdata);
  337. private:
  338. //!GUID
  339. GUID_t m_guid;
  340. //!Holds locator information
  341. RemoteLocatorList remote_locators_;
  342. //!GUID_t of the Reader converted to InstanceHandle_t
  343. InstanceHandle_t m_key;
  344. //!GUID_t of the participant converted to InstanceHandle
  345. InstanceHandle_t m_RTPSParticipantKey;
  346. //!Type name
  347. string_255 m_typeName;
  348. //!Topic name
  349. string_255 m_topicName;
  350. //!User defined ID
  351. uint16_t m_userDefinedId;
  352. //!Field to indicate if the Reader is Alive.
  353. bool m_isAlive;
  354. //!Topic kind
  355. TopicKind_t m_topicKind;
  356. //!Type Identifier
  357. TypeIdV1* m_type_id;
  358. //!Type Object
  359. TypeObjectV1* m_type;
  360. //!Type Information
  361. xtypes::TypeInformation* m_type_information;
  362. };
  363. }
  364. } /* namespace rtps */
  365. } /* namespace eprosima */
  366. #endif
  367. #endif // _FASTDDS_RTPS_BUILTIN_DATA_READERPROXYDATA_H_