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