summaryrefslogtreecommitdiff
path: root/ace/Registry_Name_Space.cpp
blob: 543ddd1a4e2251dfaf9b22f6d20afc1fd01d8c5a (plain)
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
// $Id$

#define ACE_BUILD_DLL

#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,  ASYS_TEXT ("%p\n"),  ASYS_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 char *host = name_options->nameserver_host ();
  ACE_Registry::Naming_Context predefined;
  
  int result = ACE_Predefined_Naming_Contexts::connect (predefined,
							HKEY_LOCAL_MACHINE,
							ACE_WIDE_STRING (host));
  if (result != 0)
    ACE_ERROR_RETURN ((LM_ERROR,  ASYS_TEXT ("%p\n"),  ASYS_TEXT ("ACE_Predefined_Naming_Context::connect")), result);
  else
    {
      // Directory
      ACE_Registry::Istring 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,  ASYS_TEXT ("%p\n"),  ASYS_TEXT ("ACE_Registry::Naming_Context::bind_context")), result);
    }
  return 0;
}


int 
ACE_Registry_Name_Space::bind (const ACE_WString &name, 
			       const ACE_WString &value, 
			       const char *type)
{
  // Pointer to data
  const ACE_USHORT16 *data = value.fast_rep ();
  
  // Size
  u_long size = value.length () * sizeof (ACE_USHORT16);
  
  // Represent value as an ACE_Registry::Object
  ACE_Registry::Object object ((void *) data,
			       size,
			       REG_SZ);
  // Add new <key>/<value> pair
  return this->context_.bind (name.fast_rep(), 
			      object);
}


int 
ACE_Registry_Name_Space::rebind (const ACE_WString &name, 
				 const ACE_WString &value, 
				 const char *type)
{
  // Pointer to data
  const ACE_USHORT16 *data = value.fast_rep ();
  
  // Size
  u_long size = value.length () * sizeof (ACE_USHORT16);
  
  // Represent value as an ACE_Registry::Object
  ACE_Registry::Object object ((void *) data,
			       size,
			       REG_SZ);
  // Add new <key>/<value> pair
  return this->context_.rebind (name.fast_rep (), 
				object);
}


int 
ACE_Registry_Name_Space::unbind (const ACE_WString &name)
{
  return this->context_.unbind (name.fast_rep ());
}


int 
ACE_Registry_Name_Space::resolve (const ACE_WString &name, 
				  ACE_WString &value, 
				  char *&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 = this->context_.resolve (name.fast_rep (), query_object);
  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_USHORT16));

  // Represent new space as an ACE_Registry::Object
  ACE_Registry::Object object ((void *) value.fast_rep (),
			       query_object.size (),
			       REG_SZ);

  result = this->context_.resolve (name.fast_rep (), object);
  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_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_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_WString &pattern)
{
  return 0;
}


int 
ACE_Registry_Name_Space::list_name_entries (ACE_BINDING_SET &set, 
					    const ACE_WString &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_Registry::Istring string = binding.name ();
	  ACE_WString key (string.c_str ());
	  
	  // Value
	  ACE_WString value;
	  char *type = 0;
	  result = this->resolve (key,
				  value,
				  type);	  
	  if (result != 0)
	    ACE_ERROR_RETURN ((LM_ERROR,  ASYS_TEXT ("%p\n"),  ASYS_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_WString &pattern)
{
  return this->list_name_entries (set, pattern);
}


int 
ACE_Registry_Name_Space::list_type_entries (ACE_BINDING_SET &set, 
					    const ACE_WString &pattern)
{
  return this->list_name_entries (set, pattern);
}


void 
ACE_Registry_Name_Space::dump (void) const
{
}


#endif /* ACE_WIN32 && UNICODE */