1 #include "ace/Remote_Name_Space.h"
2 #include "ace/Auto_Ptr.h"
3 #include "ace/Log_Category.h"
4 #include "ace/SString.h"
5 #include "ace/OS_NS_string.h"
7 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
10 ACE_Remote_Name_Space::open (const ACE_TCHAR
*servername
, u_short port
)
12 ACE_TRACE ("ACE_Remote_Name_Space::open");
13 ACE_INET_Addr servaddr
;
16 if (servaddr
.set (port
, servername
) == -1)
19 // Connect to Name Server process.
20 if (this->ns_proxy_
.open (servaddr
) == -1)
26 ACE_Remote_Name_Space::ACE_Remote_Name_Space (void)
28 ACE_TRACE ("ACE_Remote_Name_Space::ACE_Remote_Name_Space");
31 ACE_Remote_Name_Space::ACE_Remote_Name_Space (const ACE_TCHAR
*hostname
,
34 ACE_TRACE ("ACE_Remote_Name_Space::ACE_Remote_Name_Space");
35 if (this->open (hostname
, port
) == -1)
36 ACELIB_ERROR ((LM_ERROR
, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Remote_Name_Space::ACE_Remote_Name_Space")));
40 ACE_Remote_Name_Space::bind (const ACE_NS_WString
&name
,
41 const ACE_NS_WString
&value
,
44 ACE_TRACE ("ACE_Remote_Name_Space::bind");
45 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> name_urep (name
.rep ());
46 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> value_urep (value
.rep ());
48 static_cast<ACE_UINT32
> (name
.length () * sizeof (ACE_WCHAR_T
));
49 ACE_UINT32 value_len
=
50 static_cast<ACE_UINT32
> (value
.length () * sizeof (ACE_WCHAR_T
));
52 static_cast<ACE_UINT32
> (ACE_OS::strlen (type
));
53 ACE_Name_Request
request (ACE_Name_Request::BIND
,
60 return this->ns_proxy_
.request_reply (request
);
64 ACE_Remote_Name_Space::rebind (const ACE_NS_WString
&name
,
65 const ACE_NS_WString
&value
,
68 ACE_TRACE ("ACE_Remote_Name_Space::rebind");
69 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> name_urep (name
.rep ());
70 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> value_urep (value
.rep ());
72 static_cast<ACE_UINT32
> (name
.length () * sizeof (ACE_WCHAR_T
));
73 ACE_UINT32 value_len
=
74 static_cast<ACE_UINT32
> (value
.length () * sizeof (ACE_WCHAR_T
));
76 static_cast<ACE_UINT32
> (ACE_OS::strlen (type
));
77 ACE_Name_Request
request (ACE_Name_Request::REBIND
,
84 return this->ns_proxy_
.request_reply (request
);
88 ACE_Remote_Name_Space::resolve (const ACE_NS_WString
&name
,
89 ACE_NS_WString
&value
,
92 ACE_TRACE ("ACE_Remote_Name_Space::resolve");
93 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> name_urep (name
.rep ());
95 static_cast<ACE_UINT32
> (name
.length () * sizeof (ACE_WCHAR_T
));
96 ACE_Name_Request
request (ACE_Name_Request::RESOLVE
,
101 if (this->ns_proxy_
.send_request (request
) == -1)
104 ACE_Name_Request reply
;
106 if (this->ns_proxy_
.recv_reply (reply
) == -1)
109 ACE_NS_WString
temp (reply
.value (), reply
.value_len () / sizeof (ACE_WCHAR_T
));
111 #if defined (ACE_HAS_ALLOC_HOOKS)
112 ACE_ALLOCATOR_RETURN (type
,
113 static_cast<char*>(ACE_Allocator::instance()->malloc(sizeof(char) * (reply
.type_len () + 1))),
116 ACE_NEW_RETURN (type
,
117 char[reply
.type_len () + 1],
119 #endif /* ACE_HAS_ALLOC_HOOKS */
120 ACE_OS::strcpy (type
, reply
.type ());
125 ACE_Remote_Name_Space::unbind (const ACE_NS_WString
&name
)
127 ACE_TRACE ("ACE_Remote_Name_Space::unbind");
128 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> name_urep (name
.rep ());
129 ACE_UINT32 name_len
=
130 static_cast<ACE_UINT32
> (name
.length () * sizeof (ACE_WCHAR_T
));
131 ACE_Name_Request
request (ACE_Name_Request::UNBIND
,
135 return this->ns_proxy_
.request_reply (request
);
139 ACE_Remote_Name_Space::list_names (ACE_WSTRING_SET
&set
,
140 const ACE_NS_WString
&pattern
)
142 ACE_TRACE ("ACE_Remote_Name_Space::list_names");
143 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> pattern_urep (pattern
.rep ());
144 ACE_UINT32 pattern_len
=
145 static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
146 ACE_Name_Request
request (ACE_Name_Request::LIST_NAMES
,
150 if (this->ns_proxy_
.send_request (request
) == -1)
153 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
155 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
157 if (this->ns_proxy_
.recv_reply (reply
) == -1)
158 ACELIB_ERROR_RETURN ((LM_ERROR
,
160 ACE_TEXT ("ACE_Remote_Name_Space::list_names")),
162 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
164 ACE_NS_WString
name (reply
.name (),
165 reply
.name_len () / sizeof (ACE_WCHAR_T
));
173 ACE_Remote_Name_Space::list_values (ACE_WSTRING_SET
&set
,
174 const ACE_NS_WString
&pattern
)
176 ACE_TRACE ("ACE_Remote_Name_Space::list_values");
177 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> pattern_urep (pattern
.rep ());
178 ACE_UINT32 pattern_len
=
179 static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
180 ACE_Name_Request
request (ACE_Name_Request::LIST_VALUES
,
184 if (this->ns_proxy_
.send_request (request
) == -1)
187 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
189 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
191 if (this->ns_proxy_
.recv_reply (reply
) == -1)
192 ACELIB_ERROR_RETURN ((LM_ERROR
,
194 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
196 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
198 ACE_NS_WString
value (reply
.value (),
199 reply
.value_len () / sizeof (ACE_WCHAR_T
));
208 ACE_Remote_Name_Space::list_types (ACE_WSTRING_SET
&set
,
209 const ACE_NS_WString
&pattern
)
211 ACE_TRACE ("ACE_Remote_Name_Space::list_types");
212 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> pattern_urep (pattern
.rep ());
213 ACE_UINT32 pattern_len
=
214 static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
215 ACE_Name_Request
request (ACE_Name_Request::LIST_TYPES
,
220 if (this->ns_proxy_
.send_request (request
) == -1)
223 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
225 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
227 if (this->ns_proxy_
.recv_reply (reply
) == -1)
228 ACELIB_ERROR_RETURN ((LM_ERROR
,
230 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
232 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
234 ACE_NS_WString
type (reply
.type ());
243 ACE_Remote_Name_Space::list_name_entries (ACE_BINDING_SET
&set
,
244 const ACE_NS_WString
&pattern
)
246 ACE_TRACE ("ACE_Remote_Name_Space::list_name_entries");
247 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> pattern_urep (pattern
.rep ());
248 ACE_UINT32 pattern_len
=
249 static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
250 ACE_Name_Request
request (ACE_Name_Request::LIST_NAME_ENTRIES
,
255 if (this->ns_proxy_
.send_request (request
) == -1)
258 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
260 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
262 if (this->ns_proxy_
.recv_reply (reply
) == -1)
263 ACELIB_ERROR_RETURN ((LM_ERROR
,
265 ACE_TEXT ("ACE_Remote_Name_Space::list_names")),
267 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
269 ACE_NS_WString
name (reply
.name (),
270 reply
.name_len () / sizeof (ACE_WCHAR_T
));
271 ACE_NS_WString
value (reply
.value (),
272 reply
.value_len () / sizeof (ACE_WCHAR_T
));
273 ACE_Name_Binding
entry (name
,
276 if (set
.insert (entry
) == -1)
284 ACE_Remote_Name_Space::list_value_entries (ACE_BINDING_SET
&set
,
285 const ACE_NS_WString
&pattern
)
287 ACE_TRACE ("ACE_Remote_Name_Space::list_value_entries");
288 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> pattern_urep (pattern
.rep ());
289 ACE_UINT32 pattern_len
=
290 static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
291 ACE_Name_Request
request (ACE_Name_Request::LIST_VALUE_ENTRIES
,
296 if (this->ns_proxy_
.send_request (request
) == -1)
299 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
301 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
303 if (this->ns_proxy_
.recv_reply (reply
) == -1)
304 ACELIB_ERROR_RETURN ((LM_ERROR
,
306 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
308 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
310 ACE_NS_WString
name (reply
.name (),
311 reply
.name_len () / sizeof (ACE_WCHAR_T
));
312 ACE_NS_WString
value (reply
.value (),
313 reply
.value_len () / sizeof (ACE_WCHAR_T
));
314 ACE_Name_Binding
entry (name
,
317 if (set
.insert (entry
) == -1)
325 ACE_Remote_Name_Space::list_type_entries (ACE_BINDING_SET
&set
,
326 const ACE_NS_WString
&pattern
)
328 ACE_TRACE ("ACE_Remote_Name_Space::list_type_entries");
329 ACE_Auto_Basic_Array_Ptr
<ACE_WCHAR_T
> pattern_urep (pattern
.rep ());
330 ACE_UINT32 pattern_len
=
331 static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
332 ACE_Name_Request
request (ACE_Name_Request::LIST_TYPE_ENTRIES
,
337 if (this->ns_proxy_
.send_request (request
) == -1)
340 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
342 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
344 if (this->ns_proxy_
.recv_reply (reply
) == -1)
345 ACELIB_ERROR_RETURN ((LM_ERROR
,
347 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
349 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
351 ACE_NS_WString
name (reply
.name (),
352 reply
.name_len () / sizeof (ACE_WCHAR_T
));
353 ACE_NS_WString
value (reply
.value (),
354 reply
.value_len () / sizeof (ACE_WCHAR_T
));
355 ACE_Name_Binding
entry (name
,
358 if (set
.insert (entry
) == -1)
365 ACE_Remote_Name_Space::~ACE_Remote_Name_Space (void)
367 ACE_TRACE ("ACE_Remote_Name_Space::~ACE_Remote_Name_Space");
370 ACE_ALLOC_HOOK_DEFINE(ACE_Remote_Name_Space
)
373 ACE_Remote_Name_Space::dump (void) const
375 #if defined (ACE_HAS_DUMP)
376 ACE_TRACE ("ACE_Remote_Name_Space::dump");
378 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
379 this->ns_proxy_
.dump ();
380 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
381 #endif /* ACE_HAS_DUMP */
384 ACE_END_VERSIONED_NAMESPACE_DECL