DomainParticipantFactory.hpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 DomainParticipantFactory.hpp
  16. *
  17. */
  18. #ifndef _FASTDDS_DOMAINPARTICIPANT_HPP_
  19. #define _FASTDDS_DOMAINPARTICIPANT_HPP_
  20. #include <fastrtps/attributes/ParticipantAttributes.h>
  21. #include <fastrtps/types/TypesBase.h>
  22. #include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
  23. #include <fastdds/dds/domain/qos/DomainParticipantFactoryQos.hpp>
  24. #include <fastdds/dds/core/status/StatusMask.hpp>
  25. #include <mutex>
  26. #include <map>
  27. using eprosima::fastrtps::types::ReturnCode_t;
  28. namespace eprosima {
  29. namespace fastdds {
  30. namespace dds {
  31. class DomainParticipantListener;
  32. class DomainParticipant;
  33. class DomainParticipantImpl;
  34. /**
  35. * Class DomainParticipantFactory
  36. * @ingroup FASTDDS_MODULE
  37. */
  38. class DomainParticipantFactory
  39. {
  40. public:
  41. /**
  42. * Returns the DomainParticipantFactory singleton.
  43. * @return The DomainParticipantFactory singleton.
  44. */
  45. RTPS_DllAPI static DomainParticipantFactory* get_instance();
  46. /**
  47. * Create a Participant.
  48. * @param domain_id Domain Id.
  49. * @param qos DomainParticipantQos Reference.
  50. * @param listener DomainParticipantListener Pointer (default: nullptr)
  51. * @param mask StatusMask Reference (default: all)
  52. * @return DomainParticipant pointer. (nullptr if not created.)
  53. */
  54. RTPS_DllAPI DomainParticipant* create_participant(
  55. DomainId_t domain_id,
  56. const DomainParticipantQos& qos,
  57. DomainParticipantListener* listener = nullptr,
  58. const StatusMask& mask = StatusMask::all());
  59. /**
  60. * Create a Participant.
  61. * @param domain_id Domain Id.
  62. * @param profile_name Participant profile name.
  63. * @param listener DomainParticipantListener Pointer (default: nullptr)
  64. * @param mask StatusMask Reference (default: all)
  65. * @return DomainParticipant pointer. (nullptr if not created.)
  66. */
  67. RTPS_DllAPI DomainParticipant* create_participant_with_profile(
  68. DomainId_t domain_id,
  69. const std::string& profile_name,
  70. DomainParticipantListener* listener = nullptr,
  71. const StatusMask& mask = StatusMask::all());
  72. /**
  73. * This operation retrieves a previously created DomainParticipant belonging to specified domain_id.
  74. * If no such DomainParticipant exists, the operation will return 'nullptr'.
  75. * If multiple DomainParticipant entities belonging to that domain_id exist,
  76. * then the operation will return one of them. It is not specified which one.
  77. * @param domain_id
  78. * @return previously created DomainParticipant within the specified domain
  79. */
  80. RTPS_DllAPI DomainParticipant* lookup_participant(
  81. DomainId_t domain_id) const;
  82. /**
  83. * Returns all participants that belongs to the specified domain_id.
  84. * @param domain_id
  85. * @return previously created DomainParticipants within the specified domain
  86. */
  87. RTPS_DllAPI std::vector<DomainParticipant*> lookup_participants(
  88. DomainId_t domain_id) const;
  89. /**
  90. * @brief This operation retrieves the default value of the DomainParticipant QoS, that is, the QoS policies which will
  91. * be used for newly created DomainParticipant entities in the case where the QoS policies are defaulted in the
  92. * create_participant operation.
  93. * The values retrieved get_default_participant_qos will match the set of values specified on the last successful call
  94. * to set_default_participant_qos, or else, if the call was never made, the default values.
  95. * @param qos DomainParticipantQos where the qos is returned
  96. * @return RETCODE_OK
  97. */
  98. RTPS_DllAPI ReturnCode_t get_default_participant_qos(
  99. DomainParticipantQos& qos) const;
  100. /**
  101. * @brief This operation retrieves the default value of the DomainParticipant QoS, that is, the QoS policies which will
  102. * be used for newly created DomainParticipant entities in the case where the QoS policies are defaulted in the
  103. * create_participant operation.
  104. * The values retrieved get_default_participant_qos will match the set of values specified on the last successful call
  105. * to set_default_participant_qos, or else, if the call was never made, the default values.
  106. * @return A reference to the default DomainParticipantQos
  107. */
  108. RTPS_DllAPI const DomainParticipantQos& get_default_participant_qos() const;
  109. /**
  110. * @brief This operation sets a default value of the DomainParticipant QoS policies which will be used for
  111. * newly created DomainParticipant entities in the case where the QoS policies are defaulted in the
  112. * create_participant operation.
  113. *
  114. * This operation will check that the resulting policies are self consistent; if they are not, the operation
  115. * will have no effect and return INCONSISTENT_POLICY.
  116. *
  117. * The special value PARTICIPANT_QOS_DEFAULT may be passed to this operation to indicate that the default
  118. * QoS should be reset back to the initial values the factory would use, that is the values that would be
  119. * used if the set_default_participant_qos operation had never been called.
  120. *
  121. * @param qos DomainParticipantQos to be set
  122. * @return RETCODE_INCONSISTENT_POLICY if the Qos is not self consistent and RETCODE_OK if the qos is changed correctly.
  123. */
  124. RTPS_DllAPI ReturnCode_t set_default_participant_qos(
  125. const DomainParticipantQos& qos);
  126. /**
  127. * Remove a Participant and all associated publishers and subscribers.
  128. * @param part Pointer to the participant.
  129. * @return RETCODE_PRECONDITION_NOT_MET if the participant has active entities, RETCODE_OK if the participant is correctly
  130. * deleted and RETCODE_ERROR otherwise.
  131. */
  132. RTPS_DllAPI ReturnCode_t delete_participant(
  133. DomainParticipant* part);
  134. /**
  135. * Load profiles from default XML file.
  136. * @return RETCODE_OK
  137. */
  138. RTPS_DllAPI ReturnCode_t load_profiles();
  139. /**
  140. * Load profiles from XML file.
  141. * @param xml_profile_file XML profile file.
  142. * @return RETCODE_OK if it is correctly loaded, RETCODE_ERROR otherwise.
  143. */
  144. RTPS_DllAPI ReturnCode_t load_XML_profiles_file(
  145. const std::string& xml_profile_file);
  146. /**
  147. * This operation returns the value of the DomainParticipantFactory QoS policies.
  148. * @param qos DomaParticipantFactoryQos reference where the qos is returned
  149. * @return RETCODE_OK
  150. */
  151. RTPS_DllAPI ReturnCode_t get_qos(
  152. DomainParticipantFactoryQos& qos) const;
  153. /**
  154. * This operation sets the value of the DomainParticipantFactory QoS policies. These policies
  155. * control the behavior of the object a factory for entities.
  156. *
  157. * Note that despite having QoS, the DomainParticipantFactory is not an Entity.
  158. *
  159. * This operation will check that the resulting policies are self consistent; if they are not,
  160. * the operation will have no effect and return INCONSISTENT_POLICY.
  161. * @param qos DomainParticipantFactoryQos to be set.
  162. * @return RETCODE_IMMUTABLE_POLICY if any of the Qos cannot be changed, RETCODE_INCONSISTENT_POLICY if the Qos is not
  163. * self consistent and RETCODE_OK if the qos is changed correctly.
  164. */
  165. RTPS_DllAPI ReturnCode_t set_qos(
  166. const DomainParticipantFactoryQos& qos);
  167. private:
  168. friend class DomainParticipantFactoryReleaser;
  169. friend class DomainParticipant;
  170. std::map<DomainId_t, std::vector<DomainParticipantImpl*> > participants_;
  171. DomainParticipantFactory();
  172. virtual ~DomainParticipantFactory();
  173. void reset_default_participant_qos();
  174. static bool delete_instance();
  175. static void set_qos(
  176. DomainParticipantFactoryQos& to,
  177. const DomainParticipantFactoryQos& from,
  178. bool first_time);
  179. static ReturnCode_t check_qos(
  180. const DomainParticipantFactoryQos& qos);
  181. static bool can_qos_be_updated(
  182. const DomainParticipantFactoryQos& to,
  183. const DomainParticipantFactoryQos& from);
  184. void participant_has_been_deleted(
  185. DomainParticipantImpl* part);
  186. mutable std::mutex mtx_participants_;
  187. mutable bool default_xml_profiles_loaded;
  188. DomainParticipantFactoryQos factory_qos_;
  189. DomainParticipantQos default_participant_qos_;
  190. };
  191. } /* namespace dds */
  192. } /* namespace fastdds */
  193. } /* namespace eprosima */
  194. #endif /* _FASTDDS_DOMAINPARTICIPANT_HPP_*/