Removed ACE_HAS_BSTRING, not used
[ACE_TAO.git] / ACE / ace / Remote_Name_Space.cpp
blobc40d190ef3d030d72ca1dbcc06b00ae4febab7d0
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
9 int
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;
15 // Initialize Addr
16 if (servaddr.set (port, servername) == -1)
17 return -1;
19 // Connect to Name Server process.
20 if (this->ns_proxy_.open (servaddr) == -1)
21 return -1;
23 return 0;
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,
32 u_short port)
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")));
39 int
40 ACE_Remote_Name_Space::bind (const ACE_NS_WString &name,
41 const ACE_NS_WString &value,
42 const char *type)
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 ());
47 ACE_UINT32 name_len =
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));
51 ACE_UINT32 type_len =
52 static_cast<ACE_UINT32> (ACE_OS::strlen (type));
53 ACE_Name_Request request (ACE_Name_Request::BIND,
54 name_urep.get (),
55 name_len,
56 value_urep.get (),
57 value_len,
58 type,
59 type_len);
60 return this->ns_proxy_.request_reply (request);
63 int
64 ACE_Remote_Name_Space::rebind (const ACE_NS_WString &name,
65 const ACE_NS_WString &value,
66 const char *type)
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 ());
71 ACE_UINT32 name_len =
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));
75 ACE_UINT32 type_len =
76 static_cast<ACE_UINT32> (ACE_OS::strlen (type));
77 ACE_Name_Request request (ACE_Name_Request::REBIND,
78 name_urep.get (),
79 name_len,
80 value_urep.get (),
81 value_len,
82 type,
83 type_len);
84 return this->ns_proxy_.request_reply (request);
87 int
88 ACE_Remote_Name_Space::resolve (const ACE_NS_WString &name,
89 ACE_NS_WString &value,
90 char *&type)
92 ACE_TRACE ("ACE_Remote_Name_Space::resolve");
93 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> name_urep (name.rep ());
94 ACE_UINT32 name_len =
95 static_cast<ACE_UINT32> (name.length () * sizeof (ACE_WCHAR_T));
96 ACE_Name_Request request (ACE_Name_Request::RESOLVE,
97 name_urep.get (),
98 name_len,
99 0, 0, 0, 0);
101 if (this->ns_proxy_.send_request (request) == -1)
102 return -1;
104 ACE_Name_Request reply;
106 if (this->ns_proxy_.recv_reply (reply) == -1)
107 return -1;
109 ACE_NS_WString temp (reply.value (), reply.value_len () / sizeof (ACE_WCHAR_T));
110 value = temp;
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))),
114 -1);
115 #else
116 ACE_NEW_RETURN (type,
117 char[reply.type_len () + 1],
118 -1);
119 #endif /* ACE_HAS_ALLOC_HOOKS */
120 ACE_OS::strcpy (type, reply.type ());
121 return 0;
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,
132 name_urep.get (),
133 name_len,
134 0, 0, 0, 0);
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,
147 pattern_urep.get (),
148 pattern_len,
149 0, 0, 0, 0);
150 if (this->ns_proxy_.send_request (request) == -1)
151 return -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,
159 ACE_TEXT ("%p\n"),
160 ACE_TEXT ("ACE_Remote_Name_Space::list_names")),
161 -1);
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));
166 set.insert (name);
169 return 0;
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,
181 pattern_urep.get (),
182 pattern_len,
183 0, 0, 0, 0);
184 if (this->ns_proxy_.send_request (request) == -1)
185 return -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,
193 ACE_TEXT ("%p\n"),
194 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
195 -1);
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));
200 set.insert (value);
204 return 0;
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,
216 pattern_urep.get (),
217 pattern_len,
218 0, 0, 0, 0);
220 if (this->ns_proxy_.send_request (request) == -1)
221 return -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,
229 ACE_TEXT ("%p\n"),
230 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
231 -1);
232 if (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
234 ACE_NS_WString type (reply.type ());
235 set.insert (type);
239 return 0;
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,
251 pattern_urep.get (),
252 pattern_len,
253 0, 0, 0, 0);
255 if (this->ns_proxy_.send_request (request) == -1)
256 return -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,
264 ACE_TEXT ("%p\n"),
265 ACE_TEXT ("ACE_Remote_Name_Space::list_names")),
266 -1);
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,
274 value,
275 reply.type ());
276 if (set.insert (entry) == -1)
277 return -1;
280 return 0;
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,
292 pattern_urep.get (),
293 pattern_len,
294 0, 0, 0, 0);
296 if (this->ns_proxy_.send_request (request) == -1)
297 return -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,
305 ACE_TEXT ("%p\n"),
306 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
307 -1);
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,
315 value,
316 reply.type());
317 if (set.insert (entry) == -1)
318 return -1;
321 return 0;
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,
333 pattern_urep.get (),
334 pattern_len,
335 0, 0, 0, 0);
337 if (this->ns_proxy_.send_request (request) == -1)
338 return -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,
346 ACE_TEXT ("%p\n"),
347 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
348 -1);
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,
356 value,
357 reply.type ());
358 if (set.insert (entry) == -1)
359 return -1;
362 return 0;
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)
372 void
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