ORB_Table.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file     ORB_Table.h
00006  *
00007  *  ORB_Table.h,v 1.22 2006/03/21 13:01:06 jwillemsen Exp
00008  *
00009  *  @author Ossama Othman
00010  *  @author Carlos O'Ryan
00011  */
00012 //=============================================================================
00013 
00014 
00015 #ifndef TAO_ORB_TABLE_H
00016 #define TAO_ORB_TABLE_H
00017 
00018 #include /**/ "ace/pre.h"
00019 
00020 #include "tao/TAO_Export.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #include "tao/orbconf.h"
00027 #include "tao/CORBA_String.h"
00028 
00029 #include "ace/Array_Map.h"
00030 #include "ace/Thread_Mutex.h"
00031 
00032 
00033 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00034 
00035 // Forward declarations.
00036 class TAO_ORB_Core;
00037 
00038 namespace TAO
00039 {
00040   class ORB_Core_Ref_Counter;
00041 
00042   /**
00043    * @class ORB_Table
00044    *
00045    * @brief Keep a table with all the ORBs in the system.
00046    *
00047    * CORBA::ORB_init() is supposed to return the same ORB if the
00048    * user specifies the same ORBid, either in the ORB_init()
00049    * parameter or in the -ORBid option.
00050    * This class is used to implement that feature.
00051    * It is also useful when trying to determine if an object
00052    * reference is collocated or not.
00053    *
00054    * @note This class should be instantiated via its instance()
00055    *       method.  Normally this would be enforced by making the
00056    *       constructor protected but that forces a friend declaration
00057    *       containing a template type (TAO_Singleton) with a static
00058    *       member to be introduced.  In turn, this potentially
00059    *       introduces problems in MS Windows DLL environments due to
00060    *       the occurance of multiple singleton instances.  There
00061    *       should only be one!
00062    */
00063   class TAO_Export ORB_Table
00064   {
00065   friend class ::TAO_ORB_Core;
00066   public:
00067 
00068     /// Constructor
00069     /**
00070      * @note See the note in the class description for an explanation
00071      *       of why this constructor is not protected.
00072      */
00073     ORB_Table (void);
00074 
00075     typedef ACE_Array_Map<CORBA::String_var,
00076                           ORB_Core_Ref_Counter,
00077                           TAO::String_Var_Equal_To> Table;
00078     typedef Table::key_type   key_type;
00079     typedef Table::data_type  data_type;
00080     typedef Table::value_type value_type;
00081     typedef Table::size_type  size_type;
00082     typedef Table::iterator   iterator;
00083 
00084     /**
00085      * @name The canonical ACE_Map methods.
00086      */
00087     //@{
00088     iterator begin (void);
00089     iterator end (void);
00090     int bind (const char *orb_id, ::TAO_ORB_Core *orb_core);
00091 
00092     /// Return @c TAO_ORB_Core corresponding to ORB with given @a
00093     /// orb_id.
00094     /**
00095      * @note The caller must decrease the reference count on the
00096      *       returned ORB_Core, i.e. the callers "owns" it.
00097      */
00098     ::TAO_ORB_Core* find (const char *orb_id);
00099 
00100     int unbind (const char *orb_id);
00101     //@}
00102 
00103     ::TAO_ORB_Core * const * get_orbs (size_t& num_orbs);
00104 
00105     /// Obtain the first ORB for the @c ORB_Core_instance()
00106     /// implementation.
00107     ::TAO_ORB_Core * first_orb (void);
00108 
00109     /// Return a unique instance
00110     static ORB_Table * instance (void);
00111 
00112     /// Set the ORB related to the orb_id as the default ORB and not the
00113     /// ORB that is first binded.
00114     void set_default (char const * orb_id);
00115 
00116     /// Method the ORB invokes to specify that it doesnt want to be the
00117     /// default ORB if there are more than one ORB registered.
00118     void not_default (char const * orb_id);
00119 
00120     /// Accessor to the underlying table_
00121     Table * table (void);
00122 
00123   private:
00124 
00125     // Prevent copying
00126     ORB_Table (const ORB_Table &);
00127     void operator= (const ORB_Table &);
00128 
00129     /// Return @c TAO_ORB_Core corresponding to ORB with given @a
00130     /// orb_id.  (underlying unlocked implementation).
00131     ::TAO_ORB_Core * find_i (char const * orb_id);
00132 
00133   private:
00134 
00135     /// Lock used to synchronize access to the internal state.
00136     ::TAO_SYNCH_MUTEX lock_;
00137 
00138     /// Variable to check if the first ORB decides not to be the
00139     /// default.
00140     bool first_orb_not_default_;
00141 
00142     /// The underlying table.
00143     Table table_;
00144 
00145     /// The first ORB created by the user
00146     ::TAO_ORB_Core * first_orb_;
00147 
00148     /// List of orbs for get_orbs call
00149     /**
00150      * @todo ORB_Table::orbs_ appears to be unused.  Remove it?
00151      */
00152     ::TAO_ORB_Core ** orbs_;
00153 
00154     /// Number of ORBs in the table.
00155     size_t num_orbs_;
00156 
00157   };
00158 
00159   // -----------------------------------------------
00160 
00161   /**
00162    * @class ORB_Table_Ref_Counter
00163    *
00164    * @brief Class contained by ORB_Table's Unbounded_Set.
00165    *
00166    * Class contained by ORB_Table's Unbounded_Set.
00167    */
00168   class ORB_Core_Ref_Counter
00169   {
00170   public:
00171 
00172     /// Constructor.
00173     ORB_Core_Ref_Counter (void);
00174 
00175     /// Constructor.
00176     ORB_Core_Ref_Counter (::TAO_ORB_Core * core);
00177 
00178     /// Destructor.
00179     ~ORB_Core_Ref_Counter (void);
00180 
00181     /// Copy constructor.
00182     ORB_Core_Ref_Counter (ORB_Core_Ref_Counter const & rhs);
00183 
00184     /// Assignment operator.
00185     void operator= (ORB_Core_Ref_Counter const & rhs);
00186 
00187     /// ORB_Core pointer accessor.
00188     ::TAO_ORB_Core * core (void) const { return this->core_; }
00189 
00190   private:
00191 
00192     ::TAO_ORB_Core * core_;
00193 
00194   };
00195 
00196 }
00197 
00198 TAO_END_VERSIONED_NAMESPACE_DECL
00199 
00200 #if defined (__ACE_INLINE__)
00201 # include "tao/ORB_Table.inl"
00202 #endif /* __ACE_INLINE__ */
00203 
00204 #include /**/ "ace/post.h"
00205 
00206 #endif  /* TAO_ORB_TABLE_H */

Generated on Thu Nov 9 11:54:19 2006 for TAO by doxygen 1.3.6