diff options
author | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
---|---|---|
committer | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
commit | e585187b248f48b3c6e9247b49fa07c6565d65e5 (patch) | |
tree | 637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /dep/ACE_wrappers/ace/Registry.cpp | |
parent | 26b5e033ffde3d161382fc9addbfa99738379641 (diff) |
*Backed out changeset 3be01fb200a5
--HG--
branch : trunk
Diffstat (limited to 'dep/ACE_wrappers/ace/Registry.cpp')
-rw-r--r-- | dep/ACE_wrappers/ace/Registry.cpp | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/dep/ACE_wrappers/ace/Registry.cpp b/dep/ACE_wrappers/ace/Registry.cpp index ff41103b724..897df00a9af 100644 --- a/dep/ACE_wrappers/ace/Registry.cpp +++ b/dep/ACE_wrappers/ace/Registry.cpp @@ -1,11 +1,16 @@ // $Id: Registry.cpp 82435 2008-07-28 11:53:42Z johnnyw $ + #include "ace/Registry.h" + ACE_RCSID (ace, Registry, "$Id: Registry.cpp 82435 2008-07-28 11:53:42Z johnnyw $") + #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY) + # include "ace/os_include/os_netdb.h" # include "ace/OS_NS_unistd.h" + // Funky macro to deal with strange error passing semantics // of Win32 Reg*() functions #define ACE_REGISTRY_CALL_RETURN(X) \ @@ -19,8 +24,11 @@ ACE_RCSID (ace, return 0; \ } while (0) + ACE_BEGIN_VERSIONED_NAMESPACE_DECL + ACE_TCHAR const ACE_Registry::STRING_SEPARATOR[] = ACE_TEXT ("\\"); + bool ACE_Registry::Name_Component::operator== (const Name_Component &rhs) const { @@ -28,11 +36,13 @@ ACE_Registry::Name_Component::operator== (const Name_Component &rhs) const rhs.id_ == this->id_ && rhs.kind_ == this->kind_; } + bool ACE_Registry::Name_Component::operator!= (const Name_Component &rhs) const { return !this->operator== (rhs); } + // Simple binding constructor ACE_Registry::Binding::Binding () : name_ (), @@ -40,6 +50,7 @@ ACE_Registry::Binding::Binding () { } + // Binding constructor // (Name version) ACE_Registry::Binding::Binding (const Name &name, @@ -49,6 +60,7 @@ ACE_Registry::Binding::Binding (const Name &name, { } + // Binding constructor // (String version) ACE_Registry::Binding::Binding (const ACE_TString &name, @@ -58,6 +70,7 @@ ACE_Registry::Binding::Binding (const ACE_TString &name, { } + bool ACE_Registry::Binding::operator== (const Binding &rhs) const { @@ -65,11 +78,13 @@ ACE_Registry::Binding::operator== (const Binding &rhs) const rhs.name_ == this->name_ && rhs.type_ == this->type_; } + bool ACE_Registry::Binding::operator!= (const Binding &rhs) const { return !this->operator== (rhs); } + // Name accessor // (Name version) void @@ -78,6 +93,7 @@ ACE_Registry::Binding::name (Name &name) name = ACE_Registry::make_name (this->name_); } + // Name accessors // (String version) void @@ -86,6 +102,7 @@ ACE_Registry::Binding::name (ACE_TString &name) name = this->name_; } + // Name accessors // (String version) ACE_TString @@ -94,6 +111,7 @@ ACE_Registry::Binding::name (void) return this->name_; } + // Type accessor ACE_Registry::Binding_Type ACE_Registry::Binding::type (void) @@ -101,6 +119,7 @@ ACE_Registry::Binding::type (void) return this->type_; } + // Simple object constructor ACE_Registry::Object::Object (void *data, u_long size, @@ -110,6 +129,7 @@ ACE_Registry::Object::Object (void *data, type_ (type) { } + // Object accessors and set methods void ACE_Registry::Object::data (void *data) @@ -117,36 +137,42 @@ ACE_Registry::Object::data (void *data) this->data_ = data; } + void * ACE_Registry::Object::data (void) const { return this->data_; } + void ACE_Registry::Object::size (u_long size) { this->size_ = size; } + u_long ACE_Registry::Object::size (void) const { return this->size_; } + void ACE_Registry::Object::type (u_long type) { this->type_ = type; } + u_long ACE_Registry::Object::type (void) const { return this->type_; } + // Simple context constructor ACE_Registry::Naming_Context::Naming_Context (void) : key_ ((HKEY) 0), @@ -155,6 +181,7 @@ ACE_Registry::Naming_Context::Naming_Context (void) { } + // Context constructor ACE_Registry::Naming_Context::Naming_Context (const HKEY &key) : key_ (key), @@ -163,6 +190,7 @@ ACE_Registry::Naming_Context::Naming_Context (const HKEY &key) { } + ACE_Registry::Naming_Context::Naming_Context (const Naming_Context &rhs) : key_ (rhs.key_), parent_key_ (rhs.parent_key_), @@ -173,20 +201,24 @@ ACE_Registry::Naming_Context::Naming_Context (const Naming_Context &rhs) // But since this is private (and not used), I don't care much } + const ACE_Registry::Naming_Context & ACE_Registry::Naming_Context::operator= (const Naming_Context &rhs) { ACE_UNUSED_ARG(rhs); + // Not implemented return *this; } + // Destructor ACE_Registry::Naming_Context::~Naming_Context () { this->close (); } + // Insert <object> with <name> into <this> context // (Name version) int @@ -196,6 +228,7 @@ ACE_Registry::Naming_Context::bind_new (const Name &name, return this->bind_new (ACE_Registry::make_string (name), object); } + // Insert <object> with <name> into <this> context // (String version) int @@ -214,6 +247,7 @@ ACE_Registry::Naming_Context::bind_new (const ACE_TString &name, return result; } + // Insert or update <object> with <name> into <this> context // (Name version) int @@ -223,6 +257,7 @@ ACE_Registry::Naming_Context::bind (const Name &name, return this->bind (ACE_Registry::make_string (name), object); } + // Insert or update <object> with <name> into <this> context // (String version) int @@ -238,6 +273,7 @@ ACE_Registry::Naming_Context::bind (const ACE_TString &name, ACE_REGISTRY_CALL_RETURN (result); } + // Update <object> with <name> in <this> context // (Name version) int @@ -247,6 +283,7 @@ ACE_Registry::Naming_Context::rebind (const Name &name, return this->rebind (ACE_Registry::make_string (name), new_object); } + // Update <object> with <name> in <this> context // (String version) int @@ -262,6 +299,7 @@ ACE_Registry::Naming_Context::rebind (const ACE_TString &name, return result; } + // Find <object> with <name> in <this> context // (Name version) int @@ -271,6 +309,7 @@ ACE_Registry::Naming_Context::resolve (const Name &name, return this->resolve (ACE_Registry::make_string (name), object); } + // Find <object> with <name> in <this> context // (String version) int @@ -281,6 +320,7 @@ ACE_Registry::Naming_Context::resolve (const ACE_TString &name, u_long type; void *data = object.data (); u_long size = object.size (); + long result = ACE_TEXT_RegQueryValueEx (this->key_, name.c_str (), 0, @@ -294,9 +334,11 @@ ACE_Registry::Naming_Context::resolve (const ACE_TString &name, object.type (type); object.size (size); } + ACE_REGISTRY_CALL_RETURN (result); } + // Remove object with <name> in <this> context // (Name version) int @@ -305,6 +347,7 @@ ACE_Registry::Naming_Context::unbind (const Name &name) return this->unbind (ACE_Registry::make_string (name)); } + // Remove object with <name> in <this> context // (String version) int @@ -312,9 +355,11 @@ ACE_Registry::Naming_Context::unbind (const ACE_TString &name) { long result = ACE_TEXT_RegDeleteValue (this->key_, name.c_str ()); + ACE_REGISTRY_CALL_RETURN (result); } + // Create new <naming_context> relative to <this> context // This method may not mean a lot in this implementation int @@ -324,6 +369,7 @@ ACE_Registry::Naming_Context::new_context (Naming_Context &naming_context) return naming_context.close (); } + // Insert <naming_context> with <name> relative to <this> context // (Name version) int @@ -340,6 +386,7 @@ ACE_Registry::Naming_Context::bind_new_context (const Name &name, security_attributes); } + // Insert <naming_context> with <name> relative to <this> context // (String version) int @@ -350,6 +397,7 @@ ACE_Registry::Naming_Context::bind_new_context (const ACE_TString &name, LPSECURITY_ATTRIBUTES security_attributes) { u_long reason; + long result = ACE_TEXT_RegCreateKeyEx (this->key_, name.c_str (), 0, @@ -382,9 +430,11 @@ ACE_Registry::Naming_Context::bind_new_context (const ACE_TString &name, naming_context.key_ = (HKEY) 0; } } + ACE_REGISTRY_CALL_RETURN (result); } + // Insert or update <naming_context> with <name> relative to <this> context // (Name version) int @@ -401,6 +451,7 @@ ACE_Registry::Naming_Context::bind_context (const Name &name, security_attributes); } + // Insert or update <naming_context> with <name> relative to <this> context // (String version) int @@ -411,6 +462,7 @@ ACE_Registry::Naming_Context::bind_context (const ACE_TString &name, LPSECURITY_ATTRIBUTES security_attributes) { u_long reason; + long result = ACE_TEXT_RegCreateKeyEx (this->key_, name.c_str (), 0, @@ -427,9 +479,11 @@ ACE_Registry::Naming_Context::bind_context (const ACE_TString &name, // Set the correct name naming_context.name (name); } + ACE_REGISTRY_CALL_RETURN (result); } + // Rename <naming_context> to <name> // (Name version) int @@ -440,6 +494,7 @@ ACE_Registry::Naming_Context::rebind_context (const Name &name, new_naming_context); } + // Rename <naming_context> to <name> // (String version) int @@ -465,6 +520,7 @@ ACE_Registry::Naming_Context::rebind_context (const ACE_TString &name, return result; } + // Remove naming_context with <name> from <this> context // (Name version) int @@ -473,6 +529,7 @@ ACE_Registry::Naming_Context::unbind_context (const Name &name) return this->unbind_context (ACE_Registry::make_string (name)); } + // Remove naming_context with <name> from <this> context // (String version) int @@ -480,9 +537,11 @@ ACE_Registry::Naming_Context::unbind_context (const ACE_TString &name) { long result = ACE_TEXT_RegDeleteKey (this->key_, name.c_str ()); + ACE_REGISTRY_CALL_RETURN (result); } + // Find <naming_context> with <name> in <this> context // (Name version) int @@ -495,6 +554,7 @@ ACE_Registry::Naming_Context::resolve_context (const Name &name, security_access); } + // Find <naming_context> with <name> in <this> context // (String version) int @@ -514,9 +574,11 @@ ACE_Registry::Naming_Context::resolve_context (const ACE_TString &name, // set the correct name naming_context.name (name); } + ACE_REGISTRY_CALL_RETURN (result); } + // Same as unbind_context() with <this> as naming_context int ACE_Registry::Naming_Context::destroy (void) @@ -524,9 +586,11 @@ ACE_Registry::Naming_Context::destroy (void) // hopefully the parent_key_ is still open long result = ACE_TEXT_RegDeleteKey (this->parent_key_, this->name_.c_str ()); + ACE_REGISTRY_CALL_RETURN (result); } + // Sync content of context to disk int ACE_Registry::Naming_Context::flush (void) @@ -535,6 +599,7 @@ ACE_Registry::Naming_Context::flush (void) ACE_REGISTRY_CALL_RETURN (result); } + // Close the handle of the context int ACE_Registry::Naming_Context::close (void) @@ -543,12 +608,14 @@ ACE_Registry::Naming_Context::close (void) ACE_REGISTRY_CALL_RETURN (result); } + // Convert a <name> to a <string> ACE_TString ACE_Registry::make_string (const Name &const_name) { ACE_TString string; Name &name = const_cast<Name &> (const_name); + // Iterator through the components of name for (Name::iterator iterator = name.begin (); iterator != name.end (); @@ -561,9 +628,11 @@ ACE_Registry::make_string (const Name &const_name) // Add to string string += component.id_; } + return string; } + // Convert a <string> to a <name> ACE_Registry::Name ACE_Registry::make_name (const ACE_TString &string) @@ -571,6 +640,7 @@ ACE_Registry::make_name (const ACE_TString &string) ACE_TString::size_type new_position = 0; ACE_TString::size_type last_position = 0; Name name; + // Rememeber: NPOS is -1 while (new_position != ACE_TString::npos) { @@ -597,9 +667,11 @@ ACE_Registry::make_name (const ACE_TString &string) // Insert component into name name.insert (component); } + return name; } + // Set key void ACE_Registry::Naming_Context::key (HKEY key) @@ -607,6 +679,7 @@ ACE_Registry::Naming_Context::key (HKEY key) this->key_ = key; } + // Get key HKEY ACE_Registry::Naming_Context::key (void) @@ -614,6 +687,7 @@ ACE_Registry::Naming_Context::key (void) return this->key_; } + // Set parent void ACE_Registry::Naming_Context::parent (HKEY parent) @@ -621,6 +695,7 @@ ACE_Registry::Naming_Context::parent (HKEY parent) this->parent_key_ = parent; } + // Get parent HKEY ACE_Registry::Naming_Context::parent (void) @@ -628,6 +703,7 @@ ACE_Registry::Naming_Context::parent (void) return this->parent_key_; } + // Set name // (Name version) void @@ -636,6 +712,7 @@ ACE_Registry::Naming_Context::name (const Name &name) this->name_ = ACE_Registry::make_string (name); } + // Get name // (Name version) void @@ -644,6 +721,7 @@ ACE_Registry::Naming_Context::name (Name &name) name = ACE_Registry::make_name (this->name_); } + // Set name // (String version) void @@ -652,6 +730,7 @@ ACE_Registry::Naming_Context::name (const ACE_TString &name) this->name_ = name; } + // Get name // (String version) ACE_TString @@ -660,6 +739,7 @@ ACE_Registry::Naming_Context::name (void) return this->name_; } + // Get name // (String version) void @@ -667,8 +747,10 @@ ACE_Registry::Naming_Context::name (ACE_TString &name) { name = this->name_; } + // Empty list static const ACE_Registry::Binding_List ace_binding_empty_list; + // listing function: iterator creator // This is useful when there are many objects and contexts // in <this> context and you only want to look at a few entries @@ -680,16 +762,21 @@ ACE_Registry::Naming_Context::list (u_long how_many, { // Make sure that the list is empty list = ace_binding_empty_list; + // Correctly initalize the iterator iter.reset (); + // Make sure that the iterator uses <this> naming context iter.naming_context (*this); + // Start iterations from the objects iter.current_enumeration (iter.object_iteration_); + // Get the next <how_many> values return iter.next_n (how_many, list); } + // listing function: iterator creator // This gives back a listing of all entries in <this> context. int @@ -697,12 +784,16 @@ ACE_Registry::Naming_Context::list (Binding_List &list) { // Make sure that the list is empty list = ace_binding_empty_list; + // Create an iterator ACE_Registry::Binding_Iterator iterator; + // Make sure that the iterator uses <this> naming context iterator.naming_context (*this); + // Start iterations from the objects iterator.current_enumeration (iterator.object_iteration_); + long result = 0; while (1) { @@ -716,6 +807,7 @@ ACE_Registry::Naming_Context::list (Binding_List &list) return 0; } + // Default constructor ACE_Registry::Binding_Iterator::Binding_Iterator () { @@ -725,6 +817,7 @@ ACE_Registry::Binding_Iterator::Binding_Iterator () this->reset (); } + void ACE_Registry::Binding_Iterator::reset () { @@ -734,37 +827,45 @@ ACE_Registry::Binding_Iterator::reset () this->context_iteration_.reset (); } + void ACE_Registry::Binding_Iterator::Iteration_State::reset () { this->index_ = 0; } + void ACE_Registry::Binding_Iterator::Iteration_State::iterator (Binding_Iterator *iter) { this->parent_ = iter; } + ACE_Registry::Binding_Iterator::Iteration_State::Iteration_State () : index_ (0) { } + // Next entry int ACE_Registry::Binding_Iterator::next_one (Binding &binding) { u_long how_many = 1; Binding_List list; + // Get next n (where n is one) long result = this->next_n (how_many, list); + if (result == 0) // Success binding = (*list.begin ()); + return result; } + // Next <how_many> entries int ACE_Registry::Binding_Iterator::next_n (u_long how_many, @@ -772,9 +873,11 @@ ACE_Registry::Binding_Iterator::next_n (u_long how_many, { // Make sure that the list is empty list = ace_binding_empty_list; + return this->current_enumeration_->next_n (how_many, list); } + // Destroy iterator int ACE_Registry::Binding_Iterator::destroy (void) @@ -783,6 +886,7 @@ ACE_Registry::Binding_Iterator::destroy (void) return 0; } + // Set/Get naming_context void ACE_Registry::Binding_Iterator::naming_context (Naming_Context &naming_context) @@ -790,12 +894,14 @@ ACE_Registry::Binding_Iterator::naming_context (Naming_Context &naming_context) this->naming_context_ = &naming_context; } + ACE_Registry::Naming_Context & ACE_Registry::Binding_Iterator::naming_context (void) { return *this->naming_context_; } + // Set/Get current enumeration void ACE_Registry::Binding_Iterator::current_enumeration (Iteration_State ¤t_enumeration) @@ -803,18 +909,21 @@ ACE_Registry::Binding_Iterator::current_enumeration (Iteration_State ¤t_en this->current_enumeration_ = ¤t_enumeration; } + ACE_Registry::Binding_Iterator::Iteration_State & ACE_Registry::Binding_Iterator::current_enumeration (void) { return *this->current_enumeration_; } + int ACE_Registry::Binding_Iterator::Object_Iteration::next_n (u_long how_many, Binding_List &list) { // Make a copy u_long requested = how_many; + // While there are more entries to be added to the list while (how_many > 0) { @@ -836,6 +945,7 @@ ACE_Registry::Binding_Iterator::Object_Iteration::next_n (u_long how_many, // Readjust counters this->index_++; how_many--; + // Add to list // Create binding Binding binding (string, OBJECT); @@ -844,10 +954,12 @@ ACE_Registry::Binding_Iterator::Object_Iteration::next_n (u_long how_many, } // Continue to add to list break; + case ERROR_NO_MORE_ITEMS: // Enumeration of objects complete // Reset index this->index_ = 0; + // Current enumeration will become CONTEXTS this->parent_->current_enumeration (this->parent_->context_iteration_); result = this->parent_->current_enumeration ().next_n (how_many, @@ -857,6 +969,7 @@ ACE_Registry::Binding_Iterator::Object_Iteration::next_n (u_long how_many, return 0; else return result; + default: // Strange error // Reset index @@ -873,12 +986,14 @@ ACE_Registry::Binding_Iterator::Object_Iteration::next_n (u_long how_many, return 0; } + int ACE_Registry::Binding_Iterator::Context_Iteration::next_n (u_long how_many, Binding_List &list) { // Make a copy u_long requested = how_many; + // While there are more entries to be added to the list while (how_many > 0) { @@ -900,6 +1015,7 @@ ACE_Registry::Binding_Iterator::Context_Iteration::next_n (u_long how_many, // Readjust counters this->index_++; how_many--; + // Add to list // Create binding Binding binding (string, CONTEXT); @@ -908,15 +1024,20 @@ ACE_Registry::Binding_Iterator::Context_Iteration::next_n (u_long how_many, } // Continue to add to list break; + case ERROR_NO_MORE_ITEMS: // Enumeration of objects complete + /* FALL THROUGH */ + default: // Strange error + // Reset index this->index_ = 0; // Current enumeration will become CONTEXTS this->parent_->current_enumeration (this->parent_->iteration_complete_); + // If we were able to add contexts if (requested != how_many) return 0; @@ -930,16 +1051,19 @@ ACE_Registry::Binding_Iterator::Context_Iteration::next_n (u_long how_many, return 0; } + int ACE_Registry::Binding_Iterator::Iteration_Complete::next_n (u_long how_many, Binding_List &list) { ACE_UNUSED_ARG(list); ACE_UNUSED_ARG(how_many); + // No more values return -1; } + // Factory method to connect to predefined registries // This method works for both remote and local machines // However, for remote machines CLASSES_ROOT and CURRENT_USER @@ -954,8 +1078,10 @@ ACE_Predefined_Naming_Contexts::connect (ACE_Registry::Naming_Context &naming_co return -1; #else long result = -1; + if (machine_name != 0 && ACE_OS::strcmp (ACE_TEXT ("localhost"), machine_name) == 0) machine_name = 0; + if (predefined == HKEY_LOCAL_MACHINE || predefined == HKEY_USERS) result = ACE_TEXT_RegConnectRegistry (const_cast<ACE_TCHAR *> (machine_name), @@ -971,9 +1097,11 @@ ACE_Predefined_Naming_Contexts::connect (ACE_Registry::Naming_Context &naming_co } else result = -1; + ACE_REGISTRY_CALL_RETURN (result); #endif // ACE_HAS_WINCE } + // Check if <machine_name> is the local host /* static */ int @@ -987,6 +1115,8 @@ ACE_Predefined_Naming_Contexts::is_local_host (const ACE_TCHAR *machine_name) result = 0; return result; } + ACE_END_VERSIONED_NAMESPACE_DECL + #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */ |