Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Remote_Name_Space.cpp
blob286f0911c32b38459c41fb1fcb77e8ff1de98083
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"
5 #include <memory>
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 ()
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 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,
51 name_urep.get (),
52 name_len,
53 value_urep.get (),
54 value_len,
55 type,
56 type_len);
57 return this->ns_proxy_.request_reply (request);
60 int
61 ACE_Remote_Name_Space::rebind (const ACE_NS_WString &name,
62 const ACE_NS_WString &value,
63 const char *type)
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,
72 name_urep.get (),
73 name_len,
74 value_urep.get (),
75 value_len,
76 type,
77 type_len);
78 return this->ns_proxy_.request_reply (request);
81 int
82 ACE_Remote_Name_Space::resolve (const ACE_NS_WString &name,
83 ACE_NS_WString &value,
84 char *&type)
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,
90 name_urep.get (),
91 name_len,
92 0, 0, 0, 0);
94 if (this->ns_proxy_.send_request (request) == -1)
95 return -1;
97 ACE_Name_Request reply;
99 if (this->ns_proxy_.recv_reply (reply) == -1)
100 return -1;
102 ACE_NS_WString temp (reply.value (), reply.value_len () / sizeof (ACE_WCHAR_T));
103 value = temp;
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))),
107 -1);
108 #else
109 ACE_NEW_RETURN (type,
110 char[reply.type_len () + 1],
111 -1);
112 #endif /* ACE_HAS_ALLOC_HOOKS */
113 ACE_OS::strcpy (type, reply.type ());
114 return 0;
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,
124 name_urep.get (),
125 name_len,
126 0, 0, 0, 0);
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,
138 pattern_urep.get (),
139 pattern_len,
140 0, 0, 0, 0);
141 if (this->ns_proxy_.send_request (request) == -1)
142 return -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,
150 ACE_TEXT ("%p\n"),
151 ACE_TEXT ("ACE_Remote_Name_Space::list_names")),
152 -1);
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));
157 set.insert (name);
160 return 0;
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,
171 pattern_urep.get (),
172 pattern_len,
173 0, 0, 0, 0);
174 if (this->ns_proxy_.send_request (request) == -1)
175 return -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,
183 ACE_TEXT ("%p\n"),
184 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
185 -1);
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));
190 set.insert (value);
194 return 0;
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,
205 pattern_urep.get (),
206 pattern_len,
207 0, 0, 0, 0);
209 if (this->ns_proxy_.send_request (request) == -1)
210 return -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,
218 ACE_TEXT ("%p\n"),
219 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
220 -1);
221 if (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
223 ACE_NS_WString type (reply.type ());
224 set.insert (type);
228 return 0;
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,
239 pattern_urep.get (),
240 pattern_len,
241 0, 0, 0, 0);
243 if (this->ns_proxy_.send_request (request) == -1)
244 return -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,
252 ACE_TEXT ("%p\n"),
253 ACE_TEXT ("ACE_Remote_Name_Space::list_names")),
254 -1);
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,
262 value,
263 reply.type ());
264 if (set.insert (entry) == -1)
265 return -1;
268 return 0;
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,
279 pattern_urep.get (),
280 pattern_len,
281 0, 0, 0, 0);
283 if (this->ns_proxy_.send_request (request) == -1)
284 return -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,
292 ACE_TEXT ("%p\n"),
293 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
294 -1);
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,
302 value,
303 reply.type());
304 if (set.insert (entry) == -1)
305 return -1;
308 return 0;
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,
319 pattern_urep.get (),
320 pattern_len,
321 0, 0, 0, 0);
323 if (this->ns_proxy_.send_request (request) == -1)
324 return -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,
332 ACE_TEXT ("%p\n"),
333 ACE_TEXT ("ACE_Remote_Name_Space::list_values")),
334 -1);
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,
342 value,
343 reply.type ());
344 if (set.insert (entry) == -1)
345 return -1;
348 return 0;
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)
358 void
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