Topology_Object.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005 *  @file    Topology_Object.h
00006 *
00007 *  $Id: Topology_Object.h 81416 2008-04-24 10:26:10Z johnnyw $
00008 *
00009 *  @author Jonathan Pollack <pollack_j@ociweb.com>
00010 */
00011 //=============================================================================
00012 
00013 #ifndef TOPOLOGY_OBJECT_H
00014 #define TOPOLOGY_OBJECT_H
00015 #include /**/ "ace/pre.h"
00016 
00017 #include "orbsvcs/Notify/Object.h"
00018 #include "orbsvcs/Notify/Name_Value_Pair.h"
00019 
00020 #include "ace/SString.h"
00021 #include "ace/Vector_T.h"
00022 
00023 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00024 #pragma once
00025 #endif /* ACE_LACKS_PRAGMA_ONCE */
00026 
00027 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00028 
00029 /// \namespace TAO_Notify
00030 /// \brief A namespace to be used by all of TAO's Notification Service
00031 /// implementation.
00032 ///
00033 /// The initial implementation used the TAO_Notify_ prefix rather than
00034 /// a namespace.  As part of the reliable Notification Service project
00035 /// we started using this TAO_Notify namespace,  but there are still
00036 /// many parts of the Notification Service that are in the global
00037 /// namespace with a TAO_NS prefix.
00038 
00039 // @@ Wouldn't it be better to use something like
00040 //
00041 // namespace TAO
00042 // {
00043 //   namespace Notify {}
00044 //
00045 // }
00046 //
00047 namespace TAO_Notify
00048 {
00049   class Topology_Saver;
00050   class Topology_Parent;
00051 
00052   /// A vector of IDS.  Used as a path from the EventChannelFactory to a proxy.
00053   typedef ACE_Vector <TAO_Notify_Object::ID> IdVec;
00054 
00055   /// \brief Interface to be implemented by savable topology objects.
00056   class TAO_Notify_Serv_Export Topology_Savable
00057   {
00058    public:
00059     /// Destructor.
00060     virtual ~Topology_Savable (void);
00061 
00062     /// Save our state to a Topology_Saver.
00063     ///
00064     /// Use the methods of a Topology_Saver to store all information we want
00065     /// persisted.  This function is called by our parent, which gives us a
00066     /// saver to use.  In turn, we must call this function on all of our
00067     /// children.
00068     /// The implementation should look like:
00069     ///   bool change = this->self_changed_;
00070     ///   this->self_changed_ = false;
00071     ///   this->children_changed_ = false;
00072     ///   if (is_persistent ())
00073     ///   {
00074     ///     bool want_all_children = saver.begin_object(
00075     ///       this->id(), type, attrs, change);
00076     ///     for all children
00077     ///     {
00078     ///       if (want_all_children || child.is_changed())
00079     ///       {
00080     ///         child.save_persistent(saver);
00081     ///       }
00082     ///     }
00083     ///     for all deleted children
00084     ///     {
00085     ///       saver.delete_child(child_type, child_id);
00086     ///     }
00087     ///     saver.end_object(this->id(), type);
00088     ///   )
00089     virtual void save_persistent (Topology_Saver& saver) = 0;
00090 
00091     /// Re-establish connections that we had before a shutdown.
00092     ///
00093     /// After a topology restore, this method is called so we can reconnect
00094     /// to any external objects with whom we were interacting.  We should
00095     /// call the reconnect() method on all of our children to give them
00096     /// the chance to do the same.
00097     virtual void reconnect (void);
00098 
00099   };
00100 
00101   /// \brief Base class for Persistent Topology Objects.
00102   ///
00103   /// Topology objects must be derived from this class to allow themselves
00104   /// to be persisted.
00105   /// Note: virtual inheritance from TopologySavable is unnecessary,
00106   /// but HP ACC compiler warns if it's not there.
00107   class TAO_Notify_Serv_Export Topology_Object :
00108     public virtual TAO_Notify_Object,
00109     public virtual Topology_Savable
00110   {
00111   public:
00112     /// The constructor.
00113     Topology_Object ();
00114 
00115     /// The destructor.
00116     virtual ~Topology_Object ();
00117 
00118     /// Init this object with data from <rhs>.
00119     virtual void initialize (Topology_Parent* topology_parent);
00120 
00121     /// \brief Create a child of the appropriate type and return it.
00122     ///
00123     /// Use "type" as passed in to determine what kind of child (supporting
00124     /// the Topology_Object interface) to create and return.  Inform it of
00125     /// its new ID.
00126     virtual Topology_Object* load_child (const ACE_CString & type,
00127       CORBA::Long id,
00128       const NVPList& attrs);
00129 
00130     /// \brief Find the id associated with topology object.
00131     ///
00132     /// A bit of a hack because id is unknown to Topology_Object
00133     /// the get_id returns the same thing as id -- we just need someone
00134     /// to find it for us.
00135     virtual TAO_Notify_Object::ID get_id (void) const;
00136 
00137     /// \brief Get the path of id's from the root to this object.
00138     void get_id_path (IdVec & id_path) const;
00139 
00140     /// \brief Is there an unsaved change for this object or its children?
00141     bool is_changed (void) const;
00142 
00143   protected:
00144     /// \brief Should this object be saved?
00145     ///
00146     /// This is a way for send_change() and save_persistent() to find out
00147     /// if this object has a persistent QoS connection property.
00148     /// \return true (default) if object should be saved.
00149     virtual bool is_persistent (void) const;
00150 
00151     /// \brief Method to report change in this object
00152     ///
00153     ///  see also Topology_Parent::child_change ()
00154     /// \return false if save will never happen
00155     bool self_change (void);
00156 
00157     /// \brief pointer to our topological parent
00158     ///
00159     /// \return 0 if none
00160     Topology_Parent * topology_parent () const;
00161 
00162     /// \brief Handle details of propagating change
00163     ///
00164     /// \return false if save will never happen
00165     bool send_change (void);
00166 
00167     /// \brief Handle details of propagating change
00168     ///  for a deleted object.
00169     ///
00170     /// \return false if save will never happen
00171     bool send_deletion_change ();
00172 
00173   private:
00174     /// \brief Send change to parent.
00175     ///
00176     /// Override this if you don't expect to have a parent
00177     /// (top level of tree)
00178     /// private virtual because this should only be called from send_change()
00179     /// \return false if save will never happen
00180     virtual bool change_to_parent (void);
00181 
00182   protected:
00183     /// true if this object changed since last save_persistent
00184     bool self_changed_;
00185     /// true of any of this object's children changed since last save_persistent
00186     bool children_changed_;
00187 
00188     /// A safely-typed copy of parent_;
00189     Topology_Parent * topology_parent_;
00190   };
00191 
00192   /// \brief Interface for topology objects that act as parents.
00193   ///
00194   /// Any topology object which contains other topology objects
00195   /// must implement this interface so that it's children can signal
00196   /// that they have changed.
00197   class TAO_Notify_Serv_Export Topology_Parent : public Topology_Object
00198   {
00199   public:
00200     /// Called by a child that has changed.
00201     /// A child calls this method to report that it has changed.
00202     /// \return false if save will never happen
00203     bool child_change (void);
00204   };
00205 
00206 } // namespace TAO_Notify
00207 
00208 TAO_END_VERSIONED_NAMESPACE_DECL
00209 
00210 #if defined (__ACE_INLINE__)
00211 #include "orbsvcs/Notify/Topology_Object.inl"
00212 #endif /* __ACE_INLINE__ */
00213 
00214 #include /**/ "ace/post.h"
00215 
00216 #endif /* TOPOLOGY_OBJECT */

Generated on Tue Feb 2 17:45:29 2010 for TAO_CosNotification by  doxygen 1.4.7