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

Registry_Name_Space.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: Registry_Name_Space.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:22 chad Exp $
00003 
00004 #include "ace/Registry_Name_Space.h"
00005 
00006 ACE_RCSID(ace, Registry_Name_Space, "$Id: Registry_Name_Space.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:22 chad Exp $")
00007 
00008 #if (defined (ACE_WIN32) && defined (UNICODE))
00009 // This only works on Win32 platforms when UNICODE is turned on
00010 
00011 ACE_Registry_Name_Space::ACE_Registry_Name_Space (void)
00012 {
00013 }
00014 
00015 ACE_Registry_Name_Space::ACE_Registry_Name_Space (ACE_Name_Options *name_options)
00016 {
00017   if (this->open (name_options) != 0)
00018     ACE_ERROR ((LM_ERROR,  ACE_LIB_TEXT ("%p\n"),
00019                 ACE_LIB_TEXT ("ACE_Registry_Name_Space::open")));
00020 }
00021 
00022 
00023 ACE_Registry_Name_Space::~ACE_Registry_Name_Space (void)
00024 {
00025 }
00026 
00027 
00028 int
00029 ACE_Registry_Name_Space::open (ACE_Name_Options *name_options)
00030 {
00031   const ACE_TCHAR *host = name_options->nameserver_host ();
00032   ACE_Registry::Naming_Context predefined;
00033 
00034   int result = ACE_Predefined_Naming_Contexts::connect (predefined,
00035                                                         HKEY_LOCAL_MACHINE,
00036                                                         host);
00037   if (result != 0)
00038     ACE_ERROR_RETURN ((LM_ERROR,  ACE_LIB_TEXT ("%p\n"),
00039                        ACE_LIB_TEXT ("ACE_Predefined_Naming_Context::connect")),
00040                       result);
00041   else
00042     {
00043       // Directory
00044       ACE_TString name = name_options->namespace_dir ();
00045       // Separator
00046       name += ACE_Registry::STRING_SEPARATOR;
00047       // Filename
00048       name += name_options->database ();
00049 
00050       // Create new context or bind to existing one
00051       result = predefined.bind_context (name,
00052                                         this->context_);
00053       if (result != 0)
00054         ACE_ERROR_RETURN ((LM_ERROR,  ACE_LIB_TEXT ("%p\n"),  ACE_LIB_TEXT ("ACE_Registry::Naming_Context::bind_context")), result);
00055     }
00056   return 0;
00057 }
00058 
00059 
00060 int
00061 ACE_Registry_Name_Space::bind (const ACE_NS_WString &name,
00062                                const ACE_NS_WString &value,
00063                                const char *type)
00064 {
00065   ACE_UNUSED_ARG(type);
00066 
00067   // Pointer to data
00068   const ACE_WSTRING_TYPE *data = value.fast_rep ();
00069 
00070   // Size
00071   u_long size = value.length () * sizeof (ACE_WSTRING_TYPE);
00072 
00073   // Represent value as an ACE_Registry::Object
00074   ACE_Registry::Object object ((void *) data,
00075                                size,
00076                                REG_SZ);
00077   // Add new <key>/<value> pair
00078 #if defined ACE_USES_WCHAR
00079   return this->context_.bind (name.fast_rep(),
00080                               object);
00081 #else
00082   return this->context_.bind (name.char_rep(),
00083                               object);
00084 #endif /* ACE_HAS_WCHAR */
00085 }
00086 
00087 
00088 int
00089 ACE_Registry_Name_Space::rebind (const ACE_NS_WString &name,
00090                                  const ACE_NS_WString &value,
00091                                  const char *type)
00092 {
00093   ACE_UNUSED_ARG(type);
00094 
00095   // Pointer to data
00096   const ACE_WSTRING_TYPE *data = value.fast_rep ();
00097 
00098   // Size
00099   u_long size = value.length () * sizeof (ACE_WSTRING_TYPE);
00100 
00101   // Represent value as an ACE_Registry::Object
00102   ACE_Registry::Object object ((void *) data,
00103                                size,
00104                                REG_SZ);
00105   // Add new <key>/<value> pair
00106 #if defined (ACE_USES_WCHAR)
00107   return this->context_.rebind (name.fast_rep (),
00108                                 object);
00109 #else
00110   return this->context_.rebind (name.char_rep (),
00111                                 object);
00112 #endif /* ACE_USES_WCHAR */
00113 }
00114 
00115 
00116 int
00117 ACE_Registry_Name_Space::unbind (const ACE_NS_WString &name)
00118 {
00119 #if defined (ACE_USES_WCHAR)
00120   return this->context_.unbind (name.fast_rep ());
00121 #else
00122   return this->context_.unbind (name.char_rep ());
00123 #endif /* ACE_USES_WCHAR */
00124 }
00125 
00126 
00127 int
00128 ACE_Registry_Name_Space::resolve (const ACE_NS_WString &name,
00129                                   ACE_NS_WString &value,
00130                                   char *&type)
00131 {
00132   ACE_UNUSED_ARG(type);
00133 
00134   // This object will be used to query the size of the data.
00135   // Note: The query_object.data will be null for this invocation.
00136   ACE_Registry::Object query_object;
00137   int result =
00138 #if defined (ACE_USES_WCHAR)
00139     this->context_.resolve (name.fast_rep (), query_object);
00140 #else
00141     this->context_.resolve (name.char_rep (), query_object);
00142 #endif /* ACE_USES_WCHAR */
00143   if (result != 0)
00144     return result;
00145 
00146   // Resize the value passed by the user
00147   // Note: -1 is used because the size includes the null terminator
00148   value.resize ((query_object.size () - 1) / sizeof (ACE_WSTRING_TYPE));
00149 
00150   // Represent new space as an ACE_Registry::Object
00151   ACE_Registry::Object object ((void *) value.fast_rep (),
00152                                query_object.size (),
00153                                REG_SZ);
00154 
00155 #if defined (ACE_USES_WCHAR)
00156   result = this->context_.resolve (name.fast_rep (), object);
00157 #else
00158   result = this->context_.resolve (name.char_rep (), object);
00159 #endif /* ACE_USES_WCHAR */
00160   if (object.size () != query_object.size ())
00161     return -1;
00162   if (result != 0)
00163     return result;
00164 
00165   return 0;
00166 }
00167 
00168 
00169 int
00170 ACE_Registry_Name_Space:: list_names (ACE_WSTRING_SET &set,
00171                                       const ACE_NS_WString &pattern)
00172 {
00173   ACE_BINDING_SET binding_set;
00174   int result = this->list_name_entries (binding_set,
00175                                         pattern);
00176   if (result != 0)
00177     return result;
00178 
00179   ACE_BINDING_ITERATOR iterator (binding_set);
00180 
00181   for (ACE_Name_Binding *entry = 0;
00182        iterator.next (entry) !=0;
00183        iterator.advance())
00184     {
00185       set.insert (entry->name_);
00186     }
00187   return 0;
00188 }
00189 
00190 
00191 int
00192 ACE_Registry_Name_Space::list_values (ACE_WSTRING_SET &set,
00193                                       const ACE_NS_WString &pattern)
00194 {
00195   ACE_BINDING_SET binding_set;
00196   int result = this->list_name_entries (binding_set,
00197                                         pattern);
00198   if (result != 0)
00199     return result;
00200 
00201   ACE_BINDING_ITERATOR iterator (binding_set);
00202 
00203   for (ACE_Name_Binding *entry = 0;
00204        iterator.next (entry) !=0;
00205        iterator.advance())
00206     {
00207       set.insert (entry->value_);
00208     }
00209   return 0;
00210 }
00211 
00212 
00213 int
00214 ACE_Registry_Name_Space::list_types (ACE_WSTRING_SET &set,
00215                                      const ACE_NS_WString &pattern)
00216 {
00217   ACE_UNUSED_ARG(set);
00218   ACE_UNUSED_ARG(pattern);
00219 
00220   return 0;
00221 }
00222 
00223 
00224 int
00225 ACE_Registry_Name_Space::list_name_entries (ACE_BINDING_SET &set,
00226                                             const ACE_NS_WString &pattern)
00227 {
00228   ACE_UNUSED_ARG(pattern);
00229 
00230   ACE_Registry::Binding_List list;
00231   int result = this->context_.list (list);
00232   if (result != 0)
00233     return result;
00234 
00235   // Iterator through all entries
00236   for (ACE_Registry::Binding_List::iterator i = list.begin ();
00237        i != list.end ();
00238        i++)
00239     {
00240       // Yeeesss! STL rules!
00241       ACE_Registry::Binding &binding = *i;
00242 
00243       if (binding.type () == ACE_Registry::OBJECT)
00244         {
00245           // Key
00246           ACE_TString string = binding.name ();
00247           ACE_NS_WString key (string.c_str ());
00248 
00249           // Value
00250           ACE_NS_WString value;
00251           char *type = 0;
00252           result = this->resolve (key,
00253                                   value,
00254                                   type);
00255           if (result != 0)
00256             ACE_ERROR_RETURN ((LM_ERROR,  ACE_LIB_TEXT ("%p\n"),  ACE_LIB_TEXT ("ACE_Registry::Naming_Context::resolve")), result);
00257 
00258           // Complete binding
00259           ACE_Name_Binding binding (key, value, type);
00260           set.insert (binding);
00261         }
00262     }
00263   return 0;
00264 }
00265 
00266 
00267 int
00268 ACE_Registry_Name_Space::list_value_entries (ACE_BINDING_SET &set,
00269                                              const ACE_NS_WString &pattern)
00270 {
00271   return this->list_name_entries (set, pattern);
00272 }
00273 
00274 
00275 int
00276 ACE_Registry_Name_Space::list_type_entries (ACE_BINDING_SET &set,
00277                                             const ACE_NS_WString &pattern)
00278 {
00279   return this->list_name_entries (set, pattern);
00280 }
00281 
00282 
00283 void
00284 ACE_Registry_Name_Space::dump (void) const
00285 {
00286 }
00287 
00288 
00289 #endif /* ACE_WIN32 && UNICODE */

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