1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
// $Id$
#include "ace/Registry_Name_Space.h"
ACE_RCSID(ace, Registry_Name_Space, "$Id$")
#if (defined (ACE_WIN32) && defined (UNICODE))
// This only works on Win32 platforms when UNICODE is turned on
ACE_Registry_Name_Space::ACE_Registry_Name_Space (void)
{
}
ACE_Registry_Name_Space::ACE_Registry_Name_Space (ACE_Name_Options *name_options)
{
if (this->open (name_options) != 0)
ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("%p\n"),
ACE_LIB_TEXT ("ACE_Registry_Name_Space::open")));
}
ACE_Registry_Name_Space::~ACE_Registry_Name_Space (void)
{
}
int
ACE_Registry_Name_Space::open (ACE_Name_Options *name_options)
{
const ACE_TCHAR *host = name_options->nameserver_host ();
ACE_Registry::Naming_Context predefined;
int result = ACE_Predefined_Naming_Contexts::connect (predefined,
HKEY_LOCAL_MACHINE,
host);
if (result != 0)
ACE_ERROR_RETURN ((LM_ERROR, ACE_LIB_TEXT ("%p\n"),
ACE_LIB_TEXT ("ACE_Predefined_Naming_Context::connect")),
result);
else
{
// Directory
ACE_TString name = name_options->namespace_dir ();
// Separator
name += ACE_Registry::STRING_SEPARATOR;
// Filename
name += name_options->database ();
// Create new context or bind to existing one
result = predefined.bind_context (name,
this->context_);
if (result != 0)
ACE_ERROR_RETURN ((LM_ERROR, ACE_LIB_TEXT ("%p\n"), ACE_LIB_TEXT ("ACE_Registry::Naming_Context::bind_context")), result);
}
return 0;
}
int
ACE_Registry_Name_Space::bind (const ACE_NS_WString &name,
const ACE_NS_WString &value,
const char *type)
{
ACE_UNUSED_ARG(type);
// Pointer to data
const ACE_WSTRING_TYPE *data = value.fast_rep ();
// Size
size_t size = value.length () * sizeof (ACE_WSTRING_TYPE);
// Represent value as an ACE_Registry::Object
ACE_Registry::Object object ((void *) data,
static_cast<u_long> (size),
REG_SZ);
// Add new <key>/<value> pair
#if defined ACE_USES_WCHAR
return this->context_.bind (name.fast_rep(),
object);
#else
return this->context_.bind (name.char_rep(),
object);
#endif /* ACE_HAS_WCHAR */
}
int
ACE_Registry_Name_Space::rebind (const ACE_NS_WString &name,
const ACE_NS_WString &value,
const char *type)
{
ACE_UNUSED_ARG(type);
// Pointer to data
const ACE_WSTRING_TYPE *data = value.fast_rep ();
// Size
size_t size = value.length () * sizeof (ACE_WSTRING_TYPE);
// Represent value as an ACE_Registry::Object
ACE_Registry::Object object ((void *) data,
static_cast<u_long> (size),
REG_SZ);
// Add new <key>/<value> pair
#if defined (ACE_USES_WCHAR)
return this->context_.rebind (name.fast_rep (),
object);
#else
return this->context_.rebind (name.char_rep (),
object);
#endif /* ACE_USES_WCHAR */
}
int
ACE_Registry_Name_Space::unbind (const ACE_NS_WString &name)
{
#if defined (ACE_USES_WCHAR)
return this->context_.unbind (name.fast_rep ());
#else
return this->context_.unbind (name.char_rep ());
#endif /* ACE_USES_WCHAR */
}
int
ACE_Registry_Name_Space::resolve (const ACE_NS_WString &name,
ACE_NS_WString &value,
char *&type)
{
ACE_UNUSED_ARG(type);
// This object will be used to query the size of the data.
// Note: The query_object.data will be null for this invocation.
ACE_Registry::Object query_object;
int result =
#if defined (ACE_USES_WCHAR)
this->context_.resolve (name.fast_rep (), query_object);
#else
this->context_.resolve (name.char_rep (), query_object);
#endif /* ACE_USES_WCHAR */
if (result != 0)
return result;
// Resize the value passed by the user
// Note: -1 is used because the size includes the null terminator
value.resize ((query_object.size () - 1) / sizeof (ACE_WSTRING_TYPE));
// Represent new space as an ACE_Registry::Object
ACE_Registry::Object object ((void *) value.fast_rep (),
query_object.size (),
REG_SZ);
#if defined (ACE_USES_WCHAR)
result = this->context_.resolve (name.fast_rep (), object);
#else
result = this->context_.resolve (name.char_rep (), object);
#endif /* ACE_USES_WCHAR */
if (object.size () != query_object.size ())
return -1;
if (result != 0)
return result;
return 0;
}
int
ACE_Registry_Name_Space:: list_names (ACE_WSTRING_SET &set,
const ACE_NS_WString &pattern)
{
ACE_BINDING_SET binding_set;
int result = this->list_name_entries (binding_set,
pattern);
if (result != 0)
return result;
ACE_BINDING_ITERATOR iterator (binding_set);
for (ACE_Name_Binding *entry = 0;
iterator.next (entry) !=0;
iterator.advance())
{
set.insert (entry->name_);
}
return 0;
}
int
ACE_Registry_Name_Space::list_values (ACE_WSTRING_SET &set,
const ACE_NS_WString &pattern)
{
ACE_BINDING_SET binding_set;
int result = this->list_name_entries (binding_set,
pattern);
if (result != 0)
return result;
ACE_BINDING_ITERATOR iterator (binding_set);
for (ACE_Name_Binding *entry = 0;
iterator.next (entry) !=0;
iterator.advance())
{
set.insert (entry->value_);
}
return 0;
}
int
ACE_Registry_Name_Space::list_types (ACE_WSTRING_SET &set,
const ACE_NS_WString &pattern)
{
ACE_UNUSED_ARG(set);
ACE_UNUSED_ARG(pattern);
return 0;
}
int
ACE_Registry_Name_Space::list_name_entries (ACE_BINDING_SET &set,
const ACE_NS_WString &pattern)
{
ACE_UNUSED_ARG(pattern);
ACE_Registry::Binding_List list;
int result = this->context_.list (list);
if (result != 0)
return result;
// Iterator through all entries
for (ACE_Registry::Binding_List::iterator i = list.begin ();
i != list.end ();
i++)
{
// Yeeesss! STL rules!
ACE_Registry::Binding &binding = *i;
if (binding.type () == ACE_Registry::OBJECT)
{
// Key
ACE_TString string = binding.name ();
ACE_NS_WString key (string.c_str ());
// Value
ACE_NS_WString value;
char *type = 0;
result = this->resolve (key,
value,
type);
if (result != 0)
ACE_ERROR_RETURN ((LM_ERROR, ACE_LIB_TEXT ("%p\n"), ACE_LIB_TEXT ("ACE_Registry::Naming_Context::resolve")), result);
// Complete binding
ACE_Name_Binding binding (key, value, type);
set.insert (binding);
}
}
return 0;
}
int
ACE_Registry_Name_Space::list_value_entries (ACE_BINDING_SET &set,
const ACE_NS_WString &pattern)
{
return this->list_name_entries (set, pattern);
}
int
ACE_Registry_Name_Space::list_type_entries (ACE_BINDING_SET &set,
const ACE_NS_WString &pattern)
{
return this->list_name_entries (set, pattern);
}
void
ACE_Registry_Name_Space::dump (void) const
{
#if defined (ACE_HAS_DUMP)
#endif /* ACE_HAS_DUMP */
}
#endif /* ACE_WIN32 && UNICODE */
|