ORB_Table.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file     ORB_Table.h
00006  *
00007  *  $Id: ORB_Table.h 74014 2006-08-14 13:52:22Z johnnyw $
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   public:
00066 
00067     /// Constructor
00068     /**
00069      * @note See the note in the class description for an explanation
00070      *       of why this constructor is not protected.
00071      */
00072     ORB_Table (void);
00073 
00074     typedef ACE_Array_Map<CORBA::String_var,
00075                           ORB_Core_Ref_Counter,
00076                           TAO::String_Var_Equal_To> Table;
00077     typedef Table::key_type   key_type;
00078     typedef Table::data_type  data_type;
00079     typedef Table::value_type value_type;
00080     typedef Table::size_type  size_type;
00081     typedef Table::iterator   iterator;
00082 
00083     /**
00084      * @name The canonical ACE_Map methods.
00085      */
00086     //@{
00087     iterator begin (void);
00088     iterator end (void);
00089     int bind (const char *orb_id, ::TAO_ORB_Core *orb_core);
00090 
00091     /// Return @c TAO_ORB_Core corresponding to ORB with given @a
00092     /// orb_id.
00093     /**
00094      * @note The caller must decrease the reference count on the
00095      *       returned ORB_Core, i.e. the callers "owns" it.
00096      */
00097     ::TAO_ORB_Core* find (const char *orb_id);
00098 
00099     int unbind (const char *orb_id);
00100     //@}
00101 
00102     ::TAO_ORB_Core * const * get_orbs (size_t& num_orbs);
00103 
00104     /// Obtain the first ORB for the @c ORB_Core_instance()
00105     /// implementation.
00106     ::TAO_ORB_Core * first_orb (void);
00107 
00108     /// Return a unique instance
00109     static ORB_Table * instance (void);
00110 
00111     /// Set the ORB related to the orb_id as the default ORB and not the
00112     /// ORB that is first binded.
00113     void set_default (char const * orb_id);
00114 
00115     /// Method the ORB invokes to specify that it doesnt want to be the
00116     /// default ORB if there are more than one ORB registered.
00117     void not_default (char const * orb_id);
00118 
00119     /// Accessor to the underlying table_
00120     Table * table (void);
00121 
00122     /// Return reference to underlying lock.
00123     TAO_SYNCH_MUTEX & lock (void);
00124 
00125   private:
00126 
00127     // Prevent copying
00128     ORB_Table (const ORB_Table &);
00129     void operator= (const ORB_Table &);
00130 
00131     /// Return @c TAO_ORB_Core corresponding to ORB with given @a
00132     /// orb_id.  (underlying unlocked implementation).
00133     ::TAO_ORB_Core * find_i (char const * orb_id);
00134 
00135   private:
00136 
00137     /// Lock used to synchronize access to the internal state.
00138     ::TAO_SYNCH_MUTEX lock_;
00139 
00140     /// Variable to check if the first ORB decides not to be the
00141     /// default.
00142     bool first_orb_not_default_;
00143 
00144     /// The underlying table.
00145     Table table_;
00146 
00147     /// The first ORB created by the user
00148     ::TAO_ORB_Core * first_orb_;
00149 
00150     /// List of orbs for get_orbs call
00151     /**
00152      * @todo ORB_Table::orbs_ appears to be unused.  Remove it?
00153      */
00154     ::TAO_ORB_Core ** orbs_;
00155 
00156     /// Number of ORBs in the table.
00157     size_t num_orbs_;
00158 
00159   };
00160 
00161   // -----------------------------------------------
00162 
00163   /**
00164    * @class ORB_Table_Ref_Counter
00165    *
00166    * @brief Class contained by ORB_Table's Unbounded_Set.
00167    *
00168    * Class contained by ORB_Table's Unbounded_Set.
00169    */
00170   class ORB_Core_Ref_Counter
00171   {
00172   public:
00173 
00174     /// Constructor.
00175     ORB_Core_Ref_Counter (void);
00176 
00177     /// Constructor.
00178     ORB_Core_Ref_Counter (::TAO_ORB_Core * core);
00179 
00180     /// Destructor.
00181     ~ORB_Core_Ref_Counter (void);
00182 
00183     /// Copy constructor.
00184     ORB_Core_Ref_Counter (ORB_Core_Ref_Counter const & rhs);
00185 
00186     /// Assignment operator.
00187     void operator= (ORB_Core_Ref_Counter const & rhs);
00188 
00189     /// ORB_Core pointer accessor.
00190     ::TAO_ORB_Core * core (void) const { return this->core_; }
00191 
00192   private:
00193 
00194     ::TAO_ORB_Core * core_;
00195 
00196   };
00197 
00198 }
00199 
00200 TAO_END_VERSIONED_NAMESPACE_DECL
00201 
00202 #if defined (__ACE_INLINE__)
00203 # include "tao/ORB_Table.inl"
00204 #endif /* __ACE_INLINE__ */
00205 
00206 #include /**/ "ace/post.h"
00207 
00208 #endif  /* TAO_ORB_TABLE_H */

Generated on Sun Jan 27 13:07:35 2008 for TAO by doxygen 1.3.6