LivelinessData.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2016-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 LivelinessData.h
  16. */
  17. #ifndef _FASTDDS_RTPS_LIVELINESS_DATA_H_
  18. #define _FASTDDS_RTPS_LIVELINESS_DATA_H_
  19. #include <fastrtps/qos/QosPolicies.h>
  20. #include <fastdds/rtps/common/Time_t.h>
  21. #include <chrono>
  22. namespace eprosima {
  23. namespace fastrtps {
  24. namespace rtps {
  25. /**
  26. * @brief A struct keeping relevant liveliness information of a writer
  27. * @ingroup WRITER_MODULE
  28. */
  29. struct LivelinessData
  30. {
  31. enum WriterStatus
  32. {
  33. //! Writer is matched but liveliness has not been asserted yet
  34. NOT_ASSERTED = 0,
  35. //! Writer is alive
  36. ALIVE = 1,
  37. //! Writer is not alive
  38. NOT_ALIVE = 2
  39. };
  40. /**
  41. * @brief Constructor
  42. * @param guid_in GUID of the writer
  43. * @param kind_in Liveliness kind
  44. * @param lease_duration_in Liveliness lease duration
  45. */
  46. LivelinessData(
  47. GUID_t guid_in,
  48. LivelinessQosPolicyKind kind_in,
  49. Duration_t lease_duration_in)
  50. : guid(guid_in)
  51. , kind(kind_in)
  52. , lease_duration(lease_duration_in)
  53. , status(WriterStatus::NOT_ASSERTED)
  54. {}
  55. LivelinessData()
  56. : guid()
  57. , kind(LivelinessQosPolicyKind::AUTOMATIC_LIVELINESS_QOS)
  58. , lease_duration(TIME_T_INFINITE_SECONDS, TIME_T_INFINITE_NANOSECONDS)
  59. , status(WriterStatus::NOT_ASSERTED)
  60. {}
  61. ~LivelinessData()
  62. {}
  63. /**
  64. * @brief Equality operator
  65. * @param other Liveliness data to compare to
  66. * @return True if equal
  67. */
  68. bool operator==(
  69. const LivelinessData& other) const
  70. {
  71. return ((guid == other.guid) &&
  72. (kind == other.kind) &&
  73. (lease_duration == other.lease_duration));
  74. }
  75. /**
  76. * @brief Inequality operator
  77. * @param other Liveliness data to compare to
  78. * @return True if different
  79. */
  80. bool operator!=(
  81. const LivelinessData& other) const
  82. {
  83. return (!operator==(other));
  84. }
  85. //! GUID of the writer
  86. GUID_t guid;
  87. //! Writer liveliness kind
  88. LivelinessQosPolicyKind kind;
  89. //! The lease duration
  90. Duration_t lease_duration;
  91. //! The number of times the writer is being counted
  92. unsigned int count = 1;
  93. //! The writer status
  94. WriterStatus status;
  95. //! The time when the writer will lose liveliness
  96. std::chrono::steady_clock::time_point time;
  97. };
  98. } /* namespace rtps */
  99. } /* namespace fastrtps */
  100. } /* namespace eprosima */
  101. #endif /* _FASTDDS_RTPS_LIVELINESS_DATA_H_ */