Fawkes API
Fawkes Development Version
|
Configuration storage using SQLite. More...
#include <>>
Classes | |
class | SQLiteValueIterator |
SQLite configuration value iterator. More... | |
Public Types | |
enum | transaction_type_t { TRANSACTION_DEFERRED, TRANSACTION_IMMEDIATE, TRANSACTION_EXCLUSIVE } |
Transaction type. More... | |
Public Member Functions | |
SQLiteConfiguration () | |
Constructor. More... | |
SQLiteConfiguration (const char *sysconfdir, const char *userconfdir=NULL) | |
Constructor. More... | |
virtual | ~SQLiteConfiguration () |
Destructor. More... | |
virtual void | copy (Configuration *copyconf) |
Copy all values from the given configuration. More... | |
virtual void | load (const char *filename) |
Load configuration. More... | |
virtual bool | exists (const char *path) |
Check if a given value exists. More... | |
virtual bool | is_float (const char *path) |
Check if a value is of type float. More... | |
virtual bool | is_uint (const char *path) |
Check if a value is of type unsigned int. More... | |
virtual bool | is_int (const char *path) |
Check if a value is of type int. More... | |
virtual bool | is_bool (const char *path) |
Check if a value is of type bool. More... | |
virtual bool | is_string (const char *path) |
Check if a value is of type string. More... | |
virtual bool | is_list (const char *path) |
Check if a value is a list. More... | |
virtual bool | is_default (const char *path) |
Check if a value was read from the default config. More... | |
virtual std::string | get_type (const char *path) |
Get type of value at given path. More... | |
virtual float | get_float (const char *path) |
Get value from configuration which is of type float. More... | |
virtual unsigned int | get_uint (const char *path) |
Get value from configuration which is of type unsigned int. More... | |
virtual int | get_int (const char *path) |
Get value from configuration which is of type int. More... | |
virtual bool | get_bool (const char *path) |
Get value from configuration which is of type bool. More... | |
virtual std::string | get_string (const char *path) |
Get value from configuration which is of type string. More... | |
virtual std::vector< float > | get_floats (const char *path) |
Get list of values from configuration which is of type float. More... | |
virtual std::vector< unsigned int > | get_uints (const char *path) |
Get list of values from configuration which is of type unsigned int. More... | |
virtual std::vector< int > | get_ints (const char *path) |
Get list of values from configuration which is of type int. More... | |
virtual std::vector< bool > | get_bools (const char *path) |
Get list of values from configuration which is of type bool. More... | |
virtual std::vector< std::string > | get_strings (const char *path) |
Get list of values from configuration which is of type string. More... | |
virtual ValueIterator * | get_value (const char *path) |
Get value from configuration. More... | |
virtual std::string | get_comment (const char *path) |
Get comment of value at given path. More... | |
virtual std::string | get_default_comment (const char *path) |
Get comment of value at given path. More... | |
virtual void | set_float (const char *path, float f) |
Set new value in configuration of type float. More... | |
virtual void | set_uint (const char *path, unsigned int uint) |
Set new value in configuration of type unsigned int. More... | |
virtual void | set_int (const char *path, int i) |
Set new value in configuration of type int. More... | |
virtual void | set_bool (const char *path, bool b) |
Set new value in configuration of type bool. More... | |
virtual void | set_string (const char *path, std::string &s) |
Set new value in configuration of type string. More... | |
virtual void | set_string (const char *path, const char *s) |
Set new value in configuration of type string. More... | |
virtual void | set_floats (const char *path, std::vector< float > &f) |
Set new value in configuration of type float. More... | |
virtual void | set_uints (const char *path, std::vector< unsigned int > &uint) |
Set new value in configuration of type unsigned int. More... | |
virtual void | set_ints (const char *path, std::vector< int > &i) |
Set new value in configuration of type int. More... | |
virtual void | set_bools (const char *path, std::vector< bool > &b) |
Set new value in configuration of type bool. More... | |
virtual void | set_strings (const char *path, std::vector< std::string > &s) |
Set new value in configuration of type string. More... | |
virtual void | set_strings (const char *path, std::vector< const char *> &s) |
Set new value in configuration of type string. More... | |
virtual void | set_comment (const char *path, std::string &comment) |
Set new comment for existing value. More... | |
virtual void | set_comment (const char *path, const char *comment) |
Set new comment for existing value. More... | |
virtual void | erase (const char *path) |
Erase the given value from the configuration. More... | |
virtual void | set_default_float (const char *path, float f) |
Set new default value in configuration of type float. More... | |
virtual void | set_default_uint (const char *path, unsigned int uint) |
Set new default value in configuration of type unsigned int. More... | |
virtual void | set_default_int (const char *path, int i) |
Set new default value in configuration of type int. More... | |
virtual void | set_default_bool (const char *path, bool b) |
Set new default value in configuration of type bool. More... | |
virtual void | set_default_string (const char *path, std::string &s) |
Set new default value in configuration of type string. More... | |
virtual void | set_default_string (const char *path, const char *s) |
Set new default value in configuration of type string. More... | |
virtual void | set_default_comment (const char *path, const char *comment) |
Set new default comment for existing default configuration value. More... | |
virtual void | set_default_comment (const char *path, std::string &comment) |
Set new default comment for existing default configuration value. More... | |
virtual void | erase_default (const char *path) |
Erase the given default value from the configuration. More... | |
void | transaction_begin (transaction_type_t ttype=TRANSACTION_DEFERRED) |
Begin SQL Transaction. More... | |
void | transaction_commit () |
Commit SQL Transaction. More... | |
void | transaction_rollback () |
Rollback SQL Transaction. More... | |
ValueIterator * | iterator () |
Iterator for all values. More... | |
ValueIterator * | iterator_default () |
Iterator for all default values. More... | |
ValueIterator * | iterator_hostspecific () |
Iterator for all host-specific values. More... | |
ValueIterator * | search (const char *path) |
Iterator with search results. More... | |
void | lock () |
Lock the config. More... | |
bool | try_lock () |
Try to lock the config. More... | |
void | unlock () |
Unlock the config. More... | |
SQLiteValueIterator * | modified_iterator () |
Iterator for modified values. More... | |
void | try_dump () |
Try to dump default configuration. More... | |
![]() | |
virtual | ~Configuration () |
Virtual empty destructor. More... | |
virtual void | add_change_handler (ConfigurationChangeHandler *h) |
Add a configuration change handler. More... | |
virtual void | rem_change_handler (ConfigurationChangeHandler *h) |
Remove a configuration change handler. More... | |
Additional Inherited Members | |
![]() | |
typedef std::list< ConfigurationChangeHandler * > | ChangeHandlerList |
List that contains pointers to ConfigurationChangeHandler. More... | |
typedef std::multimap< const char *, ConfigurationChangeHandler *, StringLess > | ChangeHandlerMultimap |
Multimap string to config change handlers. More... | |
typedef std::pair< ChangeHandlerMultimap::iterator, ChangeHandlerMultimap::iterator > | ChangeHandlerMultimapRange |
Config change handler multimap range. More... | |
![]() | |
ChangeHandlerList * | find_handlers (const char *path) |
Find handlers for given path. More... | |
void | notify_handlers (const char *path, bool comment_changed=false) |
Notify handlers for given path. More... | |
![]() | |
ChangeHandlerMultimap | _change_handlers |
Registered change handlers. More... | |
ChangeHandlerMultimapRange | _ch_range |
Change handler range. More... | |
Configuration storage using SQLite.
This implementation of the Configuration interface uses SQLite to store the configuration.
The configuration uses two databases, one is used to store the host-specific configuration and the other one is used to store the default values. Only the default database is meant to reside under version control.
See init() for the structure of the databases. This class strictly serializes all accesses to the database such that only one thread at a time can modify the database.
fawkes::SQLiteConfiguration::SQLiteConfiguration | ( | ) |
Constructor.
Definition at line 205 of file sqlite.cpp.
fawkes::SQLiteConfiguration::SQLiteConfiguration | ( | const char * | sysconfdir, |
const char * | userconfdir = NULL |
||
) |
Constructor.
sysconfdir | system configuration directory, will be searched for default configuration file, and system will try to create host-specific database if writable |
userconfdir | user configuration directory, will be searched preferably for default configuration file, and will be used to create host-specific database if sysconfdir is not writable. This directory will be created if it does not exist during load(). |
Definition at line 226 of file sqlite.cpp.
|
virtual |
Destructor.
Definition at line 251 of file sqlite.cpp.
|
virtual |
Copy all values from the given configuration.
All values from the given configuration are copied. Old values are not erased so that the copied values will overwrite existing values, new values are created, but values existent in current config but not in the copie config will remain unchanged.
copyconf | configuration to copy |
Implements fawkes::Configuration.
Definition at line 718 of file sqlite.cpp.
References fawkes::Configuration::ValueIterator::get_bool(), fawkes::Configuration::ValueIterator::get_float(), fawkes::Configuration::ValueIterator::get_int(), fawkes::Configuration::ValueIterator::get_string(), fawkes::Configuration::ValueIterator::get_uint(), fawkes::Configuration::ValueIterator::is_bool(), fawkes::Configuration::ValueIterator::is_float(), fawkes::Configuration::ValueIterator::is_int(), fawkes::Configuration::ValueIterator::is_string(), fawkes::Configuration::ValueIterator::is_uint(), fawkes::Configuration::iterator(), fawkes::Configuration::lock(), fawkes::Configuration::ValueIterator::next(), fawkes::Configuration::ValueIterator::path(), set_bool(), set_float(), set_int(), set_string(), set_uint(), transaction_begin(), transaction_commit(), and fawkes::Configuration::unlock().
|
virtual |
Erase the given value from the configuration.
It is not an error if the value does not exists before deletion.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1517 of file sqlite.cpp.
References fawkes::Configuration::notify_handlers().
|
virtual |
Erase the given default value from the configuration.
It is not an error if the value does not exists before deletion.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1838 of file sqlite.cpp.
References fawkes::Configuration::notify_handlers().
|
virtual |
Check if a given value exists.
path | path to value |
Implements fawkes::Configuration.
Definition at line 744 of file sqlite.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
virtual |
Get value from configuration which is of type bool.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1038 of file sqlite.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
virtual |
Get list of values from configuration which is of type bool.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1098 of file sqlite.cpp.
|
virtual |
Get comment of value at given path.
The value at the given path must exist in the host-specific configuration.
path | path to value |
ConfigEntryNotFoundException | shall be thrown if value does not exist |
ConfigurationException | shall be thrown on any other error |
Implements fawkes::Configuration.
Definition at line 806 of file sqlite.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
virtual |
Get comment of value at given path.
The value at the given path must exist in the default configuration.
path | path to value |
ConfigEntryNotFoundException | shall be thrown if value does not exist |
ConfigurationException | shall be thrown on any other error |
Implements fawkes::Configuration.
Definition at line 836 of file sqlite.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
virtual |
Get value from configuration which is of type float.
path | path to value |
Implements fawkes::Configuration.
Definition at line 977 of file sqlite.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
virtual |
Get list of values from configuration which is of type float.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1078 of file sqlite.cpp.
|
virtual |
Get value from configuration which is of type int.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1019 of file sqlite.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
virtual |
Get list of values from configuration which is of type int.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1092 of file sqlite.cpp.
|
virtual |
Get value from configuration which is of type string.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1056 of file sqlite.cpp.
References fawkes::Exception::append(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
virtual |
Get list of values from configuration which is of type string.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1104 of file sqlite.cpp.
|
virtual |
Get type of value at given path.
path | path to value |
ConfigurationException | shall be thrown if value does not exist or on any other error. |
Implements fawkes::Configuration.
Definition at line 772 of file sqlite.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
Referenced by is_bool(), is_float(), is_int(), is_string(), and is_uint().
|
virtual |
Get value from configuration which is of type unsigned int.
path | path to value |
Implements fawkes::Configuration.
Definition at line 996 of file sqlite.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
virtual |
Get list of values from configuration which is of type unsigned int.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1085 of file sqlite.cpp.
|
virtual |
Get value from configuration.
path | path to value |
Implements fawkes::Configuration.
Definition at line 1111 of file sqlite.cpp.
|
virtual |
Check if a value is of type bool.
path | path to value |
Implements fawkes::Configuration.
Definition at line 887 of file sqlite.cpp.
References get_type().
|
virtual |
Check if a value was read from the default config.
path | path to value |
Implements fawkes::Configuration.
Definition at line 908 of file sqlite.cpp.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
|
virtual |
Check if a value is of type float.
path | path to value |
Implements fawkes::Configuration.
Definition at line 866 of file sqlite.cpp.
References get_type().
|
virtual |
Check if a value is of type int.
path | path to value |
Implements fawkes::Configuration.
Definition at line 880 of file sqlite.cpp.
References get_type().
|
virtual |
Check if a value is a list.
path | path to value |
Implements fawkes::Configuration.
Definition at line 901 of file sqlite.cpp.
|
virtual |
Check if a value is of type string.
path | path to value |
Implements fawkes::Configuration.
Definition at line 894 of file sqlite.cpp.
References get_type().
|
virtual |
Check if a value is of type unsigned int.
path | path to value |
Implements fawkes::Configuration.
Definition at line 873 of file sqlite.cpp.
References get_type().
|
virtual |
Iterator for all values.
Returns an iterator that can be used to iterate over all values in the current configuration, it will value the overlay. If a default and a host-specific value exists you will only see the host-specific value.
Implements fawkes::Configuration.
Definition at line 1896 of file sqlite.cpp.
Configuration::ValueIterator * fawkes::SQLiteConfiguration::iterator_default | ( | ) |
Iterator for all default values.
Returns an iterator that can be used to iterate over all default values in the current default configuration. Note that this might return less paths than available, because the values for which no default entry exists are not returned.
Definition at line 1917 of file sqlite.cpp.
Configuration::ValueIterator * fawkes::SQLiteConfiguration::iterator_hostspecific | ( | ) |
Iterator for all host-specific values.
Returns an iterator that can be used to iterate over all host-specific values in the current configuration. Note that this might return less paths than available, because the default values for which no host-specific entry exists are not returned.
Definition at line 1937 of file sqlite.cpp.
|
virtual |
Load configuration.
Loads configuration data, or opens a file, depending on the implementation. After this call access to all other methods shall be possible.
file_path | path of the configuration file. |
Implements fawkes::Configuration.
Definition at line 570 of file sqlite.cpp.
References fawkes::Exception::append(), fawkes::Mutex::lock(), fawkes::HostInfo::short_name(), and fawkes::Mutex::unlock().
|
virtual |
Lock the config.
No further changes or queries can be executed on the configuration and will block until the config is unlocked.
Implements fawkes::Configuration.
Definition at line 1869 of file sqlite.cpp.
References fawkes::Mutex::lock().
SQLiteConfiguration::SQLiteValueIterator * fawkes::SQLiteConfiguration::modified_iterator | ( | ) |
Iterator for modified values.
Returns an iterator that can be used to iterate over all values that have been modified in the default database in the last load (added, erased or changed).
Definition at line 1955 of file sqlite.cpp.
|
virtual |
Iterator with search results.
Returns an iterator that can be used to iterate over the search results. All values whose component and path start with the given strings are returned. A call like
is effectively the same as a call to iterator().
path | start of path |
Implements fawkes::Configuration.
Definition at line 1980 of file sqlite.cpp.
|
virtual |
Set new value in configuration of type bool.
path | path to value |
b | new bool value |
Implements fawkes::Configuration.
Definition at line 1329 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
Referenced by copy().
|
virtual |
Set new value in configuration of type bool.
path | path to value |
b | new bool values |
Implements fawkes::Configuration.
Definition at line 1455 of file sqlite.cpp.
|
virtual |
Set new comment for existing value.
path | path to value |
comment | new comment string |
Implements fawkes::Configuration.
Definition at line 1510 of file sqlite.cpp.
|
virtual |
Set new comment for existing value.
Works like the aforementioned method. Just takes an good ol' char array instead of a std::string.
path | path to value |
comment | new comment string |
Implements fawkes::Configuration.
Definition at line 1473 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
|
virtual |
Set new default value in configuration of type bool.
path | path to value |
b | new bool value |
Implements fawkes::Configuration.
Definition at line 1688 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
|
virtual |
Set new default comment for existing default configuration value.
Works like the aforementioned method. Just takes an good ol' char array instead of a std::string.
path | path to value |
comment | new comment string |
Implements fawkes::Configuration.
Definition at line 1795 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
Referenced by set_default_comment().
|
virtual |
Set new default comment for existing default configuration value.
path | path to value |
comment | new comment string |
Implements fawkes::Configuration.
Definition at line 1831 of file sqlite.cpp.
References set_default_comment().
|
virtual |
Set new default value in configuration of type float.
path | path to value |
f | new float value |
Implements fawkes::Configuration.
Definition at line 1544 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
|
virtual |
Set new default value in configuration of type int.
path | path to value |
i | new int value |
Implements fawkes::Configuration.
Definition at line 1641 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
|
virtual |
Set new default value in configuration of type string.
path | path to value |
s | new string value |
Implements fawkes::Configuration.
Definition at line 1788 of file sqlite.cpp.
|
virtual |
Set new default value in configuration of type string.
Works like the aforementioned method. Just takes an good ol' char array instead of a std::string.
path | path to value |
s | new string value |
Implements fawkes::Configuration.
Definition at line 1737 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
|
virtual |
Set new default value in configuration of type unsigned int.
path | path to value |
uint | new unsigned int value |
Implements fawkes::Configuration.
Definition at line 1593 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
|
virtual |
Set new value in configuration of type float.
path | path to value |
f | new float value |
Implements fawkes::Configuration.
Definition at line 1183 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
Referenced by copy().
|
virtual |
Set new value in configuration of type float.
path | path to value |
f | new float values |
Implements fawkes::Configuration.
Definition at line 1437 of file sqlite.cpp.
|
virtual |
Set new value in configuration of type int.
path | path to value |
i | new int value |
Implements fawkes::Configuration.
Definition at line 1280 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
Referenced by copy().
|
virtual |
Set new value in configuration of type int.
path | path to value |
i | new int values |
Implements fawkes::Configuration.
Definition at line 1449 of file sqlite.cpp.
|
virtual |
Set new value in configuration of type string.
path | path to value |
s | new string value |
Implements fawkes::Configuration.
Definition at line 1430 of file sqlite.cpp.
Referenced by copy().
|
virtual |
Set new value in configuration of type string.
Works like the aforementioned method. Just takes an good ol' char array instead of a std::string.
path | path to value |
s | new string value |
Implements fawkes::Configuration.
Definition at line 1378 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
|
virtual |
Set new value in configuration of type string.
path | path to value |
s | new string values |
Implements fawkes::Configuration.
Definition at line 1461 of file sqlite.cpp.
|
virtual |
Set new value in configuration of type string.
Works like the aforementioned method. Just takes an good ol' char array instead of a std::string.
path | path to value |
s | new string values |
Implements fawkes::Configuration.
Definition at line 1467 of file sqlite.cpp.
|
virtual |
Set new value in configuration of type unsigned int.
path | path to value |
uint | new unsigned int value |
Implements fawkes::Configuration.
Definition at line 1232 of file sqlite.cpp.
References fawkes::Mutex::lock(), fawkes::Configuration::notify_handlers(), and fawkes::Mutex::unlock().
Referenced by copy().
|
virtual |
Set new value in configuration of type unsigned int.
path | path to value |
uint | new unsigned int values |
Implements fawkes::Configuration.
Definition at line 1443 of file sqlite.cpp.
void fawkes::SQLiteConfiguration::transaction_begin | ( | transaction_type_t | ttype = TRANSACTION_DEFERRED | ) |
Begin SQL Transaction.
ttype | transaction type |
Definition at line 511 of file sqlite.cpp.
References TRANSACTION_EXCLUSIVE, and TRANSACTION_IMMEDIATE.
Referenced by copy().
void fawkes::SQLiteConfiguration::transaction_commit | ( | ) |
void fawkes::SQLiteConfiguration::transaction_rollback | ( | ) |
Rollback SQL Transaction.
Definition at line 541 of file sqlite.cpp.
References fawkes::Exception::append().
|
virtual |
Try to dump default configuration.
This method will try to open the SQL dump file for writing and dump the current content of the default database into the file.
Exception | thrown if dumping fails |
Implements fawkes::Configuration.
Definition at line 394 of file sqlite.cpp.
|
virtual |
Try to lock the config.
Implements fawkes::Configuration.
Definition at line 1880 of file sqlite.cpp.
References fawkes::Mutex::try_lock().
|
virtual |
Unlock the config.
Modifications and queries are possible again.
Implements fawkes::Configuration.
Definition at line 1889 of file sqlite.cpp.
References fawkes::Mutex::unlock().