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")));
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
,
26 ACELIB_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("%p\n"),
27 ACE_TEXT ("ACE_Predefined_Naming_Context::connect")),
32 ACE_TString name
= name_options
->namespace_dir ();
34 name
+= ACE_Registry::STRING_SEPARATOR
;
36 name
+= name_options
->database ();
38 // Create new context or bind to existing one
39 result
= predefined
.bind_context (name
,
42 ACELIB_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Registry::Naming_Context::bind_context")), result
);
49 ACE_Registry_Name_Space::bind (const ACE_NS_WString
&name
,
50 const ACE_NS_WString
&value
,
56 const ACE_WSTRING_TYPE
*data
= value
.fast_rep ();
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
),
65 // Add new <key>/<value> pair
66 #if defined ACE_USES_WCHAR
67 return this->context_
.bind (name
.fast_rep(),
70 return this->context_
.bind (name
.char_rep(),
72 #endif /* ACE_HAS_WCHAR */
77 ACE_Registry_Name_Space::rebind (const ACE_NS_WString
&name
,
78 const ACE_NS_WString
&value
,
84 const ACE_WSTRING_TYPE
*data
= value
.fast_rep ();
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
),
93 // Add new <key>/<value> pair
94 #if defined (ACE_USES_WCHAR)
95 return this->context_
.rebind (name
.fast_rep (),
98 return this->context_
.rebind (name
.char_rep (),
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 ());
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
,
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
;
126 #if defined (ACE_USES_WCHAR)
127 this->context_
.resolve (name
.fast_rep (), query_object
);
129 this->context_
.resolve (name
.char_rep (), query_object
);
130 #endif /* ACE_USES_WCHAR */
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 (),
143 #if defined (ACE_USES_WCHAR)
144 result
= this->context_
.resolve (name
.fast_rep (), object
);
146 result
= this->context_
.resolve (name
.char_rep (), object
);
147 #endif /* ACE_USES_WCHAR */
148 if (object
.size () != query_object
.size ())
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
,
167 ACE_BINDING_ITERATOR
iterator (binding_set
);
169 for (ACE_Name_Binding
*entry
= 0;
170 iterator
.next (entry
) !=0;
173 set
.insert (entry
->name_
);
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
,
189 ACE_BINDING_ITERATOR
iterator (binding_set
);
191 for (ACE_Name_Binding
*entry
= 0;
192 iterator
.next (entry
) !=0;
195 set
.insert (entry
->value_
);
202 ACE_Registry_Name_Space::list_types (ACE_WSTRING_SET
&set
,
203 const ACE_NS_WString
&pattern
)
206 ACE_UNUSED_ARG(pattern
);
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
);
223 // Iterator through all entries
224 for (ACE_Registry::Binding_List::iterator i
= list
.begin ();
228 // Yeeesss! STL rules!
229 ACE_Registry::Binding
&binding
= *i
;
231 if (binding
.type () == ACE_Registry::OBJECT
)
234 ACE_TString string
= binding
.name ();
235 ACE_NS_WString
key (string
.c_str ());
238 ACE_NS_WString value
;
240 result
= this->resolve (key
,
244 ACELIB_ERROR_RETURN ((LM_ERROR
,
246 ACE_TEXT ("ACE_Registry::Naming_Context::resolve")),
250 ACE_Name_Binding
binding (key
, value
, type
);
251 set
.insert (binding
);
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
);
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 */