WriterProxyData.h 11 KB

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