TAO::ORB_Table Class Reference

Keep a table with all the ORBs in the system. More...

#include <ORB_Table.h>

Collaboration diagram for TAO::ORB_Table:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Array_Map< CORBA::String_var,
ORB_Core_Ref_Counter, TAO::String_Var_Equal_To
Table
typedef Table::key_type key_type
typedef Table::data_type data_type
typedef Table::value_type value_type
typedef Table::size_type size_type
typedef Table::iterator iterator

Public Member Functions

 ORB_Table (void)
 Constructor.

::TAO_ORB_Core *const * get_orbs (size_t &num_orbs)
::TAO_ORB_Corefirst_orb (void)
void set_default (char const *orb_id)
void not_default (char const *orb_id)
Tabletable (void)
 Accessor to the underlying table_.

The canonical ACE_Map methods.
iterator begin (void)
iterator end (void)
int bind (const char *orb_id,::TAO_ORB_Core *orb_core)
::TAO_ORB_Corefind (const char *orb_id)
int unbind (const char *orb_id)

Static Public Member Functions

ORB_Tableinstance (void)
 Return a unique instance.


Private Member Functions

 ORB_Table (const ORB_Table &)
void operator= (const ORB_Table &)
::TAO_ORB_Corefind_i (char const *orb_id)

Private Attributes

::TAO_SYNCH_MUTEX lock_
 Lock used to synchronize access to the internal state.

bool first_orb_not_default_
Table table_
 The underlying table.

::TAO_ORB_Corefirst_orb_
 The first ORB created by the user.

::TAO_ORB_Core ** orbs_
 List of orbs for get_orbs call.

size_t num_orbs_
 Number of ORBs in the table.


Friends

class ::TAO_ORB_Core

Detailed Description

Keep a table with all the ORBs in the system.

CORBA::ORB_init() is supposed to return the same ORB if the user specifies the same ORBid, either in the ORB_init() parameter or in the -ORBid option. This class is used to implement that feature. It is also useful when trying to determine if an object reference is collocated or not.

Note:
This class should be instantiated via its instance() method. Normally this would be enforced by making the constructor protected but that forces a friend declaration containing a template type (TAO_Singleton) with a static member to be introduced. In turn, this potentially introduces problems in MS Windows DLL environments due to the occurance of multiple singleton instances. There should only be one!

Definition at line 63 of file ORB_Table.h.


Member Typedef Documentation

typedef Table::data_type TAO::ORB_Table::data_type
 

Definition at line 79 of file ORB_Table.h.

typedef Table::iterator TAO::ORB_Table::iterator
 

Definition at line 82 of file ORB_Table.h.

typedef Table::key_type TAO::ORB_Table::key_type
 

Definition at line 78 of file ORB_Table.h.

typedef Table::size_type TAO::ORB_Table::size_type
 

Definition at line 81 of file ORB_Table.h.

typedef ACE_Array_Map<CORBA::String_var, ORB_Core_Ref_Counter, TAO::String_Var_Equal_To> TAO::ORB_Table::Table
 

Definition at line 77 of file ORB_Table.h.

typedef Table::value_type TAO::ORB_Table::value_type
 

Definition at line 80 of file ORB_Table.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO::ORB_Table::ORB_Table void   ) 
 

Constructor.

Note:
See the note in the class description for an explanation of why this constructor is not protected.

Definition at line 22 of file ORB_Table.cpp.

References TAO_DEFAULT_ORB_TABLE_SIZE.

00023   : lock_ (),
00024     first_orb_not_default_ (false),
00025     table_ (TAO_DEFAULT_ORB_TABLE_SIZE),
00026     first_orb_ (0),
00027     orbs_ (0),
00028     num_orbs_ (0)
00029 {
00030 }

TAO::ORB_Table::ORB_Table const ORB_Table  )  [private]
 


Member Function Documentation

ACE_INLINE TAO::ORB_Table::iterator TAO::ORB_Table::begin void   ) 
 

Definition at line 18 of file ORB_Table.inl.

Referenced by TAO_ORB_Core::create_object(), TAO_ORB_Core::initialize_object_i(), and unbind().

00019 {
00020   return this->table_.begin ();
00021 }

int TAO::ORB_Table::bind const char *  orb_id,
::TAO_ORB_Core orb_core
 

Definition at line 33 of file ORB_Table.cpp.

References ACE_GUARD_RETURN, first_orb_, first_orb_not_default_, and TAO_SYNCH_MUTEX.

00035 {
00036   // Make sure that the supplied ORB core pointer is valid,
00037   // i.e. non-zero.
00038   if (orb_id == 0 || orb_core == 0)
00039     {
00040       errno = EINVAL;
00041       return -1;
00042     };
00043 
00044   value_type const value =
00045     std::make_pair (key_type (orb_id), data_type (orb_core));
00046 
00047   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00048                     guard,
00049                     this->lock_,
00050                     -1);
00051 
00052   std::pair<iterator, bool> result = this->table_.insert (value);
00053 
00054   if (result.second)
00055     {
00056       // This is not the first ORB, but if the current default ORB
00057       // decided not to be the default and there is more than one ORB
00058       // then set this ORB to be the default.
00059       if (this->first_orb_ != 0
00060           && this->first_orb_not_default_)
00061         {
00062           this->first_orb_ = orb_core;
00063           this->first_orb_not_default_ = false;
00064         }
00065 
00066       // Set the "first_orb_" member for the first given ORB Core
00067       // that was successfully added to the ORB table.
00068       if (this->first_orb_ == 0)
00069         {
00070           this->first_orb_ = orb_core;
00071         }
00072     }
00073 
00074   return (result.second ? 0 : 1);
00075 }

ACE_INLINE TAO::ORB_Table::iterator TAO::ORB_Table::end void   ) 
 

Definition at line 24 of file ORB_Table.inl.

Referenced by TAO_ORB_Core::create_object(), find(), TAO_ORB_Core::initialize_object_i(), set_default(), and unbind().

00025 {
00026   return this->table_.end ();
00027 }

TAO_ORB_Core * TAO::ORB_Table::find const char *  orb_id  ) 
 

Note:
The caller must decrease the reference count on the returned ORB_Core, i.e. the callers "owns" it.

Definition at line 78 of file ORB_Table.cpp.

References TAO_ORB_Core::_incr_refcnt(), ACE_GUARD_RETURN, end(), and TAO_SYNCH_MUTEX.

00079 {
00080   TAO_ORB_Core * orb_core = 0;
00081 
00082   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00083                     guard,
00084                     this->lock_,
00085                     0);
00086 
00087   iterator const i = this->table_.find (Table::key_type (orb_id));
00088 
00089   // Maintain ownership of the ORB_Core.
00090   if (i != this->end ())
00091     {
00092       orb_core = (*i).second.core ();
00093       (void) orb_core->_incr_refcnt ();
00094     }
00095 
00096   return orb_core;
00097 }

::TAO_ORB_Core* TAO::ORB_Table::find_i char const *  orb_id  )  [private]
 

Return TAO_ORB_Core corresponding to ORB with given orb_id. (underlying unlocked implementation).

TAO_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE::TAO_ORB_Core * TAO::ORB_Table::first_orb void   ) 
 

Obtain the first ORB for the ORB_Core_instance() implementation.

Definition at line 12 of file ORB_Table.inl.

References first_orb_.

Referenced by TAO_ORB_Core_instance().

00013 {
00014   return this->first_orb_;
00015 }

ACE_INLINE::TAO_ORB_Core *const * TAO::ORB_Table::get_orbs size_t &  num_orbs  ) 
 

Definition at line 30 of file ORB_Table.inl.

References num_orbs_, and orbs_.

00031 {
00032   num_orbs = this->num_orbs_;
00033   return this->orbs_;
00034 }

TAO::ORB_Table * TAO::ORB_Table::instance void   )  [static]
 

Return a unique instance.

Definition at line 177 of file ORB_Table.cpp.

References TAO_Singleton< TYPE, ACE_LOCK >::instance().

Referenced by TAO_ORB_Core::create_object(), TAO_ORB_Core::destroy(), TAO_ORB_Core::initialize_object_i(), TAO_ORB_Core::not_default(), CORBA::ORB_init(), TAO_ORB_Core::set_default(), and TAO_ORB_Core_instance().

void TAO::ORB_Table::not_default char const *  orb_id  ) 
 

Method the ORB invokes to specify that it doesnt want to be the default ORB if there are more than one ORB registered.

Definition at line 145 of file ORB_Table.cpp.

References ACE_GUARD, first_orb_, first_orb_not_default_, ACE_OS::strcmp(), and TAO_SYNCH_MUTEX.

Referenced by TAO_ORB_Core::not_default().

00146 {
00147   // @@  This method now works for restricted cases. Should work on
00148   //     generalizing it. It works if the first ORB that is registered
00149   //     decides to not want be the default ORB. Should generalize it
00150   //     to handle all cases.
00151 
00152 
00153   ACE_GUARD (TAO_SYNCH_MUTEX,
00154              guard,
00155              this->lock_);
00156 
00157   // Check if there is a default ORB already and if it is *not* the
00158   // same as the orb_id thats passed in.  We don't have to do
00159   // anything.
00160   if (this->first_orb_ != 0)
00161     {
00162       if (ACE_OS::strcmp (this->first_orb_->orbid (), orb_id) != 0)
00163         {
00164           // There is another default ORB. No need to change anything
00165           return;
00166         }
00167       else
00168         {
00169           // The ORB with orbid 'orb_id' is the default now. We need
00170           // to change it.
00171           this->first_orb_not_default_ = true;
00172         }
00173     }
00174 }

void TAO::ORB_Table::operator= const ORB_Table  )  [private]
 

void TAO::ORB_Table::set_default char const *  orb_id  ) 
 

Set the ORB related to the orb_id as the default ORB and not the ORB that is first binded.

Definition at line 132 of file ORB_Table.cpp.

References ACE_GUARD, end(), first_orb_, and TAO_SYNCH_MUTEX.

Referenced by TAO_ORB_Core::set_default().

00133 {
00134   ACE_GUARD (TAO_SYNCH_MUTEX,
00135              guard,
00136              this->lock_);
00137 
00138   iterator const i = this->table_.find (key_type (orb_id));
00139 
00140   if (i != this->end ())
00141     this->first_orb_ = (*i).second.core ();
00142 }

ACE_INLINE TAO::ORB_Table::Table * TAO::ORB_Table::table void   ) 
 

Accessor to the underlying table_.

Definition at line 38 of file ORB_Table.inl.

00039 {
00040   return &this->table_;
00041 }

int TAO::ORB_Table::unbind const char *  orb_id  ) 
 

Definition at line 100 of file ORB_Table.cpp.

References ACE_GUARD_RETURN, begin(), TAO::ORB_Core_Ref_Counter::core(), end(), first_orb_, and TAO_SYNCH_MUTEX.

00101 {
00102   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00103                     guard,
00104                     this->lock_,
00105                     -1);
00106 
00107   iterator const result = this->table_.find (key_type (orb_id));
00108 
00109   if (result != this->end ())
00110     {
00111       TAO::ORB_Core_Ref_Counter oc ((*result).second);
00112 
00113       this->table_.erase (result);
00114 
00115       if (oc.core () == this->first_orb_)
00116         {
00117           if (!this->table_.empty ())
00118             {
00119               this->first_orb_ = (*this->begin ()).second.core ();
00120             }
00121           else
00122             {
00123               this->first_orb_ = 0;
00124             }
00125         }
00126     }
00127 
00128   return 0;
00129 }


Friends And Related Function Documentation

friend class ::TAO_ORB_Core [friend]
 

Definition at line 65 of file ORB_Table.h.


Member Data Documentation

::TAO_ORB_Core* TAO::ORB_Table::first_orb_ [private]
 

The first ORB created by the user.

Definition at line 146 of file ORB_Table.h.

Referenced by bind(), first_orb(), not_default(), set_default(), and unbind().

bool TAO::ORB_Table::first_orb_not_default_ [private]
 

Variable to check if the first ORB decides not to be the default.

Definition at line 140 of file ORB_Table.h.

Referenced by bind(), and not_default().

::TAO_SYNCH_MUTEX TAO::ORB_Table::lock_ [private]
 

Lock used to synchronize access to the internal state.

Definition at line 136 of file ORB_Table.h.

size_t TAO::ORB_Table::num_orbs_ [private]
 

Number of ORBs in the table.

Definition at line 155 of file ORB_Table.h.

Referenced by get_orbs().

::TAO_ORB_Core** TAO::ORB_Table::orbs_ [private]
 

List of orbs for get_orbs call.

Todo:
ORB_Table::orbs_ appears to be unused. Remove it?

Definition at line 152 of file ORB_Table.h.

Referenced by get_orbs().

Table TAO::ORB_Table::table_ [private]
 

The underlying table.

Definition at line 143 of file ORB_Table.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 12:26:37 2006 for TAO by doxygen 1.3.6