1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
#include "Object_Ref_Table.h"
#include "Object.h"
#include "ORB.h"
#include "Exception.h"
#include "Environment.h"
#include "CORBA_String.h"
#include "debug.h"
ACE_RCSID (tao,
Object_Ref_Table,
"$Id$")
// ****************************************************************
TAO_Object_Ref_Table::TAO_Object_Ref_Table (void)
: table_ (TAO_DEFAULT_OBJECT_REF_TABLE_SIZE)
{
}
TAO_Object_Ref_Table::~TAO_Object_Ref_Table (void)
{
// Must explicitly call destroy() in the destructor since not all
// applications will invoke ORB::shutdown() or ORB::destroy().
this->destroy ();
}
void
TAO_Object_Ref_Table::register_initial_reference (
const char *id,
CORBA::Object_ptr obj
ACE_ENV_ARG_DECL)
{
if (id == 0 || ACE_OS_String::strlen (id) == 0)
ACE_THROW (CORBA::ORB::InvalidName ());
else if (CORBA::is_nil (obj))
ACE_THROW (CORBA::BAD_PARAM (CORBA::OMGVMCID | 27,
CORBA::COMPLETED_NO));
int result = this->bind (id, obj);
if (result == 1)
{
if (TAO_debug_level > 1)
ACE_ERROR ((LM_ERROR,
"(%P|%t) Object_Ref_Table::register_initial_reference:\n"
" Could not register duplicate object <%s> with "
"the ORB\n",
id));
ACE_THROW (CORBA::ORB::InvalidName ());
}
if (result == -1)
{
if (TAO_debug_level > 1)
ACE_ERROR ((LM_ERROR,
"(%P|%t) Object_Ref_Table::register_initial_reference:\n"
" Could not register object <%s> with "
"the ORB\n",
id));
ACE_THROW (CORBA::INTERNAL ());
}
}
CORBA::Object_ptr
TAO_Object_Ref_Table::resolve_initial_references (
const char *id
ACE_ENV_ARG_DECL_NOT_USED)
{
return this->find (id); // Returns a duplicate.
}
void
TAO_Object_Ref_Table::destroy (void)
{
for (Iterator i = this->begin ();
i != this->end ();
++i)
{
// Deallocate the id.
CORBA::string_free (ACE_const_cast (char *, (*i).ext_id_));
// Release the Object.
CORBA::release ((*i).int_id_);
}
this->table_.unbind_all ();
}
TAO_Object_Ref_Table::Iterator
TAO_Object_Ref_Table::begin (void)
{
return this->table_.begin ();
}
TAO_Object_Ref_Table::Iterator
TAO_Object_Ref_Table::end (void)
{
return this->table_.end ();
}
size_t
TAO_Object_Ref_Table::current_size (void) const
{
return this->table_.current_size ();
}
int
TAO_Object_Ref_Table::bind (const char *id,
CORBA::Object_ptr obj)
{
// Make sure that the supplied Object reference is valid,
// i.e. not nil.
if (id == 0 || CORBA::is_nil (obj))
{
errno = EINVAL;
return -1;
};
CORBA::String_var name = CORBA::string_dup (id);
CORBA::Object_var object = CORBA::Object::_duplicate (obj);
int result = this->table_.bind (name.in (),
object.in ());
if (result == 0)
{
// Transfer ownership to the Object Table.
(void) name._retn ();
(void) object._retn ();
}
return result;
}
CORBA::Object_ptr
TAO_Object_Ref_Table::find (const char *id)
{
CORBA::Object_ptr found = CORBA::Object::_nil ();
this->table_.find (id, found);
return CORBA::Object::_duplicate (found);
}
int
TAO_Object_Ref_Table::unbind (const char *id)
{
Table::ENTRY *entry = 0;
int result = this->table_.find (id, entry);
if (result == 0)
{
// Deallocate the external ID and obtain the ORB core pointer
// before unbinding the entry since the entry is deallocated
// during the call to unbind().
CORBA::string_free (ACE_const_cast (char *, entry->ext_id_));
CORBA::Object_ptr obj = entry->int_id_;
result = this->table_.unbind (entry);
if (result != 0)
return result;
CORBA::release (obj);
}
return result;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Hash_Map_Entry<const char *, CORBA::Object_ptr>;
template class ACE_Hash_Map_Manager_Ex<const char *, CORBA::Object_ptr, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_MUTEX>;
template class ACE_Hash_Map_Iterator_Base_Ex<const char *, CORBA::Object_ptr, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_MUTEX>;
template class ACE_Hash_Map_Iterator_Ex<const char *, CORBA::Object_ptr, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_MUTEX>;
template class ACE_Hash_Map_Reverse_Iterator_Ex<const char *, CORBA::Object_ptr, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_MUTEX>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Hash_Map_Entry<const char *, CORBA::Object_ptr>
#pragma instantiate ACE_Hash_Map_Manager_Ex<const char *, CORBA::Object_ptr, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_MUTEX>
#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<const char *, CORBA::Object_ptr, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_MUTEX>
#pragma instantiate ACE_Hash_Map_Iterator_Ex<const char *, CORBA::Object_ptr, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_MUTEX>
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<const char *, CORBA::Object_ptr, ACE_Hash<const char *>, ACE_Equal_To<const char *>, TAO_SYNCH_MUTEX>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|