OpenDDS  Snapshot(2023/04/28-20:55)
DCPS_IR_Domain.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef DCPS_IR_DOMAIN_H
9 #define DCPS_IR_DOMAIN_H
10 
11 #include "inforepo_export.h"
12 
13 #include <dds/DdsDcpsInfrastructureC.h>
14 #include <dds/DdsDcpsDomainC.h>
15 #include <dds/DdsDcpsInfoUtilsC.h>
16 #include <dds/DCPS/InfoRepoDiscovery/InfoS.h>
17 #include <dds/DCPS/AtomicBool.h>
22 
23 #if !defined (DDS_HAS_MINIMUM_BIT)
24 #include <dds/DdsDcpsCoreTypeSupportImpl.h>
25 #endif // !defined (DDS_HAS_MINIMUM_BIT)
26 
27 #include <ace/Unbounded_Set.h>
28 
29 #include <set>
30 #include <map>
31 
32 #if !defined (ACE_LACKS_PRAGMA_ONCE)
33 #pragma once
34 #endif /* ACE_LACKS_PRAGMA_ONCE */
35 
37 
38 // forward declarations
40 typedef std::map<std::string,
42 
45 typedef std::set<DCPS_IR_Participant_rch > DCPS_IR_Participant_Set;
46 
47 typedef std::map<OpenDDS::DCPS::GUID_t,
50 
51 class DCPS_IR_Topic;
54 
55 /**
56  * @class DCPS_IR_Domain
57  *
58  * @brief Representation of a Domain in the system.
59  *
60  * This represents a Domain in the system. It contains the
61  * representatives of the entities that are in the corresponding
62  * system's domain.
63  */
65 : public OpenDDS::DCPS::RcObject {
66 public:
68 
69  ~DCPS_IR_Domain();
70 
71  /// Add the participant
72  /// Returns 0 if added, 1 if already exists, -1 other failure
73  int add_participant(DCPS_IR_Participant_rch participant);
74 
75  /// Remove the particpant
76  /// The participant has been deleted if returns successful.
77  /// Returns 0 if successful.
78  /// The notify_lost parameter is passed to the remove_associations()
79  /// See the comments of remove_associations() in DataWriterRemote.idl
80  /// or DataReaderRemote.idl.
81  int remove_participant(const OpenDDS::DCPS::GUID_t& particpantId,
82  CORBA::Boolean notify_lost);
83 
84  DCPS_IR_Participant_rch participant_rch(const OpenDDS::DCPS::GUID_t& id) const;
85 
86  /// Find the participant with the id.
87  DCPS_IR_Participant* participant(const OpenDDS::DCPS::GUID_t& id) const;
88 
89  ///@{
90  /// Add a topic to the domain
91  /// Returns OpenDDS::DCPS::CREATED if successful
92  OpenDDS::DCPS::TopicStatus add_topic(OpenDDS::DCPS::GUID_t_out topicId,
93  const char * topicName,
94  const char * dataTypeName,
95  const DDS::TopicQos & qos,
96  DCPS_IR_Participant* participantPtr);
97 
98  OpenDDS::DCPS::TopicStatus force_add_topic(const OpenDDS::DCPS::GUID_t& topicId,
99  const char* topicName,
100  const char* dataTypeName,
101  const DDS::TopicQos & qos,
102  DCPS_IR_Participant* participantPtr);
103  ///@}
104 
105  /// Find the topic with the topic name
106  /// Does NOT take ownership of any initial memory pointed to by topic
107  /// Returns OpenDDS::DCPS::FOUND if exists and topic is changed, -1 otherwise
108  OpenDDS::DCPS::TopicStatus find_topic(const char * topicName,
109  DCPS_IR_Topic*& topic);
110 
111  /// Find a topic object reference using the topic Id value.
112  DCPS_IR_Topic* find_topic(const OpenDDS::DCPS::GUID_t& id);
113 
114  /// Remove the topic
115  /// The topic has been deleted if returns successful
116  /// Returns OpenDDS::DCPS::REMOVED if successful
118  DCPS_IR_Topic*& topic);
119 
120  /// Remove the topic from the id to topic map.
121  /// This method should only be called by the DCPS_IR_Topic
122  /// when deleting the topic.
123  void remove_topic_id_mapping(const OpenDDS::DCPS::GUID_t& topicId);
124 
125  /// Mark a participant as being unresponsive (dead) and
126  /// schedule it to be removed next time
127  /// remove_dead_participants is called.
128  void add_dead_participant(DCPS_IR_Participant_rch participant);
129 
130  /// Remove any participants currently marked as dead
131  void remove_dead_participants(bool part_of_cleanup = false);
132 
133  DDS::DomainId_t get_id();
134 
135  /// Next Entity Id value in sequence.
136  OpenDDS::DCPS::GUID_t get_next_participant_id();
137 
138  /// Ensure no conflicts with sequence values from persistent storage.
139  void last_participant_key(long key);
140 
141  /// Initialize the Built-In Topic structures
142  /// This needs to be called before the run begins
143  /// Returns 0 (zero) if successful
144  int init_built_in_topics(bool federated, bool persistent);
145 
146  /// Cleans up the Built-In Topic structures
147  int cleanup_built_in_topics();
148 
149  /// Reassociate the Built-In Topic datawriters
150  /// This needs to be called after reincarnating from persistence and
151  /// before the run begins
152  /// Returns 0 (zero) if successful
153  int reassociate_built_in_topic_pubs();
154 
155  /// Publish Participant in the Participant Built-In Topic
156  void publish_participant_bit(DCPS_IR_Participant* participant);
157  /// Publish Topic in the Topic Built-In Topic
158  void publish_topic_bit(DCPS_IR_Topic* topic);
159  /// Publish Subscription in the Subscription Built-In Topic
160  void publish_subscription_bit(DCPS_IR_Subscription* subscription);
161  /// Publish Publication in the Publication Built-In Topic
162  void publish_publication_bit(DCPS_IR_Publication* publication);
163 
164  /// Dispose Participant in the Participant Built-In Topic
165  void dispose_participant_bit(DCPS_IR_Participant* participant);
166  /// Dispose Topic in the Topic Built-In Topic
167  void dispose_topic_bit(DCPS_IR_Topic* topic);
168  /// Dispose Subscription in the Subscription Built-In Topic
169  void dispose_subscription_bit(DCPS_IR_Subscription* subscription);
170  /// Dispose Publication in the Publication Built-In Topic
171  void dispose_publication_bit(DCPS_IR_Publication* publication);
172 
173  /// Expose a readable reference to the participant map.
174  const DCPS_IR_Participant_Map& participants() const;
175 
176  std::string dump_to_string(const std::string& prefix, int depth) const;
177 
178  bool useBIT() const { return useBIT_; }
179 
180 private:
182  const char * topicName,
183  const char * dataTypeName,
184  const DDS::TopicQos & qos,
185  DCPS_IR_Participant* participantPtr,
186  bool isBIT);
187 
188  /// Takes ownership of the memory pointed to by desc if successful
189  /// returns 0 if successful,
190  /// 1 if description already exists
191  /// -1 unknown error
192  /// 2 if confliciting dataTypeName
193  int add_topic_description(OpenDDS::DCPS::unique_ptr<DCPS_IR_Topic_Description> desc);
194 
195  /// Find the topic description with the name and data type name
196  /// Does NOT take ownership of any initial memory pointed to by desc
197  /// Returns 0 if found and desc is changed,
198  /// -1 if not found and 1 if conflicting dataTypeName
199  int find_topic_description(const char* name,
200  const char* dataTypeName,
202 
203  /// Returns 0 if successful
204  int remove_topic_description(DCPS_IR_Topic_Description* desc);
205 
206  ///@{
207  /**
208  * work of initializing the built in topics is
209  * done in these private methods. They were
210  * broken up for readability.
211  */
212  int init_built_in_topics_topics();
213  int init_built_in_topics_datawriters(bool federated);
214  int init_built_in_topics_transport(bool persistent);
215  ///@}
216 
218 
219  /// Participant GUID Id generator. The remaining Entities have their
220  /// values generated within the containing Participant.
222 
223  /// all the participants
224  DCPS_IR_Participant_Map participants_;
225 
226  /// the dead participants
227  /// dead participants exist in both this and participants_
229 
230  /// all the topics
232 
233  /// Mapping from GUID_t values to Topic object references.
234  typedef std::map<OpenDDS::DCPS::GUID_t,
237 
238  /// Actual mapping of Id values to Topic object references.
239  IdToTopicMap idToTopicMap_;
240 
241  /// indicates if the BuiltIn Topics are enabled
243 
244  ///@{
245  /// Built-in Topic variables
246  DDS::DomainParticipantFactory_var bitParticipantFactory_;
247  DDS::DomainParticipant_var bitParticipant_;
248  DDS::DomainParticipantListener_var bitParticipantListener_;
249  DDS::Publisher_var bitPublisher_;
250 
251 #if !defined (DDS_HAS_MINIMUM_BIT)
253 
254  DDS::Topic_var bitParticipantTopic_;
255  DDS::ParticipantBuiltinTopicDataDataWriter_var bitParticipantDataWriter_;
256 
257  DDS::Topic_var bitTopicTopic_;
258  DDS::TopicBuiltinTopicDataDataWriter_var bitTopicDataWriter_;
259 
260  DDS::Topic_var bitSubscriptionTopic_;
261  DDS::SubscriptionBuiltinTopicDataDataWriter_var bitSubscriptionDataWriter_;
262 
263  DDS::Topic_var bitPublicationTopic_;
264  DDS::PublicationBuiltinTopicDataDataWriter_var bitPublicationDataWriter_;
265 #endif // !defined (DDS_HAS_MINIMUM_BIT)
266  ///@}
267 
268  // MSVC 2017 has trouble to compile std::map<key, std::unique_ptr<Foo> > when it is enclosed
269  // by a DLL exported class whose copy constructor is not explicitly deleted
271 };
272 
274 
275 #endif /* DCPS_IR_DOMAIN_H */
DDS::DomainParticipant_var bitParticipant_
DDS::Publisher_var bitPublisher_
sequence< octet > key
DDS::Topic_var bitSubscriptionTopic_
OpenDDS::DCPS::AtomicBool useBIT_
indicates if the BuiltIn Topics are enabled
std::set< DCPS_IR_Participant_rch > DCPS_IR_Participant_Set
DDS::SubscriptionBuiltinTopicDataDataWriter_var bitSubscriptionDataWriter_
DDS::Topic_var bitParticipantTopic_
DCPS_IR_Participant_Set deadParticipants_
std::map< OpenDDS::DCPS::GUID_t, OpenDDS::DCPS::container_supported_unique_ptr< DCPS_IR_Topic >, OpenDDS::DCPS::GUID_tKeyLessThan > IdToTopicMap
Mapping from GUID_t values to Topic object references.
DCPS_IR_Topic_Description_Set topicDescriptions_
all the topics
#define OpenDDS_InfoRepoLib_Export
DDS::TopicBuiltinTopicDataDataWriter_var bitTopicDataWriter_
std::map< std::string, OpenDDS::DCPS::container_supported_unique_ptr< DCPS_IR_Topic_Description > > DCPS_IR_Topic_Description_Set
OpenDDS::DCPS::TransportConfig_rch transportConfig_
DCPS_IR_Participant_Map participants_
all the participants
DOMAINID_TYPE_NATIVE DomainId_t
DDS::Topic_var bitTopicTopic_
DDS::DomainParticipantFactory_var bitParticipantFactory_
ACE_CDR::Boolean Boolean
Representative of a Topic.
Definition: DCPS_IR_Topic.h:43
Representative of the Domain Participant.
Create RepoId values for use within DDS.
const char *const name
Definition: debug.cpp:60
OpenDDS::DCPS::RepoIdGenerator & participantIdGenerator_
DDS::Topic_var bitPublicationTopic_
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
Representative of a Subscription.
Representation of a Domain in the system.
DDS::ParticipantBuiltinTopicDataDataWriter_var bitParticipantDataWriter_
Representative of a Topic Description.
DDS::DomainId_t id_
IdToTopicMap idToTopicMap_
Actual mapping of Id values to Topic object references.
std::map< OpenDDS::DCPS::GUID_t, DCPS_IR_Participant_rch, OpenDDS::DCPS::GUID_tKeyLessThan > DCPS_IR_Participant_Map
Representative of a Publication.
DDS::PublicationBuiltinTopicDataDataWriter_var bitPublicationDataWriter_
bool useBIT() const
OpenDDS::DCPS::RcHandle< DCPS_IR_Participant > DCPS_IR_Participant_rch
DDS::DomainParticipantListener_var bitParticipantListener_