Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / ORB_Table.h
blob3d5b04151206ecb6bf7d9f8de891472db475a31d
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file ORB_Table.h
7 * @author Ossama Othman
8 * @author Carlos O'Ryan
9 */
10 //=============================================================================
13 #ifndef TAO_ORB_TABLE_H
14 #define TAO_ORB_TABLE_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "tao/TAO_Export.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "tao/orbconf.h"
25 #include "tao/CORBA_String.h"
27 #include "ace/Array_Map.h"
28 #include "ace/Thread_Mutex.h"
31 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
33 // Forward declarations.
34 class TAO_ORB_Core;
36 namespace TAO
38 class ORB_Core_Ref_Counter;
40 /**
41 * @class ORB_Table
43 * @brief Keep a table with all the ORBs in the system.
45 * CORBA::ORB_init() is supposed to return the same ORB if the
46 * user specifies the same ORBid, either in the ORB_init()
47 * parameter or in the -ORBid option.
48 * This class is used to implement that feature.
49 * It is also useful when trying to determine if an object
50 * reference is collocated or not.
52 * @note This class should be instantiated via its instance()
53 * method. Normally this would be enforced by making the
54 * constructor protected but that forces a friend declaration
55 * containing a template type (TAO_Singleton) with a static
56 * member to be introduced. In turn, this potentially
57 * introduces problems in MS Windows DLL environments due to
58 * the occurrence of multiple singleton instances. There
59 * should only be one!
61 class TAO_Export ORB_Table
63 public:
64 /// Constructor
65 /**
66 * @note See the note in the class description for an explanation
67 * of why this constructor is not protected.
69 ORB_Table ();
71 typedef ACE_Array_Map<CORBA::String_var,
72 ORB_Core_Ref_Counter,
73 TAO::String_Var_Equal_To> Table;
74 typedef Table::key_type key_type;
75 typedef Table::data_type data_type;
76 typedef Table::value_type value_type;
77 typedef Table::size_type size_type;
78 typedef Table::iterator iterator;
80 /**
81 * @name The canonical ACE_Map methods.
83 //@{
84 iterator begin ();
85 iterator end ();
86 int bind (const char *orb_id, ::TAO_ORB_Core *orb_core);
88 /// Return @c TAO_ORB_Core corresponding to ORB with given @a
89 /// orb_id.
90 /**
91 * @note The caller must decrease the reference count on the
92 * returned ORB_Core, i.e. the callers "owns" it.
94 ::TAO_ORB_Core* find (const char *orb_id);
96 int unbind (const char *orb_id);
97 //@}
99 /// Obtain the first ORB for the @c ORB_Core_instance()
100 /// implementation.
101 ::TAO_ORB_Core * first_orb ();
103 /// Return a unique instance
104 static ORB_Table * instance ();
106 /// Set the ORB related to the orb_id as the default ORB and not the
107 /// ORB that is first binded.
108 void set_default (char const * orb_id);
110 /// Method the ORB invokes to specify that it doesnt want to be the
111 /// default ORB if there are more than one ORB registered.
112 void not_default (char const * orb_id);
114 /// Accessor to the underlying table_
115 Table * table ();
117 /// Return reference to underlying lock.
118 TAO_SYNCH_MUTEX & lock ();
120 private:
121 // Prevent copying
122 ORB_Table (const ORB_Table &);
123 void operator= (const ORB_Table &);
125 /// Return @c TAO_ORB_Core corresponding to ORB with given @a
126 /// orb_id. (underlying unlocked implementation).
127 ::TAO_ORB_Core * find_i (char const * orb_id);
129 private:
130 /// Lock used to synchronize access to the internal state.
131 ::TAO_SYNCH_MUTEX lock_;
133 /// Variable to check if the first ORB decides not to be the
134 /// default.
135 bool first_orb_not_default_;
137 /// The underlying table.
138 Table table_;
140 /// The first ORB created by the user
141 ::TAO_ORB_Core * first_orb_;
144 // -----------------------------------------------
147 * @class ORB_Table_Ref_Counter
149 * @brief Class contained by ORB_Table's Unbounded_Set.
151 * Class contained by ORB_Table's Unbounded_Set.
153 class ORB_Core_Ref_Counter
155 public:
156 /// Constructor.
157 ORB_Core_Ref_Counter ();
159 /// Constructor.
160 ORB_Core_Ref_Counter (::TAO_ORB_Core * core);
162 /// Destructor.
163 ~ORB_Core_Ref_Counter ();
165 /// Copy constructor.
166 ORB_Core_Ref_Counter (ORB_Core_Ref_Counter const & rhs);
168 /// Assignment operator.
169 void operator= (ORB_Core_Ref_Counter const & rhs);
171 /// ORB_Core pointer accessor.
172 ::TAO_ORB_Core * core () const { return this->core_; }
174 private:
175 ::TAO_ORB_Core * core_;
179 TAO_END_VERSIONED_NAMESPACE_DECL
181 #if defined (__ACE_INLINE__)
182 # include "tao/ORB_Table.inl"
183 #endif /* __ACE_INLINE__ */
185 #include /**/ "ace/post.h"
187 #endif /* TAO_ORB_TABLE_H */