Domain.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 Domain.h
  16. *
  17. */
  18. #ifndef DOMAIN_H_
  19. #define DOMAIN_H_
  20. #include <fastdds/dds/topic/TopicDataType.hpp>
  21. #include <fastrtps/attributes/ParticipantAttributes.h>
  22. #include <mutex>
  23. #ifdef USE_DEPRECATION
  24. #if defined(__GNUC__) || defined(__clang__)
  25. #define DEPRECATED __attribute__ ((deprecated))
  26. #elif defined(_MSC_VER)
  27. #define DEPRECATED __declspec(deprecated)
  28. #else
  29. #define DEPRECATED /** --Deprecated-- */
  30. #endif
  31. #else
  32. #define DEPRECATED
  33. #endif
  34. namespace eprosima{
  35. namespace fastrtps{
  36. class ParticipantListener;
  37. class Participant;
  38. class ParticipantImpl;
  39. class Publisher;
  40. class PublisherAttributes;
  41. class PublisherListener;
  42. class Subscriber;
  43. class SubscriberAttributes;
  44. class SubscriberListener;
  45. namespace types{
  46. class DynamicPubSubType;
  47. }
  48. /**
  49. * Class Domain, use to interact with the Publisher Subscriber API of the Fast RTPS implementation.
  50. * @ingroup FASTRTPS_MODULE
  51. */
  52. class Domain
  53. {
  54. public:
  55. /**
  56. * Create a Participant from a profile name.
  57. * @param participant_profile Participant profile name.
  58. * @param listen ParticipantListener Pointer.
  59. * @return Participant pointer. (nullptr if not created.)
  60. */
  61. RTPS_DllAPI DEPRECATED static Participant* createParticipant(
  62. const std::string& participant_profile,
  63. ParticipantListener* listen = nullptr);
  64. /**
  65. * Create a Participant.
  66. * @param att Participant Attributes.
  67. * @param listen ParticipantListener Pointer.
  68. * @return Participant pointer. (nullptr if not created.)
  69. */
  70. RTPS_DllAPI DEPRECATED static Participant* createParticipant(
  71. const ParticipantAttributes& att,
  72. ParticipantListener* listen = nullptr);
  73. //!Fills participant_attributes with the default values.
  74. RTPS_DllAPI static void getDefaultParticipantAttributes(ParticipantAttributes& participant_attributes);
  75. /**
  76. * Create a Publisher in a Participant from a profile name.
  77. * @param part Pointer to the participant where you want to create the Publisher.
  78. * @param publisher_profile Publisher profile name.
  79. * @param listen Pointer to the PublisherListener.
  80. * @return Pointer to the created Publisher (nullptr if not created).
  81. */
  82. RTPS_DllAPI static Publisher* createPublisher(
  83. Participant* part,
  84. const std::string& publisher_profile,
  85. PublisherListener* listen = nullptr);
  86. /**
  87. * Create a Publisher in a Participant.
  88. * @param part Pointer to the participant where you want to create the Publisher.
  89. * @param att PublisherAttributes.
  90. * @param listen Pointer to the PublisherListener.
  91. * @return Pointer to the created Publisher (nullptr if not created).
  92. */
  93. RTPS_DllAPI static Publisher* createPublisher(
  94. Participant* part,
  95. const PublisherAttributes& att,
  96. PublisherListener* listen = nullptr);
  97. //!Fills publisher_attributes with the default values.
  98. RTPS_DllAPI static void getDefaultPublisherAttributes(PublisherAttributes& publisher_attributes);
  99. /**
  100. * Create a Subscriber in a Participant from a profile name.
  101. * @param part Pointer to the participant where you want to create the Publisher.
  102. * @param subscriber_profile Subscriber profile name.
  103. * @param listen Pointer to the SubscriberListener.
  104. * @return Pointer to the created Subscriber (nullptr if not created).
  105. */
  106. RTPS_DllAPI static Subscriber* createSubscriber(
  107. Participant* part,
  108. const std::string& subscriber_profile,
  109. SubscriberListener* listen = nullptr);
  110. /**
  111. * Create a Subscriber in a Participant.
  112. * @param part Pointer to the participant where you want to create the Publisher.
  113. * @param att SubscriberAttributes.
  114. * @param listen Pointer to the SubscriberListener.
  115. * @return Pointer to the created Subscriber (nullptr if not created).
  116. */
  117. RTPS_DllAPI static Subscriber* createSubscriber(
  118. Participant* part,
  119. const SubscriberAttributes& att,
  120. SubscriberListener* listen = nullptr);
  121. //!Fills subscriber_attributes with the default values.
  122. RTPS_DllAPI static void getDefaultSubscriberAttributes(SubscriberAttributes& subscriber_attributes);
  123. /**
  124. * Remove a Participant and all associated publishers and subscribers.
  125. * @param part Pointer to the participant.
  126. * @return True if correctly removed.
  127. */
  128. RTPS_DllAPI static bool removeParticipant(Participant* part);
  129. /**
  130. * Remove a Publisher.
  131. * @param pub Pointer to the Publisher.
  132. * @return True if correctly removed.
  133. */
  134. RTPS_DllAPI static bool removePublisher(Publisher* pub);
  135. /**
  136. * Remove a Subscriber.
  137. * @param sub Pointer to the Subscriber.
  138. * @return True if correctly removed.
  139. */
  140. RTPS_DllAPI static bool removeSubscriber(Subscriber* sub);
  141. /**
  142. * Return a registered type.
  143. * @param part Pointer to the Participant.
  144. * @param typeName Name of the type.
  145. * @param type Returned type.
  146. * @return True if type was found.
  147. */
  148. RTPS_DllAPI static bool getRegisteredType(
  149. Participant* part,
  150. const char* typeName,
  151. fastdds::dds::TopicDataType** type);
  152. /**
  153. * Register a type in a participant.
  154. * @param part Pointer to the Participant.
  155. * @param type Pointer to the Type.
  156. * @return True if correctly registered.
  157. */
  158. RTPS_DllAPI static bool registerType(
  159. Participant* part,
  160. fastdds::dds::TopicDataType * type);
  161. /**
  162. * Register a type in a participant.
  163. * @param part Pointer to the Participant.
  164. * @param type Pointer to the Type.
  165. * @return True if correctly registered.
  166. */
  167. RTPS_DllAPI static bool registerDynamicType(
  168. Participant* part,
  169. types::DynamicPubSubType* type);
  170. /**
  171. * Unregister a type in a participant.
  172. * @param part Pointer to the Participant.
  173. * @param typeName Name of the type.
  174. * @return True if correctly unregistered.
  175. */
  176. RTPS_DllAPI static bool unregisterType(
  177. Participant* part,
  178. const char* typeName);
  179. /**
  180. * Stop and remove all participants, publishers and subscribers in this Domain.
  181. */
  182. RTPS_DllAPI static void stopAll();
  183. /**
  184. * Load profiles from XML file.
  185. * @param xml_profile_file XML profile file.
  186. * @return True if correctly loaded.
  187. */
  188. RTPS_DllAPI static bool loadXMLProfilesFile(const std::string& xml_profile_file);
  189. private:
  190. typedef std::pair<Participant*,ParticipantImpl*> t_p_Participant;
  191. Domain();
  192. virtual ~Domain();
  193. static std::mutex m_mutex;
  194. static std::vector<t_p_Participant> m_participants;
  195. static bool default_xml_profiles_loaded;
  196. };
  197. } /* namespace */
  198. } /* namespace eprosima */
  199. #endif /* DOMAIN_H_ */