00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #ifndef DCPS_IR_TOPIC_H 00009 #define DCPS_IR_TOPIC_H 00010 00011 #include "inforepo_export.h" 00012 #include /**/ "dds/DdsDcpsInfrastructureC.h" 00013 #include /**/ "dds/DdsDcpsTopicC.h" 00014 #include /**/ "dds/DCPS/InfoRepoDiscovery/InfoC.h" 00015 #include /**/ "ace/Unbounded_Set.h" 00016 #include "dds/DCPS/unique_ptr.h" 00017 #include <string> 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 #pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 00024 00025 // forward declarations 00026 class DCPS_IR_Publication; 00027 typedef ACE_Unbounded_Set<DCPS_IR_Publication*> DCPS_IR_Publication_Set; 00028 00029 class DCPS_IR_Subscription; 00030 typedef ACE_Unbounded_Set<DCPS_IR_Subscription*> DCPS_IR_Subscription_Set; 00031 00032 class DCPS_IR_Domain; 00033 class DCPS_IR_Participant; 00034 class DCPS_IR_Topic_Description; 00035 class DCPS_IR_Subscription; 00036 00037 /** 00038 * @class DCPS_IR_Topic 00039 * 00040 * @brief Representative of a Topic 00041 * 00042 */ 00043 class OpenDDS_InfoRepoLib_Export DCPS_IR_Topic 00044 : public OpenDDS::DCPS::EnableContainerSupportedUniquePtr<DCPS_IR_Topic> 00045 { 00046 public: 00047 DCPS_IR_Topic(const OpenDDS::DCPS::RepoId& id, 00048 const DDS::TopicQos& qos, 00049 DCPS_IR_Domain* domain, 00050 DCPS_IR_Participant* creator, 00051 DCPS_IR_Topic_Description* description, 00052 bool isBIT); 00053 00054 ~DCPS_IR_Topic(); 00055 00056 /// Delete the topic object upon last topic associated sub/pub and topic 00057 /// object deletion. It's kind of reference counting. 00058 /// The removing true indicates it's called upon delete_topic, otherwise 00059 /// it's upon remove_publication/remove_subcription. 00060 void release(bool removing); 00061 00062 /// Adds the publication to the list of publications 00063 /// Calls the topic description's try associate if successfully added 00064 /// 'associate' switch toggles association attempt. 00065 /// Returns 0 if added, 1 if already exists, -1 other failure 00066 int add_publication_reference(DCPS_IR_Publication* publication 00067 , bool associate = true); 00068 00069 /// Removes the publication from the list of publications 00070 /// Returns 0 if successful 00071 int remove_publication_reference(DCPS_IR_Publication* publication); 00072 00073 /// Adds the subscription to the list of subscriptions 00074 /// and let description handle the association. 00075 /// Returns 0 if added, 1 if already exists, -1 other failure 00076 int add_subscription_reference(DCPS_IR_Subscription* subscription 00077 , bool associate = true); 00078 00079 /// Removes the subscription from the list of subscriptions 00080 /// Returns 0 if successful 00081 int remove_subscription_reference(DCPS_IR_Subscription* subscription); 00082 00083 /// Called by the DCPS_IR_Topic_Description 00084 /// Find any compatible publications and associate 00085 /// them using the DCPS_IR_Topic_Description's 00086 /// associate method. 00087 /// This method does not check the subscription's incompatible 00088 /// qos status. 00089 void try_associate(DCPS_IR_Subscription* subscription); 00090 00091 /// Called by the DCPS_IR_Topic_Description to re-evaluate the 00092 /// association between the publications of this topic and the 00093 /// provided subscription. 00094 void reevaluate_associations(DCPS_IR_Subscription* subscription); 00095 00096 OpenDDS::DCPS::RepoId get_id() const; 00097 OpenDDS::DCPS::RepoId get_participant_id() const; 00098 00099 /// Return pointer to the Topic Description 00100 /// Domain retains ownership 00101 DCPS_IR_Topic_Description* get_topic_description(); 00102 00103 /// Return pointer to the Topic qos 00104 /// Topic retains ownership 00105 DDS::TopicQos * get_topic_qos(); 00106 00107 /// Reset topic qos and also propagate the qos change to related BITs 00108 /// that has the qos copy. 00109 /// Return false if the provided QoS makes the DataWriter and DataReader 00110 /// QoS incompatible. Currently supported changeable QoS in TopicQos do 00111 /// not affect. 00112 bool set_topic_qos(const DDS::TopicQos& qos); 00113 00114 DDS::InstanceHandle_t get_handle(); 00115 void set_handle(DDS::InstanceHandle_t handle); 00116 00117 CORBA::Boolean is_bit(); 00118 void set_bit_status(CORBA::Boolean isBIT); 00119 00120 /// Try to associate all the current publications. 00121 /// This is used to reconnect Built in Topics after a persistent restart. 00122 void reassociate_all_publications(); 00123 00124 std::string dump_to_string(const std::string& prefix, int depth) const; 00125 00126 private: 00127 OpenDDS::DCPS::RepoId id_; 00128 DDS::TopicQos qos_; 00129 DCPS_IR_Domain* domain_; 00130 DCPS_IR_Participant* participant_; 00131 DCPS_IR_Topic_Description* description_; 00132 DDS::InstanceHandle_t handle_; 00133 CORBA::Boolean isBIT_; 00134 00135 DCPS_IR_Publication_Set publicationRefs_; 00136 /// Keep track the subscriptions of this topic so the TopicQos 00137 /// change can be published for those subscriptions. 00138 DCPS_IR_Subscription_Set subscriptionRefs_; 00139 00140 /// True means release() is called upon delete_topic, but topic object is 00141 /// not deleted because there are still pub/sub associated. 00142 bool removed_; 00143 }; 00144 00145 OPENDDS_END_VERSIONED_NAMESPACE_DECL 00146 00147 #endif /* DCPS_IR_TOPIC_H */