Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Remote_Name_Space.cpp

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

Generated on Mon Jun 16 11:21:04 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002