Entity.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Copyright 2019 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 Entity.hpp
  16. *
  17. */
  18. #ifndef _FASTDDS_ENTITY_HPP_
  19. #define _FASTDDS_ENTITY_HPP_
  20. #include <fastdds/dds/core/status/StatusMask.hpp>
  21. #include <fastdds/rtps/common/InstanceHandle.h>
  22. #include <fastrtps/types/TypesBase.h>
  23. namespace eprosima {
  24. namespace fastdds {
  25. namespace dds {
  26. /**
  27. * @brief The Entity class is the abstract base class for all the objects that support QoS policies, a listener and
  28. * a status condition.
  29. *
  30. */
  31. class Entity
  32. {
  33. public:
  34. /**
  35. * @brief Constructor
  36. * @param mask StatusMask (default: all)
  37. */
  38. RTPS_DllAPI Entity(
  39. const StatusMask& mask = StatusMask::all())
  40. : status_mask_(mask)
  41. , enable_(false)
  42. {
  43. }
  44. /**
  45. * @brief This operation enables the Entity
  46. * @return RETCODE_OK
  47. */
  48. virtual fastrtps::types::ReturnCode_t enable()
  49. {
  50. enable_ = true;
  51. return fastrtps::types::ReturnCode_t::RETCODE_OK;
  52. }
  53. /**
  54. * @brief This operation disables the Entity before closing it
  55. */
  56. void close()
  57. {
  58. enable_ = false;
  59. }
  60. /**
  61. * @brief Retrieves the set of relevant statuses for the Entity
  62. * @return Reference to the StatusMask with the relevant statuses set to 1
  63. */
  64. RTPS_DllAPI const StatusMask& get_status_mask() const
  65. {
  66. return status_mask_;
  67. }
  68. /**
  69. * @brief Retrieves the instance handler that represents the Entity
  70. * @return Reference to the InstanceHandle
  71. */
  72. const fastrtps::rtps::InstanceHandle_t& get_instance_handle() const
  73. {
  74. return instance_handle_;
  75. }
  76. /**
  77. * @brief Checks if the Entity is enabled
  78. * @return true if enabled, false if not
  79. */
  80. RTPS_DllAPI bool is_enabled() const
  81. {
  82. return enable_;
  83. }
  84. RTPS_DllAPI bool operator ==(
  85. const Entity& other) const
  86. {
  87. return (this->instance_handle_ == other.instance_handle_);
  88. }
  89. protected:
  90. /**
  91. * @brief Setter for the Instance Handle
  92. * @param handle Instance Handle
  93. */
  94. RTPS_DllAPI void set_instance_handle(
  95. const fastrtps::rtps::InstanceHandle_t& handle)
  96. {
  97. instance_handle_ = handle;
  98. }
  99. //! StatusMask with relevant statuses set to 1
  100. StatusMask status_mask_;
  101. //! InstanceHandle associated to the Entity
  102. fastrtps::rtps::InstanceHandle_t instance_handle_;
  103. //! Boolean that states if the Entity is enabled or disabled
  104. bool enable_;
  105. };
  106. /**
  107. * @brief The DomainEntity class is a subclass of Entity created in order to differentiate between DomainParticipants
  108. * and the rest of Entities
  109. */
  110. class DomainEntity : public Entity
  111. {
  112. public:
  113. /**
  114. * @brief Constructor
  115. * @param mask StatusMask (default: all)
  116. */
  117. RTPS_DllAPI DomainEntity(
  118. const StatusMask& mask = StatusMask::all())
  119. : Entity(mask)
  120. {
  121. }
  122. };
  123. } // namespace dds
  124. } // namespace fastdds
  125. } // namespace eprosima
  126. #endif // _FASTDDS_ENTITY_HPP_