TopicAttributes.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 TopicAttributes.h
  16. */
  17. #ifndef TOPICPARAMETERS_H_
  18. #define TOPICPARAMETERS_H_
  19. #include <string>
  20. #include <fastdds/rtps/common/Types.h>
  21. #include <fastrtps/qos/QosPolicies.h>
  22. namespace eprosima {
  23. namespace fastrtps{
  24. /**
  25. * Class TopicAttributes, used by the user to define the attributes of the topic associated with a Publisher or Subscriber.
  26. * @ingroup FASTRTPS_ATTRIBUTES_MODULE
  27. */
  28. class TopicAttributes
  29. {
  30. public:
  31. /**
  32. * Default constructor
  33. */
  34. TopicAttributes()
  35. : topicKind(rtps::NO_KEY)
  36. , topicName("UNDEF")
  37. , topicDataType("UNDEF")
  38. , auto_fill_type_object(true)
  39. , auto_fill_type_information(true)
  40. {
  41. }
  42. //!Constructor, you need to provide the topic name and the topic data type.
  43. TopicAttributes(
  44. const char* name,
  45. const char* dataType,
  46. rtps::TopicKind_t tKind= rtps::NO_KEY)
  47. {
  48. topicKind = tKind;
  49. topicName = name;
  50. topicDataType = dataType;
  51. auto_fill_type_object = true;
  52. auto_fill_type_information = true;
  53. }
  54. virtual ~TopicAttributes() {}
  55. bool operator==(const TopicAttributes& b) const
  56. {
  57. return (this->topicKind == b.topicKind) &&
  58. (this->topicName == b.topicName) &&
  59. (this->topicDataType == b.topicDataType) &&
  60. (this->historyQos == b.historyQos);
  61. }
  62. /**
  63. * Get the topic data type
  64. * @return Topic data type
  65. */
  66. const string_255& getTopicDataType() const {
  67. return topicDataType;
  68. }
  69. /**
  70. * Get the topic kind
  71. * @return Topic kind
  72. */
  73. rtps::TopicKind_t getTopicKind() const {
  74. return topicKind;
  75. }
  76. /**
  77. * Get the topic name
  78. * @return Topic name
  79. */
  80. const string_255& getTopicName() const {
  81. return topicName;
  82. }
  83. //! TopicKind_t, default value NO_KEY.
  84. rtps::TopicKind_t topicKind;
  85. //! Topic Name.
  86. string_255 topicName;
  87. //!Topic Data Type.
  88. string_255 topicDataType;
  89. //!QOS Regarding the History to be saved.
  90. HistoryQosPolicy historyQos;
  91. //!QOS Regarding the resources to allocate.
  92. ResourceLimitsQosPolicy resourceLimitsQos;
  93. //!Type Identifier XTYPES 1.1
  94. TypeIdV1 type_id;
  95. //!Type Object XTYPES 1.1
  96. TypeObjectV1 type;
  97. //!XTYPES 1.2
  98. xtypes::TypeInformation type_information;
  99. //!Tries to complete type identifier and type object (TypeObjectV1)
  100. bool auto_fill_type_object;
  101. //!Tries to complete type information (TypeObjectV2)
  102. bool auto_fill_type_information;
  103. /**
  104. * Method to check whether the defined QOS are correct.
  105. * @return True if they are valid.
  106. */
  107. bool checkQos() const;
  108. };
  109. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  110. /**
  111. * Check if two topic attributes are not equal
  112. * @param t1 First instance of TopicAttributes to compare
  113. * @param t2 Second instance of TopicAttributes to compare
  114. * @return True if the instances are not equal. False if the instances are equal.
  115. */
  116. bool inline operator!=(const TopicAttributes& t1, const TopicAttributes& t2)
  117. {
  118. if(t1.topicKind != t2.topicKind
  119. || t1.topicName != t2.topicName
  120. || t1.topicDataType != t2.topicDataType
  121. || t1.historyQos.kind != t2.historyQos.kind
  122. || (t1.historyQos.kind == KEEP_LAST_HISTORY_QOS && t1.historyQos.depth != t2.historyQos.depth))
  123. {
  124. return true;
  125. }
  126. return false;
  127. }
  128. #endif
  129. } /* namespace fastrtps */
  130. } /* namespace eprosima */
  131. #endif /* TOPICPARAMETERS_H_ */