Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Registry_Name_Space.cpp
blob7422a7db69d9fa906b92d7f1383bab7c4478e0ed
1 #include "ace/Registry_Name_Space.h"
3 #if (defined (ACE_WIN32) && defined (ACE_USES_WCHAR))
4 // This only works on Win32 platforms when ACE_USES_WCHAR is turned on
6 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
8 ACE_Registry_Name_Space::ACE_Registry_Name_Space (ACE_Name_Options *name_options)
10 if (this->open (name_options) != 0)
11 ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"),
12 ACE_TEXT ("ACE_Registry_Name_Space::open")));
16 int
17 ACE_Registry_Name_Space::open (ACE_Name_Options *name_options)
19 const ACE_TCHAR *host = name_options->nameserver_host ();
20 ACE_Registry::Naming_Context predefined;
22 int result = ACE_Predefined_Naming_Contexts::connect (predefined,
23 HKEY_LOCAL_MACHINE,
24 host);
25 if (result != 0)
26 ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
27 ACE_TEXT ("ACE_Predefined_Naming_Context::connect")),
28 result);
29 else
31 // Directory
32 ACE_TString name = name_options->namespace_dir ();
33 // Separator
34 name += ACE_Registry::STRING_SEPARATOR;
35 // Filename
36 name += name_options->database ();
38 // Create new context or bind to existing one
39 result = predefined.bind_context (name,
40 this->context_);
41 if (result != 0)
42 ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Registry::Naming_Context::bind_context")), result);
44 return 0;
48 int
49 ACE_Registry_Name_Space::bind (const ACE_NS_WString &name,
50 const ACE_NS_WString &value,
51 const char *type)
53 ACE_UNUSED_ARG(type);
55 // Pointer to data
56 const ACE_WSTRING_TYPE *data = value.fast_rep ();
58 // Size
59 size_t size = value.length () * sizeof (ACE_WSTRING_TYPE);
61 // Represent value as an ACE_Registry::Object
62 ACE_Registry::Object object ((void *) data,
63 static_cast<u_long> (size),
64 REG_SZ);
65 // Add new <key>/<value> pair
66 #if defined ACE_USES_WCHAR
67 return this->context_.bind (name.fast_rep(),
68 object);
69 #else
70 return this->context_.bind (name.char_rep(),
71 object);
72 #endif /* ACE_HAS_WCHAR */
76 int
77 ACE_Registry_Name_Space::rebind (const ACE_NS_WString &name,
78 const ACE_NS_WString &value,
79 const char *type)
81 ACE_UNUSED_ARG(type);
83 // Pointer to data
84 const ACE_WSTRING_TYPE *data = value.fast_rep ();
86 // Size
87 size_t size = value.length () * sizeof (ACE_WSTRING_TYPE);
89 // Represent value as an ACE_Registry::Object
90 ACE_Registry::Object object ((void *) data,
91 static_cast<u_long> (size),
92 REG_SZ);
93 // Add new <key>/<value> pair
94 #if defined (ACE_USES_WCHAR)
95 return this->context_.rebind (name.fast_rep (),
96 object);
97 #else
98 return this->context_.rebind (name.char_rep (),
99 object);
100 #endif /* ACE_USES_WCHAR */
105 ACE_Registry_Name_Space::unbind (const ACE_NS_WString &name)
107 #if defined (ACE_USES_WCHAR)
108 return this->context_.unbind (name.fast_rep ());
109 #else
110 return this->context_.unbind (name.char_rep ());
111 #endif /* ACE_USES_WCHAR */
116 ACE_Registry_Name_Space::resolve (const ACE_NS_WString &name,
117 ACE_NS_WString &value,
118 char *&type)
120 ACE_UNUSED_ARG(type);
122 // This object will be used to query the size of the data.
123 // Note: The query_object.data will be null for this invocation.
124 ACE_Registry::Object query_object;
125 int result =
126 #if defined (ACE_USES_WCHAR)
127 this->context_.resolve (name.fast_rep (), query_object);
128 #else
129 this->context_.resolve (name.char_rep (), query_object);
130 #endif /* ACE_USES_WCHAR */
131 if (result != 0)
132 return result;
134 // Resize the value passed by the user
135 // Note: -1 is used because the size includes the null terminator
136 value.resize ((query_object.size () - 1) / sizeof (ACE_WSTRING_TYPE));
138 // Represent new space as an ACE_Registry::Object
139 ACE_Registry::Object object ((void *) value.fast_rep (),
140 query_object.size (),
141 REG_SZ);
143 #if defined (ACE_USES_WCHAR)
144 result = this->context_.resolve (name.fast_rep (), object);
145 #else
146 result = this->context_.resolve (name.char_rep (), object);
147 #endif /* ACE_USES_WCHAR */
148 if (object.size () != query_object.size ())
149 return -1;
150 if (result != 0)
151 return result;
153 return 0;
158 ACE_Registry_Name_Space:: list_names (ACE_WSTRING_SET &set,
159 const ACE_NS_WString &pattern)
161 ACE_BINDING_SET binding_set;
162 int result = this->list_name_entries (binding_set,
163 pattern);
164 if (result != 0)
165 return result;
167 ACE_BINDING_ITERATOR iterator (binding_set);
169 for (ACE_Name_Binding *entry = 0;
170 iterator.next (entry) !=0;
171 iterator.advance())
173 set.insert (entry->name_);
175 return 0;
180 ACE_Registry_Name_Space::list_values (ACE_WSTRING_SET &set,
181 const ACE_NS_WString &pattern)
183 ACE_BINDING_SET binding_set;
184 int result = this->list_name_entries (binding_set,
185 pattern);
186 if (result != 0)
187 return result;
189 ACE_BINDING_ITERATOR iterator (binding_set);
191 for (ACE_Name_Binding *entry = 0;
192 iterator.next (entry) !=0;
193 iterator.advance())
195 set.insert (entry->value_);
197 return 0;
202 ACE_Registry_Name_Space::list_types (ACE_WSTRING_SET &set,
203 const ACE_NS_WString &pattern)
205 ACE_UNUSED_ARG(set);
206 ACE_UNUSED_ARG(pattern);
208 return 0;
213 ACE_Registry_Name_Space::list_name_entries (ACE_BINDING_SET &set,
214 const ACE_NS_WString &pattern)
216 ACE_UNUSED_ARG(pattern);
218 ACE_Registry::Binding_List list;
219 int result = this->context_.list (list);
220 if (result != 0)
221 return result;
223 // Iterator through all entries
224 for (ACE_Registry::Binding_List::iterator i = list.begin ();
225 i != list.end ();
226 i++)
228 // Yeeesss! STL rules!
229 ACE_Registry::Binding &binding = *i;
231 if (binding.type () == ACE_Registry::OBJECT)
233 // Key
234 ACE_TString string = binding.name ();
235 ACE_NS_WString key (string.c_str ());
237 // Value
238 ACE_NS_WString value;
239 char *type = 0;
240 result = this->resolve (key,
241 value,
242 type);
243 if (result != 0)
244 ACELIB_ERROR_RETURN ((LM_ERROR,
245 ACE_TEXT ("%p\n"),
246 ACE_TEXT ("ACE_Registry::Naming_Context::resolve")),
247 result);
249 // Complete binding
250 ACE_Name_Binding binding (key, value, type);
251 set.insert (binding);
254 return 0;
259 ACE_Registry_Name_Space::list_value_entries (ACE_BINDING_SET &set,
260 const ACE_NS_WString &pattern)
262 return this->list_name_entries (set, pattern);
267 ACE_Registry_Name_Space::list_type_entries (ACE_BINDING_SET &set,
268 const ACE_NS_WString &pattern)
270 return this->list_name_entries (set, pattern);
274 void
275 ACE_Registry_Name_Space::dump () const
277 #if defined (ACE_HAS_DUMP)
278 #endif /* ACE_HAS_DUMP */
281 ACE_END_VERSIONED_NAMESPACE_DECL
283 #endif /* ACE_WIN32 && ACE_USES_WCHAR */