Object_Ref_Table.cpp

Go to the documentation of this file.
00001 // Object_Ref_Table.cpp,v 1.28 2006/04/19 08:55:54 jwillemsen Exp
00002 
00003 #include "tao/Object_Ref_Table.h"
00004 #include "tao/ORB.h"
00005 #include "tao/Environment.h"
00006 #include "tao/debug.h"
00007 #include "tao/ORB_Constants.h"
00008 #include "tao/SystemException.h"
00009 #include "ace/OS_NS_string.h"
00010 #include "ace/Log_Msg.h"
00011 
00012 
00013 ACE_RCSID (tao,
00014            Object_Ref_Table,
00015            "Object_Ref_Table.cpp,v 1.28 2006/04/19 08:55:54 jwillemsen Exp")
00016 
00017 #ifndef __ACE_INLINE__
00018 # include "tao/Object_Ref_Table.inl"
00019 #endif  /* __ACE_INLINE__ */
00020 
00021 
00022 // ****************************************************************
00023 
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 int
00027 TAO_Object_Ref_Table::bind (const char *id,
00028                             CORBA::Object_ptr obj)
00029 {
00030   // Make sure that the supplied Object reference is valid,
00031   // i.e. not nil.
00032   if (id == 0
00033       || ACE_OS::strlen (id) == 0
00034       || ::CORBA::is_nil (obj))
00035     {
00036       errno = EINVAL;
00037       return -1;
00038     };
00039 
00040   Table::value_type const value =
00041     std::make_pair (CORBA::String_var (id),
00042                     CORBA::Object_var (CORBA::Object::_duplicate (obj)));
00043 
00044   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00045                     guard,
00046                     this->lock_,
00047                     -1);
00048 
00049   std::pair<iterator, bool> const result = this->table_.insert (value);
00050 
00051   if (!result.second)
00052     {
00053       if (TAO_debug_level > 1)
00054         {
00055           ACE_ERROR ((LM_ERROR,
00056                       ACE_TEXT ("(%P|%t) Object_Ref_Table::")
00057                       ACE_TEXT ("bind:")
00058                       ACE_TEXT ("  Could not register duplicate object <%s> ")
00059                       ACE_TEXT ("with the ORB\n"),
00060                       ACE_TEXT_CHAR_TO_TCHAR (id)));
00061         }
00062 
00063       return -1;
00064     }
00065 
00066   return 0;
00067 }
00068 
00069 CORBA::Object_ptr
00070 TAO_Object_Ref_Table::find (const char *id)
00071 {
00072   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00073                     guard,
00074                     this->lock_,
00075                     CORBA::Object::_nil ());
00076 
00077   iterator const found =
00078     this->table_.find (CORBA::String_var (id));
00079 
00080   if (found == this->table_.end ())
00081     return CORBA::Object::_nil ();
00082 
00083   return CORBA::Object::_duplicate ((*found).second.in ());
00084 }
00085 
00086 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:16 2006 for TAO by doxygen 1.3.6