DCPS_IR_Domain.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef DCPS_IR_DOMAIN_H
00009 #define DCPS_IR_DOMAIN_H
00010 
00011 #include  "inforepo_export.h"
00012 #include /**/ "dds/DdsDcpsInfrastructureC.h"
00013 #include /**/ "dds/DCPS/InfoRepoDiscovery/InfoS.h"
00014 
00015 #include "dds/DCPS/RepoIdGenerator.h"
00016 
00017 #include /**/ "dds/DdsDcpsDomainC.h"
00018 #include /**/ "dds/DdsDcpsInfoUtilsC.h"
00019 
00020 #if !defined (DDS_HAS_MINIMUM_BIT)
00021 #include /**/ "dds/DdsDcpsCoreTypeSupportImpl.h"
00022 #endif // !defined (DDS_HAS_MINIMUM_BIT)
00023 
00024 #include "dds/DCPS/transport/framework/TransportConfig.h"
00025 #include "dds/DCPS/transport/tcp/TcpTransport.h"
00026 #include "dds/DCPS/transport/framework/TransportConfig_rch.h"
00027 #include /**/ "ace/Unbounded_Set.h"
00028 
00029 #include <set>
00030 #include <map>
00031 
00032 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00033 #pragma once
00034 #endif /* ACE_LACKS_PRAGMA_ONCE */
00035 
00036 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00037 
00038 // forward declarations
00039 class DCPS_IR_Topic_Description;
00040 typedef std::map<std::string,
00041                  OpenDDS::DCPS::container_supported_unique_ptr<DCPS_IR_Topic_Description> > DCPS_IR_Topic_Description_Set;
00042 
00043 class DCPS_IR_Participant;
00044 typedef OpenDDS::DCPS::RcHandle<DCPS_IR_Participant> DCPS_IR_Participant_rch;
00045 typedef std::set<DCPS_IR_Participant_rch > DCPS_IR_Participant_Set;
00046 
00047 typedef std::map<OpenDDS::DCPS::RepoId,
00048                  DCPS_IR_Participant_rch ,
00049                  OpenDDS::DCPS::GUID_tKeyLessThan> DCPS_IR_Participant_Map;
00050 
00051 class DCPS_IR_Topic;
00052 class DCPS_IR_Subscription;
00053 class DCPS_IR_Publication;
00054 
00055 /**
00056  * @class DCPS_IR_Domain
00057  *
00058  * @brief Representation of a Domain in the system.
00059  *
00060  * This represents a Domain in the system.  It contains the
00061  * representatives of the entities that are in the corresponding
00062  * system's domain.
00063  */
00064 class OpenDDS_InfoRepoLib_Export DCPS_IR_Domain
00065 : public OpenDDS::DCPS::EnableContainerSupportedUniquePtr<DCPS_IR_Domain>{
00066 public:
00067   DCPS_IR_Domain(DDS::DomainId_t id, OpenDDS::DCPS::RepoIdGenerator& generator);
00068 
00069   ~DCPS_IR_Domain();
00070 
00071   /// Add the participant
00072   /// Returns 0 if added, 1 if already exists, -1 other failure
00073   int add_participant(DCPS_IR_Participant_rch participant);
00074 
00075   /// Remove the particpant
00076   /// The participant has been deleted if returns successful.
00077   /// Returns 0 if successful.
00078   /// The notify_lost parameter is passed to the remove_associations()
00079   /// See the comments of remove_associations() in DataWriterRemote.idl
00080   /// or DataReaderRemote.idl.
00081   int remove_participant(const OpenDDS::DCPS::RepoId& particpantId,
00082                          CORBA::Boolean    notify_lost);
00083 
00084   /// Find the participant with the id.
00085   DCPS_IR_Participant* participant(const OpenDDS::DCPS::RepoId& id) const;
00086 
00087   ///@{
00088   /// Add a topic to the domain
00089   /// Returns OpenDDS::DCPS::CREATED if successfull
00090   OpenDDS::DCPS::TopicStatus add_topic(OpenDDS::DCPS::RepoId_out topicId,
00091                                        const char * topicName,
00092                                        const char * dataTypeName,
00093                                        const DDS::TopicQos & qos,
00094                                        DCPS_IR_Participant* participantPtr);
00095 
00096   OpenDDS::DCPS::TopicStatus force_add_topic(const OpenDDS::DCPS::RepoId& topicId,
00097                                              const char* topicName,
00098                                              const char* dataTypeName,
00099                                              const DDS::TopicQos & qos,
00100                                              DCPS_IR_Participant* participantPtr);
00101   ///@}
00102 
00103   /// Find the topic with the topic name
00104   /// Does NOT take ownership of any initial memory pointed to by topic
00105   /// Returns OpenDDS::DCPS::FOUND if exists and topic is changed, -1 otherwise
00106   OpenDDS::DCPS::TopicStatus find_topic(const char * topicName,
00107                                         DCPS_IR_Topic*& topic);
00108 
00109   /// Find a topic object reference using the topic Id value.
00110   DCPS_IR_Topic* find_topic(const OpenDDS::DCPS::RepoId& id);
00111 
00112   /// Remove the topic
00113   /// The topic has been deleted if returns successful
00114   /// Returns OpenDDS::DCPS::REMOVED if successful
00115   OpenDDS::DCPS::TopicStatus remove_topic(DCPS_IR_Participant* part,
00116                                           DCPS_IR_Topic*& topic);
00117 
00118   /// Remove the topic from the id to topic map.
00119   /// This method should only be called by the DCPS_IR_Topic
00120   /// when deleting the topic.
00121   void remove_topic_id_mapping(const OpenDDS::DCPS::RepoId& topicId);
00122 
00123   /// Mark a participant as being unresponsive (dead) and
00124   ///  schedule it to be removed next time
00125   ///  remove_dead_participants is called.
00126   void add_dead_participant(DCPS_IR_Participant_rch participant);
00127 
00128   /// Remove any participants currently marked as dead
00129   void remove_dead_participants();
00130 
00131   DDS::DomainId_t get_id();
00132 
00133   /// Next Entity Id value in sequence.
00134   OpenDDS::DCPS::RepoId get_next_participant_id();
00135 
00136   /// Ensure no conflicts with sequence values from persistent storage.
00137   void last_participant_key(long key);
00138 
00139   /// Initialize the Built-In Topic structures
00140   /// This needs to be called before the run begins
00141   /// Returns 0 (zero) if successful
00142   int init_built_in_topics(bool federated, bool persistent);
00143 
00144   /// Cleans up the Built-In Topic structures
00145   int cleanup_built_in_topics();
00146 
00147   /// Reassociate the Built-In Topic datawriters
00148   /// This needs to be called after reincarnating from persistence and
00149   /// before the run begins
00150   /// Returns 0 (zero) if successful
00151   int reassociate_built_in_topic_pubs();
00152 
00153   /// Publish Participant in the Participant Built-In Topic
00154   void publish_participant_bit(DCPS_IR_Participant* participant);
00155   /// Publish Topic in the Topic Built-In Topic
00156   void publish_topic_bit(DCPS_IR_Topic* topic);
00157   /// Publish Subscription in the Subscription Built-In Topic
00158   void publish_subscription_bit(DCPS_IR_Subscription* subscription);
00159   /// Publish Publication in the Publication Built-In Topic
00160   void publish_publication_bit(DCPS_IR_Publication* publication);
00161 
00162   /// Dispose Participant in the Participant Built-In Topic
00163   void dispose_participant_bit(DCPS_IR_Participant* participant);
00164   /// Dispose Topic in the Topic Built-In Topic
00165   void dispose_topic_bit(DCPS_IR_Topic* topic);
00166   /// Dispose Subscription in the Subscription Built-In Topic
00167   void dispose_subscription_bit(DCPS_IR_Subscription* subscription);
00168   /// Dispose Publication in the Publication Built-In Topic
00169   void dispose_publication_bit(DCPS_IR_Publication* publication);
00170 
00171   /// Expose a readable reference to the participant map.
00172   const DCPS_IR_Participant_Map& participants() const;
00173 
00174   std::string dump_to_string(const std::string& prefix, int depth) const;
00175 
00176   bool useBIT() const { return useBIT_; }
00177 
00178 private:
00179   OpenDDS::DCPS::TopicStatus add_topic_i(OpenDDS::DCPS::RepoId& topicId,
00180                                          const char * topicName,
00181                                          const char * dataTypeName,
00182                                          const DDS::TopicQos & qos,
00183                                          DCPS_IR_Participant* participantPtr,
00184                                          bool isBIT);
00185 
00186   /// Takes ownership of the memory pointed to by desc if successful
00187   /// returns 0 if successful,
00188   /// 1 if description already exists
00189   /// -1 unknown error
00190   /// 2 if confliciting dataTypeName
00191   int add_topic_description(OpenDDS::DCPS::unique_ptr<DCPS_IR_Topic_Description> desc);
00192 
00193   /// Find the topic description with the name and data type name
00194   /// Does NOT take ownership of any initial memory pointed to by desc
00195   /// Returns 0 if found and desc is changed,
00196   ///  -1 if not found and 1 if conflicting dataTypeName
00197   int find_topic_description(const char* name,
00198                              const char* dataTypeName,
00199                              DCPS_IR_Topic_Description*& desc);
00200 
00201   /// Returns 0 if successful
00202   int remove_topic_description(DCPS_IR_Topic_Description* desc);
00203 
00204   ///@{
00205   /**
00206    * work of initializing the built in topics is
00207    * done in these private methods.  They were
00208    * broken up for readability.
00209    */
00210   int init_built_in_topics_topics();
00211   int init_built_in_topics_datawriters(bool federated);
00212   int init_built_in_topics_transport(bool persistent);
00213   ///@}
00214 
00215   DDS::DomainId_t id_;
00216 
00217   /// Participant GUID Id generator.  The remaining Entities have their
00218   /// values generated within the containing Participant.
00219   OpenDDS::DCPS::RepoIdGenerator& participantIdGenerator_;
00220 
00221   /// all the participants
00222   DCPS_IR_Participant_Map participants_;
00223 
00224   /// the dead participants
00225   /// dead participants exist in both this and participants_
00226   DCPS_IR_Participant_Set deadParticipants_;
00227 
00228   /// all the topics
00229   DCPS_IR_Topic_Description_Set topicDescriptions_;
00230 
00231   /// Mapping from RepoId values to Topic object references.
00232   typedef std::map<OpenDDS::DCPS::RepoId,
00233                    OpenDDS::DCPS::container_supported_unique_ptr<DCPS_IR_Topic>,
00234                    OpenDDS::DCPS::GUID_tKeyLessThan> IdToTopicMap;
00235 
00236   /// Actual mapping of Id values to Topic object references.
00237   IdToTopicMap idToTopicMap_;
00238 
00239   /// indicates if the BuiltIn Topics are enabled
00240   bool useBIT_;
00241 
00242   ///@{
00243   /// Built-in Topic variables
00244   DDS::DomainParticipantFactory_var                bitParticipantFactory_;
00245   DDS::DomainParticipant_var                       bitParticipant_;
00246   DDS::DomainParticipantListener_var               bitParticipantListener_;
00247   DDS::Publisher_var                               bitPublisher_;
00248 
00249 #if !defined (DDS_HAS_MINIMUM_BIT)
00250   OpenDDS::DCPS::TransportConfig_rch               transportConfig_;
00251 
00252   DDS::Topic_var                                   bitParticipantTopic_;
00253   DDS::ParticipantBuiltinTopicDataDataWriter_var   bitParticipantDataWriter_;
00254 
00255   DDS::Topic_var                                   bitTopicTopic_;
00256   DDS::TopicBuiltinTopicDataDataWriter_var         bitTopicDataWriter_;
00257 
00258   DDS::Topic_var                                   bitSubscriptionTopic_;
00259   DDS::SubscriptionBuiltinTopicDataDataWriter_var  bitSubscriptionDataWriter_;
00260 
00261   DDS::Topic_var                                   bitPublicationTopic_;
00262   DDS::PublicationBuiltinTopicDataDataWriter_var   bitPublicationDataWriter_;
00263 #endif // !defined (DDS_HAS_MINIMUM_BIT)
00264   ///@}
00265 
00266   // MSVC 2017 has trouble to compile std::map<key, std::unique_ptr<Foo> > when it is enclosed
00267   // by a DLL exported class whose copy constructor is not explicitly deleted
00268   DCPS_IR_Domain(const DCPS_IR_Domain&);
00269 };
00270 
00271 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00272 
00273 #endif /* DCPS_IR_DOMAIN_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1