Object_Ref_Table.cpp

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

Generated on Tue Feb 2 17:37:52 2010 for TAO by  doxygen 1.4.7