00001 #include "ace/Remote_Name_Space.h"
00002 #include "ace/Auto_Ptr.h"
00003 #include "ace/Log_Msg.h"
00004 #include "ace/SString.h"
00005 #include "ace/OS_NS_string.h"
00006
00007 ACE_RCSID (ace,
00008 Remote_Name_Space,
00009 "Remote_Name_Space.cpp,v 4.30 2006/04/19 19:13:09 jwillemsen Exp")
00010
00011 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00012
00013 int
00014 ACE_Remote_Name_Space::open (const ACE_TCHAR *servername, u_short port)
00015 {
00016 ACE_TRACE ("ACE_Remote_Name_Space::open");
00017 ACE_INET_Addr servaddr;
00018
00019
00020 if (servaddr.set (port, servername) == -1)
00021 return -1;
00022
00023
00024 if (this->ns_proxy_.open (servaddr) == -1)
00025 return -1;
00026
00027 return 0;
00028 }
00029
00030 ACE_Remote_Name_Space::ACE_Remote_Name_Space (void)
00031 {
00032 ACE_TRACE ("ACE_Remote_Name_Space::ACE_Remote_Name_Space");
00033 }
00034
00035 ACE_Remote_Name_Space::ACE_Remote_Name_Space (const ACE_TCHAR *hostname,
00036 u_short port)
00037 {
00038 ACE_TRACE ("ACE_Remote_Name_Space::ACE_Remote_Name_Space");
00039 if (this->open (hostname, port) == -1)
00040 ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("%p\n"), ACE_LIB_TEXT ("ACE_Remote_Name_Space::ACE_Remote_Name_Space")));
00041 }
00042
00043 int
00044 ACE_Remote_Name_Space::bind (const ACE_NS_WString &name,
00045 const ACE_NS_WString &value,
00046 const char *type)
00047 {
00048 ACE_TRACE ("ACE_Remote_Name_Space::bind");
00049 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> name_urep (name.rep ());
00050 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> value_urep (value.rep ());
00051 ACE_UINT32 name_len =
00052 static_cast<ACE_UINT32> (name.length () * sizeof (ACE_WCHAR_T));
00053 ACE_UINT32 value_len =
00054 static_cast<ACE_UINT32> (value.length () * sizeof (ACE_WCHAR_T));
00055 ACE_UINT32 type_len =
00056 static_cast<ACE_UINT32> (ACE_OS::strlen (type));
00057 ACE_Name_Request request (ACE_Name_Request::BIND,
00058 name_urep.get (),
00059 name_len,
00060 value_urep.get (),
00061 value_len,
00062 type,
00063 type_len);
00064 return this->ns_proxy_.request_reply (request);
00065 }
00066
00067 int
00068 ACE_Remote_Name_Space::rebind (const ACE_NS_WString &name,
00069 const ACE_NS_WString &value,
00070 const char *type)
00071 {
00072 ACE_TRACE ("ACE_Remote_Name_Space::rebind");
00073 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> name_urep (name.rep ());
00074 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> value_urep (value.rep ());
00075 ACE_UINT32 name_len =
00076 static_cast<ACE_UINT32> (name.length () * sizeof (ACE_WCHAR_T));
00077 ACE_UINT32 value_len =
00078 static_cast<ACE_UINT32> (value.length () * sizeof (ACE_WCHAR_T));
00079 ACE_UINT32 type_len =
00080 static_cast<ACE_UINT32> (ACE_OS::strlen (type));
00081 ACE_Name_Request request (ACE_Name_Request::REBIND,
00082 name_urep.get (),
00083 name_len,
00084 value_urep.get (),
00085 value_len,
00086 type,
00087 type_len);
00088 return this->ns_proxy_.request_reply (request);
00089 }
00090
00091 int
00092 ACE_Remote_Name_Space::resolve (const ACE_NS_WString &name,
00093 ACE_NS_WString &value,
00094 char *&type)
00095 {
00096 ACE_TRACE ("ACE_Remote_Name_Space::resolve");
00097 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> name_urep (name.rep ());
00098 ACE_UINT32 name_len =
00099 static_cast<ACE_UINT32> (name.length () * sizeof (ACE_WCHAR_T));
00100 ACE_Name_Request request (ACE_Name_Request::RESOLVE,
00101 name_urep.get (),
00102 name_len,
00103 0, 0, 0, 0);
00104
00105 if (this->ns_proxy_.send_request (request) == -1)
00106 return -1;
00107
00108 ACE_Name_Request reply;
00109
00110 if (this->ns_proxy_.recv_reply (reply) == -1)
00111 return -1;
00112
00113 ACE_NS_WString temp (reply.value (), reply.value_len () / sizeof (ACE_WCHAR_T));
00114 value = temp;
00115 ACE_NEW_RETURN (type,
00116 char[reply.type_len () + 1],
00117 -1);
00118 ACE_OS::strcpy (type, reply.type ());
00119 return 0;
00120 }
00121
00122 int
00123 ACE_Remote_Name_Space::unbind (const ACE_NS_WString &name)
00124 {
00125 ACE_TRACE ("ACE_Remote_Name_Space::unbind");
00126 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> name_urep (name.rep ());
00127 ACE_UINT32 name_len =
00128 static_cast<ACE_UINT32> (name.length () * sizeof (ACE_WCHAR_T));
00129 ACE_Name_Request request (ACE_Name_Request::UNBIND,
00130 name_urep.get (),
00131 name_len,
00132 0, 0, 0, 0);
00133 return this->ns_proxy_.request_reply (request);
00134 }
00135
00136 int
00137 ACE_Remote_Name_Space::list_names (ACE_WSTRING_SET &set,
00138 const ACE_NS_WString &pattern)
00139 {
00140 ACE_TRACE ("ACE_Remote_Name_Space::list_names");
00141 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> pattern_urep (pattern.rep ());
00142 ACE_UINT32 pattern_len =
00143 static_cast<ACE_UINT32> (pattern.length () * sizeof (ACE_WCHAR_T));
00144 ACE_Name_Request request (ACE_Name_Request::LIST_NAMES,
00145 pattern_urep.get (),
00146 pattern_len,
00147 0, 0, 0, 0);
00148 if (this->ns_proxy_.send_request (request) == -1)
00149 return -1;
00150
00151 ACE_Name_Request reply (0, 0, 0, 0, 0, 0, 0, 0);
00152
00153 while (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00154 {
00155 if (this->ns_proxy_.recv_reply (reply) == -1)
00156 ACE_ERROR_RETURN ((LM_ERROR,
00157 ACE_LIB_TEXT ("%p\n"),
00158 ACE_LIB_TEXT ("ACE_Remote_Name_Space::list_names")),
00159 -1);
00160 if (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00161 {
00162 ACE_NS_WString name (reply.name (),
00163 reply.name_len () / sizeof (ACE_WCHAR_T));
00164 set.insert (name);
00165 }
00166 }
00167 return 0;
00168 }
00169
00170 int
00171 ACE_Remote_Name_Space::list_values (ACE_WSTRING_SET &set,
00172 const ACE_NS_WString &pattern)
00173 {
00174 ACE_TRACE ("ACE_Remote_Name_Space::list_values");
00175 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> pattern_urep (pattern.rep ());
00176 ACE_UINT32 pattern_len =
00177 static_cast<ACE_UINT32> (pattern.length () * sizeof (ACE_WCHAR_T));
00178 ACE_Name_Request request (ACE_Name_Request::LIST_VALUES,
00179 pattern_urep.get (),
00180 pattern_len,
00181 0, 0, 0, 0);
00182 if (this->ns_proxy_.send_request (request) == -1)
00183 return -1;
00184
00185 ACE_Name_Request reply (0, 0, 0, 0, 0, 0, 0, 0);
00186
00187 while (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00188 {
00189 if (this->ns_proxy_.recv_reply (reply) == -1)
00190 ACE_ERROR_RETURN ((LM_ERROR,
00191 ACE_LIB_TEXT ("%p\n"),
00192 ACE_LIB_TEXT ("ACE_Remote_Name_Space::list_values")),
00193 -1);
00194 if (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00195 {
00196 ACE_NS_WString value (reply.value (),
00197 reply.value_len () / sizeof (ACE_WCHAR_T));
00198 set.insert (value);
00199 }
00200 }
00201
00202 return 0;
00203 }
00204
00205 int
00206 ACE_Remote_Name_Space::list_types (ACE_WSTRING_SET &set,
00207 const ACE_NS_WString &pattern)
00208 {
00209 ACE_TRACE ("ACE_Remote_Name_Space::list_types");
00210 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> pattern_urep (pattern.rep ());
00211 ACE_UINT32 pattern_len =
00212 static_cast<ACE_UINT32> (pattern.length () * sizeof (ACE_WCHAR_T));
00213 ACE_Name_Request request (ACE_Name_Request::LIST_TYPES,
00214 pattern_urep.get (),
00215 pattern_len,
00216 0, 0, 0, 0);
00217
00218 if (this->ns_proxy_.send_request (request) == -1)
00219 return -1;
00220
00221 ACE_Name_Request reply (0, 0, 0, 0, 0, 0, 0, 0);
00222
00223 while (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00224 {
00225 if (this->ns_proxy_.recv_reply (reply) == -1)
00226 ACE_ERROR_RETURN ((LM_ERROR,
00227 ACE_LIB_TEXT ("%p\n"),
00228 ACE_LIB_TEXT ("ACE_Remote_Name_Space::list_values")),
00229 -1);
00230 if (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00231 {
00232 ACE_NS_WString type (reply.type ());
00233 set.insert (type);
00234 }
00235 }
00236
00237 return 0;
00238 }
00239
00240 int
00241 ACE_Remote_Name_Space::list_name_entries (ACE_BINDING_SET &set,
00242 const ACE_NS_WString &pattern)
00243 {
00244 ACE_TRACE ("ACE_Remote_Name_Space::list_name_entries");
00245 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> pattern_urep (pattern.rep ());
00246 ACE_UINT32 pattern_len =
00247 static_cast<ACE_UINT32> (pattern.length () * sizeof (ACE_WCHAR_T));
00248 ACE_Name_Request request (ACE_Name_Request::LIST_NAME_ENTRIES,
00249 pattern_urep.get (),
00250 pattern_len,
00251 0, 0, 0, 0);
00252
00253 if (this->ns_proxy_.send_request (request) == -1)
00254 return -1;
00255
00256 ACE_Name_Request reply (0, 0, 0, 0, 0, 0, 0, 0);
00257
00258 while (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00259 {
00260 if (this->ns_proxy_.recv_reply (reply) == -1)
00261 ACE_ERROR_RETURN ((LM_ERROR,
00262 ACE_LIB_TEXT ("%p\n"),
00263 ACE_LIB_TEXT ("ACE_Remote_Name_Space::list_names")),
00264 -1);
00265 if (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00266 {
00267 ACE_NS_WString name (reply.name (),
00268 reply.name_len () / sizeof (ACE_WCHAR_T));
00269 ACE_NS_WString value (reply.value (),
00270 reply.value_len () / sizeof (ACE_WCHAR_T));
00271 ACE_Name_Binding entry (name,
00272 value,
00273 reply.type ());
00274 if (set.insert (entry) == -1)
00275 return -1;
00276 }
00277 }
00278 return 0;
00279 }
00280
00281 int
00282 ACE_Remote_Name_Space::list_value_entries (ACE_BINDING_SET &set,
00283 const ACE_NS_WString &pattern)
00284 {
00285 ACE_TRACE ("ACE_Remote_Name_Space::list_value_entries");
00286 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> pattern_urep (pattern.rep ());
00287 ACE_UINT32 pattern_len =
00288 static_cast<ACE_UINT32> (pattern.length () * sizeof (ACE_WCHAR_T));
00289 ACE_Name_Request request (ACE_Name_Request::LIST_VALUE_ENTRIES,
00290 pattern_urep.get (),
00291 pattern_len,
00292 0, 0, 0, 0);
00293
00294 if (this->ns_proxy_.send_request (request) == -1)
00295 return -1;
00296
00297 ACE_Name_Request reply (0, 0, 0, 0, 0, 0, 0, 0);
00298
00299 while (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00300 {
00301 if (this->ns_proxy_.recv_reply (reply) == -1)
00302 ACE_ERROR_RETURN ((LM_ERROR,
00303 ACE_LIB_TEXT ("%p\n"),
00304 ACE_LIB_TEXT ("ACE_Remote_Name_Space::list_values")),
00305 -1);
00306 if (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00307 {
00308 ACE_NS_WString name (reply.name (),
00309 reply.name_len () / sizeof (ACE_WCHAR_T));
00310 ACE_NS_WString value (reply.value (),
00311 reply.value_len () / sizeof (ACE_WCHAR_T));
00312 ACE_Name_Binding entry (name,
00313 value,
00314 reply.type());
00315 if (set.insert (entry) == -1)
00316 return -1;
00317 }
00318 }
00319 return 0;
00320 }
00321
00322 int
00323 ACE_Remote_Name_Space::list_type_entries (ACE_BINDING_SET &set,
00324 const ACE_NS_WString &pattern)
00325 {
00326 ACE_TRACE ("ACE_Remote_Name_Space::list_type_entries");
00327 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> pattern_urep (pattern.rep ());
00328 ACE_UINT32 pattern_len =
00329 static_cast<ACE_UINT32> (pattern.length () * sizeof (ACE_WCHAR_T));
00330 ACE_Name_Request request (ACE_Name_Request::LIST_TYPE_ENTRIES,
00331 pattern_urep.get (),
00332 pattern_len,
00333 0, 0, 0, 0);
00334
00335 if (this->ns_proxy_.send_request (request) == -1)
00336 return -1;
00337
00338 ACE_Name_Request reply (0, 0, 0, 0, 0, 0, 0, 0);
00339
00340 while (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00341 {
00342 if (this->ns_proxy_.recv_reply (reply) == -1)
00343 ACE_ERROR_RETURN ((LM_ERROR,
00344 ACE_LIB_TEXT ("%p\n"),
00345 ACE_LIB_TEXT ("ACE_Remote_Name_Space::list_values")),
00346 -1);
00347 if (reply.msg_type () != ACE_Name_Request::MAX_ENUM)
00348 {
00349 ACE_NS_WString name (reply.name (),
00350 reply.name_len () / sizeof (ACE_WCHAR_T));
00351 ACE_NS_WString value (reply.value (),
00352 reply.value_len () / sizeof (ACE_WCHAR_T));
00353 ACE_Name_Binding entry (name,
00354 value,
00355 reply.type ());
00356 if (set.insert (entry) == -1)
00357 return -1;
00358 }
00359 }
00360 return 0;
00361 }
00362
00363 ACE_Remote_Name_Space::~ACE_Remote_Name_Space (void)
00364 {
00365 ACE_TRACE ("ACE_Remote_Name_Space::~ACE_Remote_Name_Space");
00366 }
00367
00368 void
00369 ACE_Remote_Name_Space::dump (void) const
00370 {
00371 #if defined (ACE_HAS_DUMP)
00372 ACE_TRACE ("ACE_Remote_Name_Space::dump");
00373
00374 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00375 this->ns_proxy_.dump ();
00376 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00377 #endif
00378 }
00379
00380 ACE_END_VERSIONED_NAMESPACE_DECL