Go to the documentation of this file.00001
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 83534 2008-11-03 12:47:26Z johnnyw $")
00015
00016 #ifndef __ACE_INLINE__
00017 # include "tao/Object_Ref_Table.inl"
00018 #endif
00019
00020
00021
00022
00023 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00024
00025 int
00026 TAO_Object_Ref_Table::register_initial_reference (
00027 const char *id,
00028 CORBA::Object_ptr obj,
00029 bool rebind)
00030 {
00031 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00032 guard,
00033 this->lock_,
00034 -1);
00035
00036 if (rebind)
00037 {
00038 if (this->unbind_i (id) == -1)
00039 return -1;
00040 else
00041 return this->bind_i (id, obj);
00042 }
00043 else
00044 return this->bind_i (id, obj);
00045 }
00046
00047 CORBA::Object_ptr
00048 TAO_Object_Ref_Table::unregister_initial_reference (
00049 const char *id)
00050 {
00051 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00052 guard,
00053 this->lock_,
00054 CORBA::Object::_nil());
00055
00056 CORBA::Object_ptr obj = this->find_i (id);
00057 if (this->unbind_i (id) == -1)
00058 {
00059 if (TAO_debug_level > 1)
00060 {
00061 ACE_ERROR ((LM_ERROR,
00062 ACE_TEXT ("(%P|%t) Object_Ref_Table::bind_i: ")
00063 ACE_TEXT ("Could not unregister object <%C> ")
00064 ACE_TEXT ("from the ORB\n"),
00065 id));
00066 }
00067 }
00068
00069 return obj;
00070 }
00071
00072 int
00073 TAO_Object_Ref_Table::bind_i (const char *id, CORBA::Object_ptr obj)
00074 {
00075
00076
00077 if (id == 0
00078 || ACE_OS::strlen (id) == 0
00079 || ::CORBA::is_nil (obj))
00080 {
00081 errno = EINVAL;
00082 return -1;
00083 };
00084
00085 Table::value_type const value =
00086 std::make_pair (CORBA::String_var (id),
00087 CORBA::Object_var (CORBA::Object::_duplicate (obj)));
00088
00089 std::pair<iterator, bool> const result = this->table_.insert (value);
00090
00091 if (!result.second)
00092 {
00093 if (TAO_debug_level > 1)
00094 {
00095 ACE_ERROR ((LM_ERROR,
00096 ACE_TEXT ("(%P|%t) Object_Ref_Table::bind_i: ")
00097 ACE_TEXT ("Could not register duplicate object <%C> ")
00098 ACE_TEXT ("with the ORB\n"),
00099 id));
00100 }
00101
00102 return -1;
00103 }
00104
00105 return 0;
00106 }
00107
00108 CORBA::Object_ptr
00109 TAO_Object_Ref_Table::resolve_initial_reference (const char * id)
00110 {
00111 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00112 guard,
00113 this->lock_,
00114 CORBA::Object::_nil ());
00115
00116 return this->find_i (id);
00117 }
00118
00119 TAO_END_VERSIONED_NAMESPACE_DECL