fawkes::SQLiteConfiguration Class Reference

Configuration storage using SQLite. More...

#include <config/sqlite.h>

Inheritance diagram for fawkes::SQLiteConfiguration:

List of all members.


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 (const char *conf_path=NULL)
 Constructor.
virtual ~SQLiteConfiguration ()
 Destructor.
virtual void copy (Configuration *copyconf)
 Copy all values from the given configuration.
virtual void load (const char *filename, const char *defaults_filename, const char *tag=NULL)
 Load configuration.
void load (const char *tag=NULL)
 Load config from default files.
virtual void tag (const char *tag)
 Tag this configuration version.
virtual std::list< std::string > tags ()
 List of tags.
virtual bool exists (const char *path)
 Check if a given value exists.
virtual bool is_float (const char *path)
 Check if a value is of type float.
virtual bool is_uint (const char *path)
 Check if a value is of type unsigned int.
virtual bool is_int (const char *path)
 Check if a value is of type int.
virtual bool is_bool (const char *path)
 Check if a value is of type bool.
virtual bool is_string (const char *path)
 Check if a value is of type string.
virtual bool is_default (const char *path)
 Check if a value was read from the default config.
virtual std::string get_type (const char *path)
 Get type of value at given path.
virtual float get_float (const char *path)
 Get value from configuration which is of type float.
virtual unsigned int get_uint (const char *path)
 Get value from configuration which is of type unsigned int.
virtual int get_int (const char *path)
 Get value from configuration which is of type int.
virtual bool get_bool (const char *path)
 Get value from configuration which is of type bool.
virtual std::string get_string (const char *path)
 Get value from configuration which is of type string.
virtual ValueIteratorget_value (const char *path)
 Get value from configuration.
virtual std::string get_comment (const char *path)
 Get comment of value at given path.
virtual std::string get_default_comment (const char *path)
 Get comment of value at given path.
virtual void set_float (const char *path, float f)
 Set new value in configuration of type float.
virtual void set_uint (const char *path, unsigned int uint)
 Set new value in configuration of type unsigned int.
virtual void set_int (const char *path, int i)
 Set new value in configuration of type int.
virtual void set_bool (const char *path, bool b)
 Set new value in configuration of type bool.
virtual void set_string (const char *path, std::string &s)
 Set new value in configuration of type string.
virtual void set_string (const char *path, const char *s)
 Set new value in configuration of type string.
virtual void set_comment (const char *path, std::string &comment)
 Set new comment for existing value.
virtual void set_comment (const char *path, const char *comment)
 Set new comment for existing value.
virtual void erase (const char *path)
 Erase the given value from the configuration.
virtual void set_default_float (const char *path, float f)
 Set new default value in configuration of type float.
virtual void set_default_uint (const char *path, unsigned int uint)
 Set new default value in configuration of type unsigned int.
virtual void set_default_int (const char *path, int i)
 Set new default value in configuration of type int.
virtual void set_default_bool (const char *path, bool b)
 Set new default value in configuration of type bool.
virtual void set_default_string (const char *path, std::string &s)
 Set new default value in configuration of type string.
virtual void set_default_string (const char *path, const char *s)
 Set new default value in configuration of type string.
virtual void set_default_comment (const char *path, const char *comment)
 Set new default comment for existing default configuration value.
virtual void set_default_comment (const char *path, std::string &comment)
 Set new default comment for existing default configuration value.
virtual void erase_default (const char *path)
 Erase the given default value from the configuration.
void transaction_begin (transaction_type_t ttype=TRANSACTION_DEFERRED)
 Begin SQL Transaction.
void transaction_commit ()
 Commit SQL Transaction.
void transaction_rollback ()
 Rollback SQL Transaction.
ValueIteratoriterator ()
 Iterator for all values.
ValueIteratoriterator_default ()
 Iterator for all default values.
ValueIteratoriterator_hostspecific ()
 Iterator for all host-specific values.
ValueIteratorsearch (const char *path)
 Iterator with search results.
void lock ()
 Lock the config.
bool try_lock ()
 Try to lock the config.
void unlock ()
 Unlock the config.
SQLiteValueIteratormodified_iterator ()
 Iterator for modified values.

Detailed Description

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.

Definition at line 37 of file sqlite.h.


Member Enumeration Documentation

Transaction type.

See SQLite Documentation for BEGIN TRANSACTION.

Enumerator:
TRANSACTION_DEFERRED  Deferred transaction, lock acquired late.

TRANSACTION_IMMEDIATE  Immediately acquire lock, reading remains possible.

TRANSACTION_EXCLUSIVE  Immediately acquire lock, no more reading or writing possible.

Definition at line 97 of file sqlite.h.


Constructor & Destructor Documentation

fawkes::SQLiteConfiguration::SQLiteConfiguration ( const char *  conf_path = NULL  ) 

Constructor.

Parameters:
conf_path Path where the configuration resides, maybe NULL in which case the path name for the base databsae supplied to load() must be absolute path names or relative to the execution directory of the surrounding program.

Definition at line 222 of file sqlite.cpp.

fawkes::SQLiteConfiguration::~SQLiteConfiguration (  )  [virtual]

Destructor.

Definition at line 234 of file sqlite.cpp.

References fawkes::Exception::print_trace().


Member Function Documentation

void fawkes::SQLiteConfiguration::erase ( const char *  path  )  [virtual]

Erase the given value from the configuration.

It is not an error if the value does not exists before deletion.

Parameters:
path path to value

Implements fawkes::Configuration.

Definition at line 1456 of file sqlite.cpp.

References fawkes::Configuration::find_handlers().

void fawkes::SQLiteConfiguration::erase_default ( const char *  path  )  [virtual]

Erase the given default value from the configuration.

It is not an error if the value does not exists before deletion.

Parameters:
path path to value

Implements fawkes::Configuration.

Definition at line 1805 of file sqlite.cpp.

References fawkes::Configuration::find_handlers().

bool fawkes::SQLiteConfiguration::exists ( const char *  path  )  [virtual]

Check if a given value exists.

Parameters:
path path to value
Returns:
true if the value exists, false otherwise

Implements fawkes::Configuration.

Definition at line 735 of file sqlite.cpp.

References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

bool fawkes::SQLiteConfiguration::get_bool ( const char *  path  )  [virtual]

Get value from configuration which is of type bool.

Parameters:
path path to value
Returns:
value

Implements fawkes::Configuration.

Definition at line 1023 of file sqlite.cpp.

References get_value(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by fawkes::NetworkConfiguration::get_bool().

std::string fawkes::SQLiteConfiguration::get_comment ( const char *  path  )  [virtual]

Get comment of value at given path.

The value at the given path must exist in the host-specific configuration.

Parameters:
path path to value
Returns:
comment
Exceptions:
ConfigEntryNotFoundException shall be thrown if value does not exist
ConfigurationException shall be thrown on any other error

Implements fawkes::Configuration.

Definition at line 797 of file sqlite.cpp.

References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by fawkes::NetworkConfiguration::get_comment().

std::string fawkes::SQLiteConfiguration::get_default_comment ( const char *  path  )  [virtual]

Get comment of value at given path.

The value at the given path must exist in the default configuration.

Parameters:
path path to value
Returns:
comment
Exceptions:
ConfigEntryNotFoundException shall be thrown if value does not exist
ConfigurationException shall be thrown on any other error

Implements fawkes::Configuration.

Definition at line 827 of file sqlite.cpp.

References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by fawkes::NetworkConfiguration::get_default_comment().

float fawkes::SQLiteConfiguration::get_float ( const char *  path  )  [virtual]

Get value from configuration which is of type float.

Parameters:
path path to value
Returns:
value

Implements fawkes::Configuration.

Definition at line 962 of file sqlite.cpp.

References get_value(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by fawkes::NetworkConfiguration::get_float().

int fawkes::SQLiteConfiguration::get_int ( const char *  path  )  [virtual]

Get value from configuration which is of type int.

Parameters:
path path to value
Returns:
value

Implements fawkes::Configuration.

Definition at line 1004 of file sqlite.cpp.

References get_value(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by fawkes::NetworkConfiguration::get_int().

std::string fawkes::SQLiteConfiguration::get_string ( const char *  path  )  [virtual]

Get value from configuration which is of type string.

Parameters:
path path to value

Implements fawkes::Configuration.

Definition at line 1041 of file sqlite.cpp.

References fawkes::Exception::append(), get_value(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by fawkes::NetworkConfiguration::get_string().

std::string fawkes::SQLiteConfiguration::get_type ( const char *  path  )  [virtual]

Get type of value at given path.

Parameters:
path path to value
Returns:
string representation of type, one of float, unsigned int, int, bool, or string
Exceptions:
ConfigurationException shall be thrown if value does not exist or on any other error.

Implements fawkes::Configuration.

Definition at line 763 of file sqlite.cpp.

References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by fawkes::NetworkConfiguration::get_type(), is_bool(), is_float(), is_int(), is_string(), and is_uint().

unsigned int fawkes::SQLiteConfiguration::get_uint ( const char *  path  )  [virtual]

Get value from configuration which is of type unsigned int.

Parameters:
path path to value
Returns:
value

Implements fawkes::Configuration.

Definition at line 981 of file sqlite.cpp.

References get_value(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by fawkes::NetworkConfiguration::get_uint().

Configuration::ValueIterator * fawkes::SQLiteConfiguration::get_value ( const char *  path  )  [virtual]

Get value from configuration.

Parameters:
path path to value
Returns:
value iterator for just this one value, maybe invalid if value does not exists.

Implements fawkes::Configuration.

Definition at line 1062 of file sqlite.cpp.

Referenced by get_bool(), get_float(), get_int(), get_string(), get_uint(), and fawkes::NetworkConfiguration::get_value().

bool fawkes::SQLiteConfiguration::is_bool ( const char *  path  )  [virtual]

Check if a value is of type bool.

Parameters:
path path to value
Returns:
true if the value exists and is of type bool

Implements fawkes::Configuration.

Definition at line 878 of file sqlite.cpp.

References get_type().

bool fawkes::SQLiteConfiguration::is_default ( const char *  path  )  [virtual]

Check if a value was read from the default config.

Parameters:
path path to value
Returns:
true if the value exists and is only stored in the default config

Implements fawkes::Configuration.

Definition at line 892 of file sqlite.cpp.

References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

bool fawkes::SQLiteConfiguration::is_float ( const char *  path  )  [virtual]

Check if a value is of type float.

Parameters:
path path to value
Returns:
true if the value exists and is of type float

Implements fawkes::Configuration.

Definition at line 857 of file sqlite.cpp.

References get_type().

bool fawkes::SQLiteConfiguration::is_int ( const char *  path  )  [virtual]

Check if a value is of type int.

Parameters:
path path to value
Returns:
true if the value exists and is of type int

Implements fawkes::Configuration.

Definition at line 871 of file sqlite.cpp.

References get_type().

bool fawkes::SQLiteConfiguration::is_string ( const char *  path  )  [virtual]

Check if a value is of type string.

Parameters:
path path to value
Returns:
true if the value exists and is of type string

Implements fawkes::Configuration.

Definition at line 885 of file sqlite.cpp.

References get_type().

bool fawkes::SQLiteConfiguration::is_uint ( const char *  path  )  [virtual]

Check if a value is of type unsigned int.

Parameters:
path path to value
Returns:
true if the value exists and is of type unsigned int

Implements fawkes::Configuration.

Definition at line 864 of file sqlite.cpp.

References get_type().

Configuration::ValueIterator * fawkes::SQLiteConfiguration::iterator (  )  [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.

Returns:
iterator over all values

Implements fawkes::Configuration.

Definition at line 1867 of file sqlite.cpp.

Referenced by fawkes::NetworkConfiguration::iterator().

Configuration::ValueIterator * fawkes::SQLiteConfiguration::iterator_default (  )  [virtual]

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.

Returns:
iterator over all default values

Implements fawkes::Configuration.

Definition at line 1881 of file sqlite.cpp.

Referenced by fawkes::NetworkConfiguration::iterator_default().

Configuration::ValueIterator * fawkes::SQLiteConfiguration::iterator_hostspecific (  )  [virtual]

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.

Returns:
iterator over all host-specific values

Implements fawkes::Configuration.

Definition at line 1894 of file sqlite.cpp.

Referenced by fawkes::NetworkConfiguration::iterator_hostspecific().

void fawkes::SQLiteConfiguration::load ( const char *  tag = NULL  ) 

Load config from default files.

Default file is "shorthostname.db" (shorthostname replaced by the short host name returned by uname) and default.db).

Parameters:
tag optional tag to restore

Definition at line 652 of file sqlite.cpp.

References load().

void fawkes::SQLiteConfiguration::load ( const char *  name,
const char *  defaults_name,
const char *  tag = NULL 
) [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.

Parameters:
name name of the host-based configuration. If this does not exist it shall be created from the default configuration. The name depends on the implementation and could be a filename.
defaults_name name of the default database. As for the name this depends on the actual implementation.
tag this optional parameter can denote a specific config version to load. This will cause the host-specific database to be flushed and filled with the values for the given tag. All values that did not exist for the tag are copied over from the default database.

Implements fawkes::Configuration.

Definition at line 543 of file sqlite.cpp.

References fawkes::Exception::append(), fawkes::Mutex::lock(), fawkes::HostInfo::short_name(), and fawkes::Mutex::unlock().

Referenced by load(), and fawkes::NetworkConfiguration::set_mirror_mode().

void fawkes::SQLiteConfiguration::lock (  )  [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 1840 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).

Returns:
iterator over all values

Definition at line 1912 of file sqlite.cpp.

Referenced by FawkesMainThread::FawkesMainThread().

Configuration::ValueIterator * fawkes::SQLiteConfiguration::search ( const char *  path  )  [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

   config->search("");
is effectively the same as a call to iterator().
Parameters:
path start of path
Returns:
iterator to search results

Implements fawkes::Configuration.

Definition at line 1937 of file sqlite.cpp.

Referenced by fawkes::NetworkConfiguration::search().

void fawkes::SQLiteConfiguration::set_bool ( const char *  path,
bool  b 
) [virtual]

Set new value in configuration of type bool.

Parameters:
path path to value
b new bool value

Implements fawkes::Configuration.

Definition at line 1292 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by copy().

void fawkes::SQLiteConfiguration::set_comment ( const char *  path,
const char *  comment 
) [virtual]

Set new comment for existing value.

Works like the aforementioned method. Just takes an good ol' char array instead of a std::string.

Parameters:
path path to value
comment new comment string

Implements fawkes::Configuration.

Definition at line 1408 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

void fawkes::SQLiteConfiguration::set_comment ( const char *  path,
std::string &  comment 
) [virtual]

Set new comment for existing value.

Parameters:
path path to value
comment new comment string

Implements fawkes::Configuration.

Definition at line 1449 of file sqlite.cpp.

void fawkes::SQLiteConfiguration::set_default_bool ( const char *  path,
bool  b 
) [virtual]

Set new default value in configuration of type bool.

Parameters:
path path to value
b new bool value

Implements fawkes::Configuration.

Definition at line 1643 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

void fawkes::SQLiteConfiguration::set_default_comment ( const char *  path,
std::string &  comment 
) [virtual]

Set new default comment for existing default configuration value.

Parameters:
path path to value
comment new comment string

Implements fawkes::Configuration.

Definition at line 1798 of file sqlite.cpp.

References set_default_comment().

void fawkes::SQLiteConfiguration::set_default_comment ( const char *  path,
const char *  comment 
) [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.

Parameters:
path path to value
comment new comment string

Implements fawkes::Configuration.

Definition at line 1758 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by set_default_comment().

void fawkes::SQLiteConfiguration::set_default_float ( const char *  path,
float  f 
) [virtual]

Set new default value in configuration of type float.

Parameters:
path path to value
f new float value

Implements fawkes::Configuration.

Definition at line 1487 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

void fawkes::SQLiteConfiguration::set_default_int ( const char *  path,
int  i 
) [virtual]

Set new default value in configuration of type int.

Parameters:
path path to value
i new int value

Implements fawkes::Configuration.

Definition at line 1592 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

void fawkes::SQLiteConfiguration::set_default_string ( const char *  path,
const char *  s 
) [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.

Parameters:
path path to value
s new string value

Implements fawkes::Configuration.

Definition at line 1696 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

void fawkes::SQLiteConfiguration::set_default_string ( const char *  path,
std::string &  s 
) [virtual]

Set new default value in configuration of type string.

Parameters:
path path to value
s new string value

Implements fawkes::Configuration.

Definition at line 1751 of file sqlite.cpp.

void fawkes::SQLiteConfiguration::set_default_uint ( const char *  path,
unsigned int  uint 
) [virtual]

Set new default value in configuration of type unsigned int.

Parameters:
path path to value
uint new unsigned int value

Implements fawkes::Configuration.

Definition at line 1540 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

void fawkes::SQLiteConfiguration::set_float ( const char *  path,
float  f 
) [virtual]

Set new value in configuration of type float.

Parameters:
path path to value
f new float value

Implements fawkes::Configuration.

Definition at line 1134 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by copy().

void fawkes::SQLiteConfiguration::set_int ( const char *  path,
int  i 
) [virtual]

Set new value in configuration of type int.

Parameters:
path path to value
i new int value

Implements fawkes::Configuration.

Definition at line 1239 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by copy().

void fawkes::SQLiteConfiguration::set_string ( const char *  path,
const char *  s 
) [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.

Parameters:
path path to value
s new string value

Implements fawkes::Configuration.

Definition at line 1345 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

void fawkes::SQLiteConfiguration::set_string ( const char *  path,
std::string &  s 
) [virtual]

Set new value in configuration of type string.

Parameters:
path path to value
s new string value

Implements fawkes::Configuration.

Definition at line 1401 of file sqlite.cpp.

Referenced by copy().

void fawkes::SQLiteConfiguration::set_uint ( const char *  path,
unsigned int  uint 
) [virtual]

Set new value in configuration of type unsigned int.

Parameters:
path path to value
uint new unsigned int value

Implements fawkes::Configuration.

Definition at line 1187 of file sqlite.cpp.

References fawkes::Configuration::find_handlers(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

Referenced by copy().

void fawkes::SQLiteConfiguration::tag ( const char *  tag  )  [virtual]

Tag this configuration version.

This creates a new tagged version of the current config. The tagged config can be accessed via load().

Parameters:
tag tag for this version

Implements fawkes::Configuration.

Definition at line 690 of file sqlite.cpp.

References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

std::list< std::string > fawkes::SQLiteConfiguration::tags (  )  [virtual]

List of tags.

Returns:
list of tags

Implements fawkes::Configuration.

Definition at line 715 of file sqlite.cpp.

References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().

void fawkes::SQLiteConfiguration::transaction_begin ( transaction_type_t  ttype = TRANSACTION_DEFERRED  ) 

Begin SQL Transaction.

Parameters:
ttype transaction type

Definition at line 501 of file sqlite.cpp.

References TRANSACTION_EXCLUSIVE, and TRANSACTION_IMMEDIATE.

Referenced by copy().

void fawkes::SQLiteConfiguration::transaction_commit (  ) 

Commit SQL Transaction.

Definition at line 518 of file sqlite.cpp.

Referenced by copy().

void fawkes::SQLiteConfiguration::transaction_rollback (  ) 

Rollback SQL Transaction.

Definition at line 531 of file sqlite.cpp.

bool fawkes::SQLiteConfiguration::try_lock (  )  [virtual]

Try to lock the config.

See also:
Configuration::lock()
Returns:
true, if the lock has been aquired, false otherwise

Implements fawkes::Configuration.

Definition at line 1851 of file sqlite.cpp.

References fawkes::Mutex::try_lock().

void fawkes::SQLiteConfiguration::unlock (  )  [virtual]

Unlock the config.

Modifications and queries are possible again.

Implements fawkes::Configuration.

Definition at line 1860 of file sqlite.cpp.

References fawkes::Mutex::unlock().


The documentation for this class was generated from the following files: