Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Object_Ref_Table.cpp
blob304a47a9decd45a1123aa079b73a48748ca3a703
1 #include "tao/Object_Ref_Table.h"
2 #include "tao/ORB.h"
3 #include "tao/debug.h"
4 #include "tao/ORB_Constants.h"
5 #include "tao/SystemException.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/Log_Msg.h"
8 #include <cstring>
10 #ifndef __ACE_INLINE__
11 # include "tao/Object_Ref_Table.inl"
12 #endif /* __ACE_INLINE__ */
14 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
16 int
17 TAO_Object_Ref_Table::register_initial_reference (
18 const char *id,
19 CORBA::Object_ptr obj,
20 bool rebind)
22 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
23 guard,
24 this->lock_,
25 -1);
27 if (rebind)
29 if (this->unbind_i (id) == -1)
30 return -1;
31 else
32 return this->bind_i (id, obj);
34 else
35 return this->bind_i (id, obj);
38 CORBA::Object_ptr
39 TAO_Object_Ref_Table::unregister_initial_reference (
40 const char *id)
42 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
43 guard,
44 this->lock_,
45 CORBA::Object::_nil());
47 CORBA::Object_ptr obj = this->find_i (id);
48 if (this->unbind_i (id) == -1)
50 if (TAO_debug_level > 1)
52 TAOLIB_ERROR ((LM_ERROR,
53 ACE_TEXT ("(%P|%t) Object_Ref_Table::bind_i: ")
54 ACE_TEXT ("Could not unregister object <%C> ")
55 ACE_TEXT ("from the ORB\n"),
56 id));
60 return obj;
63 int
64 TAO_Object_Ref_Table::bind_i (const char *id, CORBA::Object_ptr obj)
66 // Make sure that the supplied Object reference is valid,
67 // i.e. not nil.
68 if (id == nullptr
69 || std::strlen (id) == 0
70 || ::CORBA::is_nil (obj))
72 errno = EINVAL;
73 return -1;
76 Table::value_type const value =
77 std::make_pair (CORBA::String_var (id),
78 CORBA::Object_var (CORBA::Object::_duplicate (obj)));
80 std::pair<iterator, bool> const result = this->table_.insert (value);
82 if (!result.second)
84 if (TAO_debug_level > 1)
86 TAOLIB_ERROR ((LM_ERROR,
87 ACE_TEXT ("(%P|%t) Object_Ref_Table::bind_i: ")
88 ACE_TEXT ("Could not register duplicate object <%C> ")
89 ACE_TEXT ("with the ORB\n"),
90 id));
93 return -1;
96 return 0;
99 CORBA::Object_ptr
100 TAO_Object_Ref_Table::resolve_initial_reference (const char * id)
102 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
103 guard,
104 this->lock_,
105 CORBA::Object::_nil ());
107 return this->find_i (id); // Returns a duplicate.
110 TAO_END_VERSIONED_NAMESPACE_DECL