1 #include "tao/ORB_Table.h"
2 #include "tao/ORB_Core.h"
3 #include "tao/TAO_Singleton.h"
5 #if !defined (__ACE_INLINE__)
6 # include "tao/ORB_Table.inl"
7 #endif /* ! __ACE_INLINE__ */
9 #include "ace/SString.h"
10 #include "ace/OS_NS_string.h"
12 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 TAO::ORB_Table::ORB_Table ()
16 first_orb_not_default_ (false),
17 table_ (TAO_DEFAULT_ORB_TABLE_SIZE
),
23 TAO::ORB_Table::bind (char const * orb_id
,
24 TAO_ORB_Core
* orb_core
)
26 // Make sure that the supplied ORB core pointer is valid,
28 if (orb_id
== nullptr || orb_core
== nullptr)
34 value_type
const value
=
35 std::make_pair (key_type (orb_id
), data_type (orb_core
));
37 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
,
42 std::pair
<iterator
, bool> result
= this->table_
.insert (value
);
46 // This is not the first ORB, but if the current default ORB
47 // decided not to be the default and there is more than one ORB
48 // then set this ORB to be the default.
49 if (this->first_orb_
!= nullptr
50 && this->first_orb_not_default_
)
52 this->first_orb_
= orb_core
;
53 this->first_orb_not_default_
= false;
56 // Set the "first_orb_" member for the first given ORB Core
57 // that was successfully added to the ORB table.
58 if (this->first_orb_
== nullptr)
60 this->first_orb_
= orb_core
;
64 return (result
.second
? 0 : 1);
68 TAO::ORB_Table::find (char const * orb_id
)
70 TAO_ORB_Core
* orb_core
= nullptr;
72 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
,
77 iterator
const i
= this->table_
.find (Table::key_type (orb_id
));
79 // Maintain ownership of the ORB_Core.
80 if (i
!= this->end ())
82 orb_core
= (*i
).second
.core ();
83 (void) orb_core
->_incr_refcnt ();
90 TAO::ORB_Table::unbind (const char *orb_id
)
92 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
,
97 iterator
const result
= this->table_
.find (key_type (orb_id
));
99 if (result
!= this->end ())
101 TAO::ORB_Core_Ref_Counter
oc ((*result
).second
);
103 this->table_
.erase (result
);
105 if (oc
.core () == this->first_orb_
)
107 if (!this->table_
.empty ())
109 this->first_orb_
= (*this->begin ()).second
.core ();
113 this->first_orb_
= nullptr;
122 TAO::ORB_Table::set_default (char const * orb_id
)
124 ACE_GUARD (TAO_SYNCH_MUTEX
,
128 iterator
const i
= this->table_
.find (key_type (orb_id
));
130 if (i
!= this->end ())
131 this->first_orb_
= (*i
).second
.core ();
135 TAO::ORB_Table::not_default (char const * orb_id
)
137 // @@ This method now works for restricted cases. Should work on
138 // generalizing it. It works if the first ORB that is registered
139 // decides to not want be the default ORB. Should generalize it
140 // to handle all cases.
141 ACE_GUARD (TAO_SYNCH_MUTEX
,
145 // Check if there is a default ORB already and if it is *not* the
146 // same as the orb_id thats passed in. We don't have to do
148 if (this->first_orb_
!= nullptr)
150 if (ACE_OS::strcmp (this->first_orb_
->orbid (), orb_id
) != 0)
152 // There is another default ORB. No need to change anything
157 // The ORB with orbid 'orb_id' is the default now. We need
159 this->first_orb_not_default_
= true;
165 TAO::ORB_Table::instance ()
167 return TAO_Singleton
<TAO::ORB_Table
, TAO_SYNCH_MUTEX
>::instance ();
170 #if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION)
171 template TAO_Singleton
<TAO::ORB_Table
,TAO_SYNCH_MUTEX
> * TAO_Singleton
<TAO::ORB_Table
,TAO_SYNCH_MUTEX
>::singleton_
;
172 #endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */
174 TAO_END_VERSIONED_NAMESPACE_DECL