TopicDescriptionImpl.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 OPENDDS_DCPS_TOPIC_DESCRIPTION_IMPL_H
00009 #define OPENDDS_DCPS_TOPIC_DESCRIPTION_IMPL_H
00010 
00011 #include "dds/DdsDcpsTopicC.h"
00012 #include "dds/DdsDcpsTypeSupportExtC.h"
00013 #include "Definitions.h"
00014 #include "ace/SString.h"
00015 #include "ace/Atomic_Op.h"
00016 #include "LocalObject.h"
00017 
00018 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00019 #pragma once
00020 #endif /* ACE_LACKS_PRAGMA_ONCE */
00021 
00022 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 namespace OpenDDS {
00025 namespace DCPS {
00026 
00027 class DomainParticipantImpl;
00028 
00029 /**
00030 * @class TopicDescriptionImpl
00031 *
00032 * @brief Implements the DDS::TopicDescription interface.
00033 *
00034 * See the DDS specification, OMG formal/04-12-02, for a description of
00035 * the interface this class is implementing.
00036 *
00037 */
00038 class OpenDDS_Dcps_Export TopicDescriptionImpl
00039   : public virtual OpenDDS::DCPS::LocalObject<DDS::TopicDescription> {
00040 public:
00041   TopicDescriptionImpl(const char*            topic_name,
00042                        const char*            type_name,
00043                        TypeSupport_ptr        type_support,
00044                        DomainParticipantImpl* participant);
00045 
00046   virtual ~TopicDescriptionImpl();
00047 
00048   virtual char * get_type_name();
00049 
00050   virtual char * get_name();
00051 
00052   virtual DDS::DomainParticipant_ptr get_participant();
00053 
00054   /** This method is not defined in the IDL and is defined for
00055   *  internal use.
00056   *  Return the type support of the topic.
00057   */
00058   OpenDDS::DCPS::TypeSupport_ptr get_type_support();
00059 
00060   bool has_entity_refs() const {
00061     return entity_refs_ > 0;
00062   }
00063 
00064   void add_entity_ref() {
00065     RcObject::_add_ref();
00066     ++entity_refs_;
00067   }
00068 
00069   void remove_entity_ref() {
00070     --entity_refs_;
00071     RcObject::_remove_ref();
00072   }
00073 
00074 protected:
00075   /// The name of the topic.
00076   ACE_CString                    topic_name_;
00077   /// The datatype of the topic.
00078   ACE_CString                    type_name_;
00079 
00080   /// The participant that creates this topic.
00081   DomainParticipantImpl*         participant_;
00082 
00083   /// The type_support for this topic.
00084   OpenDDS::DCPS::TypeSupport_var type_support_;
00085 
00086   /// The number of entities using this topic
00087   ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long> entity_refs_;
00088 };
00089 
00090 template <typename Topic>
00091 class TopicDescriptionPtr
00092 {
00093 public:
00094   TopicDescriptionPtr(Topic* topic=0)
00095     : topic_(topic)
00096   {
00097     if (topic_)
00098       topic_->add_entity_ref();
00099   }
00100 
00101   ~TopicDescriptionPtr()
00102   {
00103     if (topic_)
00104       topic_->remove_entity_ref();
00105   }
00106 
00107   TopicDescriptionPtr(const TopicDescriptionPtr& other)
00108     : topic_(other.topic_)
00109   {
00110     if (topic_)
00111       topic_->add_entity_ref();
00112   }
00113 
00114   TopicDescriptionPtr& operator = (Topic* other)
00115   {
00116     TopicDescriptionPtr tmp(other);
00117     std::swap(this->topic_, tmp.topic_);
00118     return *this;
00119   }
00120 
00121   TopicDescriptionPtr& operator = (const TopicDescriptionPtr& other)
00122   {
00123     TopicDescriptionPtr tmp(other);
00124     std::swap(this->topic_, tmp.topic_);
00125     return *this;
00126   }
00127 
00128   Topic* operator->() const
00129   {
00130     return topic_;
00131   }
00132 
00133   Topic* get() const
00134   {
00135     return topic_;
00136   }
00137 
00138   operator bool() const
00139   {
00140     return topic_;
00141   }
00142 
00143 private:
00144   Topic* topic_;
00145 };
00146 
00147 } // namespace DCPS
00148 } // namespace OpenDDS
00149 
00150 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00151 
00152 #endif /* OPENDDS_DCPS_TOPIC_DESCRIPTION_IMPL_H  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1