00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file ORB_Table.h 00006 * 00007 * $Id: ORB_Table.h 80823 2008-03-04 10:11:35Z 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 /// Obtain the first ORB for the @c ORB_Core_instance() 00103 /// implementation. 00104 ::TAO_ORB_Core * first_orb (void); 00105 00106 /// Return a unique instance 00107 static ORB_Table * instance (void); 00108 00109 /// Set the ORB related to the orb_id as the default ORB and not the 00110 /// ORB that is first binded. 00111 void set_default (char const * orb_id); 00112 00113 /// Method the ORB invokes to specify that it doesnt want to be the 00114 /// default ORB if there are more than one ORB registered. 00115 void not_default (char const * orb_id); 00116 00117 /// Accessor to the underlying table_ 00118 Table * table (void); 00119 00120 /// Return reference to underlying lock. 00121 TAO_SYNCH_MUTEX & lock (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 00149 // ----------------------------------------------- 00150 00151 /** 00152 * @class ORB_Table_Ref_Counter 00153 * 00154 * @brief Class contained by ORB_Table's Unbounded_Set. 00155 * 00156 * Class contained by ORB_Table's Unbounded_Set. 00157 */ 00158 class ORB_Core_Ref_Counter 00159 { 00160 public: 00161 00162 /// Constructor. 00163 ORB_Core_Ref_Counter (void); 00164 00165 /// Constructor. 00166 ORB_Core_Ref_Counter (::TAO_ORB_Core * core); 00167 00168 /// Destructor. 00169 ~ORB_Core_Ref_Counter (void); 00170 00171 /// Copy constructor. 00172 ORB_Core_Ref_Counter (ORB_Core_Ref_Counter const & rhs); 00173 00174 /// Assignment operator. 00175 void operator= (ORB_Core_Ref_Counter const & rhs); 00176 00177 /// ORB_Core pointer accessor. 00178 ::TAO_ORB_Core * core (void) const { return this->core_; } 00179 00180 private: 00181 ::TAO_ORB_Core * core_; 00182 }; 00183 00184 } 00185 00186 TAO_END_VERSIONED_NAMESPACE_DECL 00187 00188 #if defined (__ACE_INLINE__) 00189 # include "tao/ORB_Table.inl" 00190 #endif /* __ACE_INLINE__ */ 00191 00192 #include /**/ "ace/post.h" 00193 00194 #endif /* TAO_ORB_TABLE_H */