#include <Configuration.h>
Inheritance diagram for ACE_Configuration_Win32Registry:


Public Member Functions | |
| ACE_Configuration_Win32Registry (HKEY hKey) | |
| virtual | ~ACE_Configuration_Win32Registry (void) |
| Destructor. | |
| virtual int | open_section (const ACE_Configuration_Section_Key &base, const ACE_TCHAR *sub_section, int create, ACE_Configuration_Section_Key &result) |
| virtual int | remove_section (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *sub_section, int recursive) |
| Removes a named section. | |
| virtual int | enumerate_values (const ACE_Configuration_Section_Key &key, int index, ACE_TString &name, VALUETYPE &type) |
| virtual int | enumerate_sections (const ACE_Configuration_Section_Key &key, int index, ACE_TString &name) |
| virtual int | set_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, const ACE_TString &value) |
| Sets a string-typed value. | |
| virtual int | set_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int value) |
| Sets a integer-typed value. | |
| virtual int | set_binary_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, const void *data, size_t length) |
| Sets a binary-typed value. | |
| virtual int | get_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, ACE_TString &value) |
| Gets a string-typed value. | |
| virtual int | get_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int &value) |
| Gets an integer-typed value. | |
| virtual int | get_binary_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, void *&data, size_t &length) |
| Gets a binary-typed value. | |
| virtual int | find_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, VALUETYPE &type) |
| virtual int | remove_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name) |
| Removes the the value name from key. returns non zero on error. | |
| virtual bool | operator== (const ACE_Configuration_Win32Registry &rhs) const |
| virtual bool | operator!= (const ACE_Configuration_Win32Registry &rhs) const |
Static Public Member Functions | |
| HKEY | resolve_key (HKEY hKey, const ACE_TCHAR *path, int create=1) |
Protected Member Functions | |
| int | load_key (const ACE_Configuration_Section_Key &key, HKEY &hKey) |
| Gets the HKEY for a configuration section. | |
| ACE_Configuration_Win32Registry (void) | |
| ACE_Configuration_Win32Registry (const ACE_Configuration_Win32Registry &rhs) | |
| ACE_Configuration_Win32Registry & | operator= (const ACE_Configuration_Win32Registry &rhs) |
The win32 implementation basically makes calls through to the registry functions. The API is very similar so very little work must be done
Definition at line 467 of file Configuration.h.
|
|
Constructor for registry configuration database. hKey is the base registry key to attach to. This class takes ownership of hKey, it will invoke on it upon destruction. Definition at line 468 of file Configuration.cpp. References ACE_NEW.
00469 {
00470 ACE_Section_Key_Win32 *temp;
00471
00472 ACE_NEW (temp, ACE_Section_Key_Win32 (hKey));
00473
00474 root_ = ACE_Configuration_Section_Key (temp);
00475 }
|
|
|
Destructor.
Definition at line 478 of file Configuration.cpp.
00479 {
00480 }
|
|
|
|
|
|
|
|
||||||||||||||||
|
Enumerates through the subsections in a section.
Implements ACE_Configuration. Definition at line 640 of file Configuration.cpp. References ACE_DEFAULT_BUFSIZE, ACE_TCHAR, ACE_TEXT_RegEnumKeyEx, ACE_TString, and load_key().
00643 {
00644 HKEY base_key;
00645 if (load_key (key, base_key))
00646 return -1;
00647
00648 ACE_TCHAR name_buffer[ACE_DEFAULT_BUFSIZE];
00649 DWORD buffer_size = ACE_DEFAULT_BUFSIZE;
00650 int rc = ACE_TEXT_RegEnumKeyEx (base_key,
00651 index,
00652 name_buffer,
00653 &buffer_size,
00654 0,
00655 0,
00656 0,
00657 0);
00658 if (rc == ERROR_NO_MORE_ITEMS)
00659 return 1;
00660 else if (rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS)
00661 {
00662 errno = rc;
00663 return -1;
00664 }
00665
00666 name = name_buffer;
00667
00668 return 0;
00669 }
|
|
||||||||||||||||||||
|
Enumerates through the values in a section.
Implements ACE_Configuration. Definition at line 590 of file Configuration.cpp. References ACE_DEFAULT_BUFSIZE, ACE_TCHAR, ACE_TEXT_RegEnumValue, ACE_TString, and load_key().
00594 {
00595 HKEY base_key;
00596 if (load_key (key, base_key))
00597 return -1;
00598
00599 ACE_TCHAR name_buffer[ACE_DEFAULT_BUFSIZE];
00600 DWORD buffer_size = ACE_DEFAULT_BUFSIZE;
00601 DWORD value_type;
00602
00603 int rc = ACE_TEXT_RegEnumValue (base_key,
00604 index,
00605 name_buffer,
00606 &buffer_size,
00607 0,
00608 &value_type,
00609 0,
00610 0);
00611 if (rc == ERROR_NO_MORE_ITEMS)
00612 return 1;
00613 else if (rc != ERROR_SUCCESS)
00614 {
00615 errno = rc;
00616 return -1;
00617 }
00618
00619 name = name_buffer;
00620
00621 switch (value_type)
00622 {
00623 case REG_BINARY:
00624 type = BINARY;
00625 break;
00626 case REG_SZ:
00627 type = STRING;
00628 break;
00629 case REG_DWORD:
00630 type = INTEGER;
00631 break;
00632 default:
00633 type = INVALID;
00634 }
00635
00636 return 0;
00637 }
|
|
||||||||||||||||
|
Retrieves the type of a named configuration value.
Implements ACE_Configuration. Definition at line 912 of file Configuration.cpp. References ACE_TCHAR, ACE_TEXT_RegQueryValueEx, load_key(), temp_name(), and ACE_Configuration::validate_value_name().
00915 {
00916 const ACE_TCHAR *t_name = temp_name (name);
00917 if (validate_value_name (t_name))
00918 return -1;
00919
00920 HKEY base_key;
00921 if (load_key (key, base_key))
00922 return -1;
00923
00924 DWORD buffer_length=0;
00925 DWORD type;
00926 int result=ACE_TEXT_RegQueryValueEx (base_key,
00927 t_name,
00928 0,
00929 &type,
00930 0,
00931 &buffer_length);
00932 if (result != ERROR_SUCCESS)
00933 {
00934 errno = result;
00935 return -1;
00936 }
00937
00938 switch (type)
00939 {
00940 case REG_SZ:
00941 type_out = STRING;
00942 break;
00943 case REG_DWORD:
00944 type_out = INTEGER;
00945 break;
00946 case REG_BINARY:
00947 type_out = BINARY;
00948 break;
00949 default:
00950 return -1; // unknown type
00951 }
00952
00953 return 0;
00954 }
|
|
||||||||||||||||||||
|
Gets a binary-typed value.
Implements ACE_Configuration. Definition at line 853 of file Configuration.cpp. References ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT_RegQueryValueEx, load_key(), ACE_Auto_Basic_Array_Ptr< X >::release(), temp_name(), and ACE_Configuration::validate_value_name().
00858 {
00859 const ACE_TCHAR *t_name = temp_name (name);
00860 if (validate_value_name (t_name))
00861 return -1;
00862
00863 HKEY base_key;
00864 if (load_key (key, base_key))
00865 return -1;
00866
00867 // Get the size of the binary data from windows
00868 int errnum;
00869 DWORD buffer_length = 0;
00870 DWORD type;
00871 if ((errnum = ACE_TEXT_RegQueryValueEx (base_key,
00872 t_name,
00873 0,
00874 &type,
00875 (BYTE *) 0,
00876 &buffer_length)) != ERROR_SUCCESS)
00877 {
00878 errno = errnum;
00879 return -1;
00880 }
00881
00882 if (type != REG_BINARY)
00883 {
00884 errno = ERROR_INVALID_DATATYPE;
00885 return -1;
00886 }
00887
00888 length = buffer_length;
00889
00890 BYTE * the_data = 0;
00891 ACE_NEW_RETURN (the_data, BYTE[length], -1);
00892 ACE_Auto_Basic_Array_Ptr<BYTE> safe_data (the_data);
00893
00894 if ((errnum = ACE_TEXT_RegQueryValueEx (base_key,
00895 t_name,
00896 0,
00897 &type,
00898 the_data,
00899 &buffer_length)) != ERROR_SUCCESS)
00900 {
00901 data = 0;
00902 errno = errnum;
00903 return -1;
00904 }
00905
00906 data = safe_data.release ();
00907
00908 return 0;
00909 }
|
|
||||||||||||||||
|
Gets an integer-typed value.
Implements ACE_Configuration. Definition at line 817 of file Configuration.cpp. References ACE_TCHAR, ACE_TEXT_RegQueryValueEx, load_key(), temp_name(), and ACE_Configuration::validate_value_name().
00820 {
00821 const ACE_TCHAR *t_name = temp_name (name);
00822 if (validate_value_name (t_name))
00823 return -1;
00824
00825 HKEY base_key;
00826 if (load_key (key, base_key))
00827 return -1;
00828
00829 int errnum;
00830 DWORD length = sizeof (value);
00831 DWORD type;
00832 if ((errnum = ACE_TEXT_RegQueryValueEx (base_key,
00833 t_name,
00834 0,
00835 &type,
00836 (BYTE *) &value,
00837 &length)) != ERROR_SUCCESS)
00838 {
00839 errno = errnum;
00840 return -1;
00841 }
00842
00843 if (type != REG_DWORD)
00844 {
00845 errno = ERROR_INVALID_DATATYPE;
00846 return -1;
00847 }
00848
00849 return 0;
00850 }
|
|
||||||||||||||||
|
Gets a string-typed value.
Implements ACE_Configuration. Definition at line 761 of file Configuration.cpp. References ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT_RegQueryValueEx, ACE_TString, ACE_Auto_Basic_Array_Ptr< X >::get(), load_key(), temp_name(), and ACE_Configuration::validate_value_name().
00764 {
00765 const ACE_TCHAR *t_name = temp_name (name);
00766 if (validate_value_name (t_name))
00767 return -1;
00768
00769 HKEY base_key;
00770 if (load_key (key, base_key))
00771 return -1;
00772
00773 // Get the size of the binary data from windows
00774 int errnum;
00775 DWORD buffer_length = 0;
00776 DWORD type;
00777 if ((errnum = ACE_TEXT_RegQueryValueEx (base_key,
00778 t_name,
00779 0,
00780 &type,
00781 (BYTE *) 0,
00782 &buffer_length)) != ERROR_SUCCESS)
00783 {
00784 errno = errnum;
00785 return -1;
00786 }
00787
00788 if (type != REG_SZ)
00789 {
00790 errno = ERROR_INVALID_DATATYPE;
00791 return -1;
00792 }
00793
00794 ACE_TCHAR *temp = 0;
00795 ACE_NEW_RETURN (temp,
00796 ACE_TCHAR[buffer_length],
00797 -1);
00798
00799 ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> buffer (temp);
00800
00801 if ((errnum = ACE_TEXT_RegQueryValueEx (base_key,
00802 t_name,
00803 0,
00804 &type,
00805 (BYTE *) buffer.get (),
00806 &buffer_length)) != ERROR_SUCCESS)
00807 {
00808 errno = errnum;
00809 return -1;
00810 }
00811
00812 value = buffer.get ();
00813 return 0;
00814 }
|
|
||||||||||||
|
Gets the HKEY for a configuration section.
Definition at line 980 of file Configuration.cpp. References ACE_Configuration::get_internal_key(), and ACE_Section_Key_Win32::hKey_. Referenced by enumerate_sections(), enumerate_values(), find_value(), get_binary_value(), get_integer_value(), get_string_value(), open_section(), remove_section(), remove_value(), set_binary_value(), set_integer_value(), and set_string_value().
00982 {
00983 ACE_Section_Key_Win32* pKey = dynamic_cast<ACE_Section_Key_Win32*> (get_internal_key (key));
00984 if (!pKey)
00985 return -1;
00986
00987 hKey = pKey->hKey_;
00988 return 0;
00989 }
|
|
||||||||||||||||||||
|
Opens a named section in an existing section.
Implements ACE_Configuration. Definition at line 483 of file Configuration.cpp. References ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT_RegCreateKeyEx, ACE_TEXT_RegOpenKeyEx, load_key(), and ACE_Configuration::validate_name(). Referenced by remove_section().
00487 {
00488 if (validate_name (sub_section, 1))
00489 return -1;
00490
00491 HKEY base_key;
00492 if (load_key (base, base_key))
00493 return -1;
00494
00495 int errnum;
00496 HKEY result_key;
00497 if ((errnum = ACE_TEXT_RegOpenKeyEx (base_key,
00498 sub_section,
00499 0,
00500 KEY_ALL_ACCESS,
00501 &result_key)) != ERROR_SUCCESS)
00502 {
00503 if (!create)
00504 {
00505 errno = errnum;
00506 return -1;
00507 }
00508
00509 if ((errnum = ACE_TEXT_RegCreateKeyEx (base_key,
00510 sub_section,
00511 0,
00512 0,
00513 REG_OPTION_NON_VOLATILE,
00514 KEY_ALL_ACCESS,
00515 0,
00516 &result_key,
00517 #if defined (__MINGW32__)
00518 (PDWORD) 0
00519 #else
00520 0
00521 #endif /* __MINGW32__ */
00522 )) != ERROR_SUCCESS)
00523 {
00524 errno = errnum;
00525 return -1;
00526 }
00527 }
00528
00529 ACE_Section_Key_Win32 *temp;
00530
00531 ACE_NEW_RETURN (temp, ACE_Section_Key_Win32 (result_key), -1);
00532 result = ACE_Configuration_Section_Key (temp);
00533 return 0;
00534 }
|
|
|
Definition at line 462 of file Configuration.cpp.
00463 {
00464 ACE_UNUSED_ARG (rhs);
00465 return true;
00466 }
|
|
|
|
|
|
Definition at line 455 of file Configuration.cpp.
00456 {
00457 ACE_UNUSED_ARG (rhs);
00458 return true;
00459 }
|
|
||||||||||||||||
|
Removes a named section.
Implements ACE_Configuration. Definition at line 537 of file Configuration.cpp. References ACE_DEFAULT_BUFSIZE, ACE_TCHAR, ACE_TEXT_RegDeleteKey, ACE_TEXT_RegEnumKeyEx, load_key(), open_section(), and ACE_Configuration::validate_name().
00540 {
00541 if (validate_name (sub_section))
00542 return -1;
00543
00544 HKEY base_key;
00545 if (load_key (key, base_key))
00546 return -1;
00547
00548 if (recursive)
00549 {
00550 ACE_Configuration_Section_Key section;
00551 if (open_section (key, sub_section, 0, section))
00552 return -1;
00553
00554 HKEY sub_key;
00555 if (load_key (section, sub_key))
00556 return -1;
00557
00558 ACE_TCHAR name_buffer[ACE_DEFAULT_BUFSIZE];
00559 DWORD buffer_size = ACE_DEFAULT_BUFSIZE;
00560 // Note we don't increment the index because the
00561 // enumeration becomes invalid if we change the
00562 // subkey, which we do when we delete it. By leaving
00563 // it 0, we always delete the top entry
00564 while (ACE_TEXT_RegEnumKeyEx (sub_key,
00565 0,
00566 name_buffer,
00567 &buffer_size,
00568 0,
00569 0,
00570 0,
00571 0) == ERROR_SUCCESS)
00572 {
00573 remove_section (section, name_buffer, 1);
00574 buffer_size = ACE_DEFAULT_BUFSIZE;
00575 }
00576 }
00577
00578 int errnum;
00579 errnum = ACE_TEXT_RegDeleteKey (base_key, sub_section);
00580 if (errnum != ERROR_SUCCESS)
00581 {
00582 errno = errnum;
00583 return -1;
00584 }
00585
00586 return 0;
00587 }
|
|
||||||||||||
|
Removes the the value name from key. returns non zero on error.
Implements ACE_Configuration. Definition at line 957 of file Configuration.cpp. References ACE_TCHAR, ACE_TEXT_RegDeleteValue, load_key(), temp_name(), and ACE_Configuration::validate_value_name().
00959 {
00960 const ACE_TCHAR *t_name = temp_name (name);
00961 if (validate_value_name (t_name))
00962 return -1;
00963
00964 HKEY base_key;
00965 if (load_key (key, base_key))
00966 return -1;
00967
00968 int errnum;
00969 if ((errnum = ACE_TEXT_RegDeleteValue (base_key, t_name)) != ERROR_SUCCESS)
00970 {
00971 errno = errnum;
00972 return -1;
00973 }
00974
00975 return 0;
00976 }
|
|
||||||||||||||||
|
This method traverses through . It is useful when you want the HKEY for a specific registry key, especially when initializing this implementation. Caller is responsible for closeing this key when it is no longer used. If create is 1 (default) the keys are create if they don't already exist. Returns 0 on error Definition at line 992 of file Configuration.cpp. References ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT_RegCreateKeyEx, ACE_TEXT_RegOpenKey, ACE_TEXT_RegOpenKeyEx, ACE_Tokenizer::delimiter_replace(), ACE_Auto_Basic_Array_Ptr< X >::get(), ACE_Tokenizer::next(), and ACE_OS::strcpy().
00995 {
00996 HKEY result = 0;
00997 // Make a copy of hKey
00998 int errnum;
00999 #if defined (ACE_HAS_WINCE)
01000 if ((errnum = RegOpenKeyEx (hKey, 0, 0, 0, &result)) != ERROR_SUCCESS)
01001 #else
01002 if ((errnum = RegOpenKey (hKey, 0, &result)) != ERROR_SUCCESS)
01003 #endif // ACE_HAS_WINCE
01004 {
01005 errno = errnum;
01006 return 0;
01007 }
01008
01009 // recurse through the path
01010 ACE_TCHAR *temp_path = 0;
01011 ACE_NEW_RETURN (temp_path,
01012 ACE_TCHAR[ACE_OS::strlen (path) + 1],
01013 0);
01014 ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> pData (temp_path);
01015 ACE_OS::strcpy (pData.get (), path);
01016 ACE_Tokenizer parser (pData.get ());
01017 parser.delimiter_replace ('\\', '\0');
01018 parser.delimiter_replace ('/', '\0');
01019
01020 for (ACE_TCHAR *temp = parser.next ();
01021 temp != 0;
01022 temp = parser.next ())
01023 {
01024 // Open the key
01025 HKEY subkey;
01026
01027 #if defined (ACE_HAS_WINCE)
01028 if ((errnum = ACE_TEXT_RegOpenKeyEx (result,
01029 temp,
01030 0,
01031 0,
01032 &subkey)) != ERROR_SUCCESS)
01033 #else
01034 if ((errnum = ACE_TEXT_RegOpenKey (result,
01035 temp,
01036 &subkey)) != ERROR_SUCCESS)
01037 #endif // ACE_HAS_WINCE
01038 {
01039 // try creating it
01040 if (!create || (errnum = ACE_TEXT_RegCreateKeyEx (result,
01041 temp,
01042 0,
01043 0,
01044 0,
01045 KEY_ALL_ACCESS,
01046 0,
01047 &subkey,
01048 #if defined (__MINGW32__)
01049 (PDWORD) 0
01050 #else
01051 0
01052 #endif /* __MINGW32__ */
01053 )) !=ERROR_SUCCESS)
01054 {
01055 errno = errnum;
01056 // error
01057 ::RegCloseKey (result);
01058 return 0;
01059 }
01060 }
01061 // release our open key handle
01062 ::RegCloseKey (result);
01063 result = subkey;
01064 }
01065
01066 return result;
01067 }
|
|
||||||||||||||||||||
|
Sets a binary-typed value.
Implements ACE_Configuration. Definition at line 731 of file Configuration.cpp. References ACE_TCHAR, ACE_TEXT_RegSetValueEx, load_key(), temp_name(), and ACE_Configuration::validate_value_name().
00735 {
00736 const ACE_TCHAR *t_name = temp_name (name);
00737 if (validate_value_name (t_name))
00738 return -1;
00739
00740 HKEY base_key;
00741 if (load_key (key, base_key))
00742 return -1;
00743
00744 int errnum;
00745 if ((errnum = ACE_TEXT_RegSetValueEx (base_key,
00746 t_name,
00747 0,
00748 REG_BINARY,
00749 (BYTE *) data,
00750 static_cast<DWORD> (length)))
00751 != ERROR_SUCCESS)
00752 {
00753 errno = errnum;
00754 return -1;
00755 }
00756
00757 return 0;
00758 }
|
|
||||||||||||||||
|
Sets a integer-typed value.
Implements ACE_Configuration. Definition at line 703 of file Configuration.cpp. References ACE_TCHAR, ACE_TEXT_RegSetValueEx, load_key(), temp_name(), and ACE_Configuration::validate_value_name().
00706 {
00707 const ACE_TCHAR *t_name = temp_name (name);
00708 if (validate_value_name (t_name))
00709 return -1;
00710
00711 HKEY base_key;
00712 if (load_key (key, base_key))
00713 return -1;
00714
00715 int errnum;
00716 if ((errnum = ACE_TEXT_RegSetValueEx (base_key,
00717 t_name,
00718 0,
00719 REG_DWORD,
00720 (BYTE *) &value,
00721 sizeof (value))) != ERROR_SUCCESS)
00722 {
00723 errno = errnum;
00724 return -1;
00725 }
00726
00727 return 0;
00728 }
|
|
||||||||||||||||
|
Sets a string-typed value.
Implements ACE_Configuration. Definition at line 672 of file Configuration.cpp. References ACE_TCHAR, ACE_TEXT_RegSetValueEx, ACE_TString, ACE_String_Base< CHAR >::fast_rep(), ACE_String_Base< CHAR >::length(), load_key(), temp_name(), and ACE_Configuration::validate_value_name().
00675 {
00676 const ACE_TCHAR *t_name = temp_name (name);
00677 if (validate_value_name (t_name))
00678 return -1;
00679
00680 HKEY base_key;
00681 if (load_key (key, base_key))
00682 return -1;
00683
00684 int errnum;
00685 DWORD len = static_cast<DWORD> (value.length () + 1);
00686 len *= sizeof (ACE_TCHAR);
00687 if ((errnum = ACE_TEXT_RegSetValueEx (base_key,
00688 t_name,
00689 0,
00690 REG_SZ,
00691 (BYTE *) value.fast_rep (),
00692 len))
00693 != ERROR_SUCCESS)
00694 {
00695 errno = errnum;
00696 return -1;
00697 }
00698
00699 return 0;
00700 }
|
1.3.6