1 #include "ace/Remote_Name_Space.h"
2 #include "ace/Log_Category.h"
3 #include "ace/SString.h"
4 #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 ()
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 std::unique_ptr
<ACE_WCHAR_T
[]> name_urep (name
.rep ());
46 std::unique_ptr
<ACE_WCHAR_T
[]> value_urep (value
.rep ());
47 ACE_UINT32 name_len
= static_cast<ACE_UINT32
> (name
.length () * sizeof (ACE_WCHAR_T
));
48 ACE_UINT32 value_len
= static_cast<ACE_UINT32
> (value
.length () * sizeof (ACE_WCHAR_T
));
49 ACE_UINT32 type_len
= static_cast<ACE_UINT32
> (ACE_OS::strlen (type
));
50 ACE_Name_Request
request (ACE_Name_Request::BIND
,
57 return this->ns_proxy_
.request_reply (request
);
61 ACE_Remote_Name_Space::rebind (const ACE_NS_WString
&name
,
62 const ACE_NS_WString
&value
,
65 ACE_TRACE ("ACE_Remote_Name_Space::rebind");
66 std::unique_ptr
<ACE_WCHAR_T
[]> name_urep (name
.rep ());
67 std::unique_ptr
<ACE_WCHAR_T
[]> value_urep (value
.rep ());
68 ACE_UINT32 name_len
= static_cast<ACE_UINT32
> (name
.length () * sizeof (ACE_WCHAR_T
));
69 ACE_UINT32 value_len
= static_cast<ACE_UINT32
> (value
.length () * sizeof (ACE_WCHAR_T
));
70 ACE_UINT32 type_len
= static_cast<ACE_UINT32
> (ACE_OS::strlen (type
));
71 ACE_Name_Request
request (ACE_Name_Request::REBIND
,
78 return this->ns_proxy_
.request_reply (request
);
82 ACE_Remote_Name_Space::resolve (const ACE_NS_WString
&name
,
83 ACE_NS_WString
&value
,
86 ACE_TRACE ("ACE_Remote_Name_Space::resolve");
87 std::unique_ptr
<ACE_WCHAR_T
[]> name_urep (name
.rep ());
88 ACE_UINT32 name_len
= static_cast<ACE_UINT32
> (name
.length () * sizeof (ACE_WCHAR_T
));
89 ACE_Name_Request
request (ACE_Name_Request::RESOLVE
,
94 if (this->ns_proxy_
.send_request (request
) == -1)
97 ACE_Name_Request reply
;
99 if (this->ns_proxy_
.recv_reply (reply
) == -1)
102 ACE_NS_WString
temp (reply
.value (), reply
.value_len () / sizeof (ACE_WCHAR_T
));
104 #if defined (ACE_HAS_ALLOC_HOOKS)
105 ACE_ALLOCATOR_RETURN (type
,
106 static_cast<char*>(ACE_Allocator::instance()->malloc(sizeof(char) * (reply
.type_len () + 1))),
109 ACE_NEW_RETURN (type
,
110 char[reply
.type_len () + 1],
112 #endif /* ACE_HAS_ALLOC_HOOKS */
113 ACE_OS::strcpy (type
, reply
.type ());
118 ACE_Remote_Name_Space::unbind (const ACE_NS_WString
&name
)
120 ACE_TRACE ("ACE_Remote_Name_Space::unbind");
121 std::unique_ptr
<ACE_WCHAR_T
[]> name_urep (name
.rep ());
122 ACE_UINT32 name_len
= static_cast<ACE_UINT32
> (name
.length () * sizeof (ACE_WCHAR_T
));
123 ACE_Name_Request
request (ACE_Name_Request::UNBIND
,
127 return this->ns_proxy_
.request_reply (request
);
131 ACE_Remote_Name_Space::list_names (ACE_WSTRING_SET
&set
,
132 const ACE_NS_WString
&pattern
)
134 ACE_TRACE ("ACE_Remote_Name_Space::list_names");
135 std::unique_ptr
<ACE_WCHAR_T
[]> pattern_urep (pattern
.rep ());
136 ACE_UINT32 pattern_len
= static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
137 ACE_Name_Request
request (ACE_Name_Request::LIST_NAMES
,
141 if (this->ns_proxy_
.send_request (request
) == -1)
144 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
146 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
148 if (this->ns_proxy_
.recv_reply (reply
) == -1)
149 ACELIB_ERROR_RETURN ((LM_ERROR
,
151 ACE_TEXT ("ACE_Remote_Name_Space::list_names")),
153 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
155 ACE_NS_WString
name (reply
.name (),
156 reply
.name_len () / sizeof (ACE_WCHAR_T
));
164 ACE_Remote_Name_Space::list_values (ACE_WSTRING_SET
&set
,
165 const ACE_NS_WString
&pattern
)
167 ACE_TRACE ("ACE_Remote_Name_Space::list_values");
168 std::unique_ptr
<ACE_WCHAR_T
[]> pattern_urep (pattern
.rep ());
169 ACE_UINT32 pattern_len
= static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
170 ACE_Name_Request
request (ACE_Name_Request::LIST_VALUES
,
174 if (this->ns_proxy_
.send_request (request
) == -1)
177 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
179 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
181 if (this->ns_proxy_
.recv_reply (reply
) == -1)
182 ACELIB_ERROR_RETURN ((LM_ERROR
,
184 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
186 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
188 ACE_NS_WString
value (reply
.value (),
189 reply
.value_len () / sizeof (ACE_WCHAR_T
));
198 ACE_Remote_Name_Space::list_types (ACE_WSTRING_SET
&set
,
199 const ACE_NS_WString
&pattern
)
201 ACE_TRACE ("ACE_Remote_Name_Space::list_types");
202 std::unique_ptr
<ACE_WCHAR_T
[]> pattern_urep (pattern
.rep ());
203 ACE_UINT32 pattern_len
= static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
204 ACE_Name_Request
request (ACE_Name_Request::LIST_TYPES
,
209 if (this->ns_proxy_
.send_request (request
) == -1)
212 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
214 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
216 if (this->ns_proxy_
.recv_reply (reply
) == -1)
217 ACELIB_ERROR_RETURN ((LM_ERROR
,
219 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
221 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
223 ACE_NS_WString
type (reply
.type ());
232 ACE_Remote_Name_Space::list_name_entries (ACE_BINDING_SET
&set
,
233 const ACE_NS_WString
&pattern
)
235 ACE_TRACE ("ACE_Remote_Name_Space::list_name_entries");
236 std::unique_ptr
<ACE_WCHAR_T
[]> pattern_urep (pattern
.rep ());
237 ACE_UINT32 pattern_len
= static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
238 ACE_Name_Request
request (ACE_Name_Request::LIST_NAME_ENTRIES
,
243 if (this->ns_proxy_
.send_request (request
) == -1)
246 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
248 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
250 if (this->ns_proxy_
.recv_reply (reply
) == -1)
251 ACELIB_ERROR_RETURN ((LM_ERROR
,
253 ACE_TEXT ("ACE_Remote_Name_Space::list_names")),
255 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
257 ACE_NS_WString
name (reply
.name (),
258 reply
.name_len () / sizeof (ACE_WCHAR_T
));
259 ACE_NS_WString
value (reply
.value (),
260 reply
.value_len () / sizeof (ACE_WCHAR_T
));
261 ACE_Name_Binding
entry (name
,
264 if (set
.insert (entry
) == -1)
272 ACE_Remote_Name_Space::list_value_entries (ACE_BINDING_SET
&set
,
273 const ACE_NS_WString
&pattern
)
275 ACE_TRACE ("ACE_Remote_Name_Space::list_value_entries");
276 std::unique_ptr
<ACE_WCHAR_T
[]> pattern_urep (pattern
.rep ());
277 ACE_UINT32 pattern_len
= static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
278 ACE_Name_Request
request (ACE_Name_Request::LIST_VALUE_ENTRIES
,
283 if (this->ns_proxy_
.send_request (request
) == -1)
286 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
288 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
290 if (this->ns_proxy_
.recv_reply (reply
) == -1)
291 ACELIB_ERROR_RETURN ((LM_ERROR
,
293 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
295 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
297 ACE_NS_WString
name (reply
.name (),
298 reply
.name_len () / sizeof (ACE_WCHAR_T
));
299 ACE_NS_WString
value (reply
.value (),
300 reply
.value_len () / sizeof (ACE_WCHAR_T
));
301 ACE_Name_Binding
entry (name
,
304 if (set
.insert (entry
) == -1)
312 ACE_Remote_Name_Space::list_type_entries (ACE_BINDING_SET
&set
,
313 const ACE_NS_WString
&pattern
)
315 ACE_TRACE ("ACE_Remote_Name_Space::list_type_entries");
316 std::unique_ptr
<ACE_WCHAR_T
[]> pattern_urep (pattern
.rep ());
317 ACE_UINT32 pattern_len
= static_cast<ACE_UINT32
> (pattern
.length () * sizeof (ACE_WCHAR_T
));
318 ACE_Name_Request
request (ACE_Name_Request::LIST_TYPE_ENTRIES
,
323 if (this->ns_proxy_
.send_request (request
) == -1)
326 ACE_Name_Request
reply (0, 0, 0, 0, 0, 0, 0, 0);
328 while (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
330 if (this->ns_proxy_
.recv_reply (reply
) == -1)
331 ACELIB_ERROR_RETURN ((LM_ERROR
,
333 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
335 if (reply
.msg_type () != ACE_Name_Request::MAX_ENUM
)
337 ACE_NS_WString
name (reply
.name (),
338 reply
.name_len () / sizeof (ACE_WCHAR_T
));
339 ACE_NS_WString
value (reply
.value (),
340 reply
.value_len () / sizeof (ACE_WCHAR_T
));
341 ACE_Name_Binding
entry (name
,
344 if (set
.insert (entry
) == -1)
351 ACE_Remote_Name_Space::~ACE_Remote_Name_Space ()
353 ACE_TRACE ("ACE_Remote_Name_Space::~ACE_Remote_Name_Space");
356 ACE_ALLOC_HOOK_DEFINE(ACE_Remote_Name_Space
)
359 ACE_Remote_Name_Space::dump () const
361 #if defined (ACE_HAS_DUMP)
362 ACE_TRACE ("ACE_Remote_Name_Space::dump");
364 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
365 this->ns_proxy_
.dump ();
366 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
367 #endif /* ACE_HAS_DUMP */
370 ACE_END_VERSIONED_NAMESPACE_DECL