Fawkes API  Fawkes Development Version
fawkes::NetworkConfiguration Class Reference

Remote configuration via Fawkes net. More...

#include <>>

Inheritance diagram for fawkes::NetworkConfiguration:

List of all members.

Classes

class  NetConfValueIterator
 Network configuration value iterator. More...

Public Member Functions

 NetworkConfiguration (FawkesNetworkClient *c, unsigned int mirror_timeout_sec=15)
 Constructor.
virtual ~NetworkConfiguration ()
 Destructor.
virtual void copy (Configuration *copyconf)
 Copy all values from the given configuration.
virtual void add_change_handler (ConfigurationChangeHandler *h)
 Add a configuration change handler.
virtual void rem_change_handler (ConfigurationChangeHandler *h)
 Remove a configuration change handler.
virtual void load (const char *filename, const char *defaults_filename, const char *tag=NULL)
 Load configuration.
virtual void tag (const char *tag)
 Tag this configuration version.
virtual std::list< std::stringtags ()
 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 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 std::string get_type (const char *path)
 Get type of field.
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, std::string &comment)
 Set new default comment for existing default configuration value.
virtual void set_default_comment (const char *path, const char *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.
virtual void deregistered (unsigned int id) throw ()
 We are no longer registered in Fawkes network client.
virtual void inbound_received (FawkesNetworkMessage *msg, unsigned int id) throw ()
 Called for incoming messages.
virtual void connection_died (unsigned int id) throw ()
 Client connection died.
virtual void connection_established (unsigned int id) throw ()
 Client has established a connection.
virtual void set_mirror_mode (bool mirror)
 Enable or disable mirror mode.
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.

Detailed Description

Remote configuration via Fawkes net.

This implementation of the Configuration interface allows for remote access to a Fawkes process implemented using the ConfigurationManager.

The network configuration can operator in two modes. In mirror and in non-mirror mode. The non-mirror mode is recommended if only a few operations have to be carried out like getting only a very few values or setting a single value. The mirror mode is for longer usage periods and on-the-fly updates. In mirror mode the complete configuration is copied once from the Fawkes process and then all updates are incorporated into the local database. You can register change handlers to be notified as soon as someone modifies a value.


Constructor & Destructor Documentation

fawkes::NetworkConfiguration::NetworkConfiguration ( FawkesNetworkClient c,
unsigned int  mirror_timeout_sec = 15 
)

Constructor.

Parameters:
cFawkes network client (thread).
mirror_timeout_sectimeout in seconds for initiating mirroring

Definition at line 78 of file netconf.cpp.

References fawkes::FawkesNetworkClient::connected(), fawkes::FawkesNetworkClient::register_handler(), and fawkes::Exception::append().

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

Member Function Documentation

void fawkes::NetworkConfiguration::add_change_handler ( ConfigurationChangeHandler h) [virtual]

Add a configuration change handler.

The added handler is called whenever a value changes and the handler desires to get notified for the given component.

Parameters:
hconfiguration change handler

Reimplemented from fawkes::Configuration.

Definition at line 1246 of file netconf.cpp.

References fawkes::Configuration::add_change_handler().

void fawkes::NetworkConfiguration::connection_died ( unsigned int  id) throw () [virtual]

Client connection died.

This method is used to inform handlers that the connection has died for any reason. No more data can be send and no more messages should be enqueued because it is unclear when they would be sent.

Parameters:
idthe id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 1228 of file netconf.cpp.

void fawkes::NetworkConfiguration::connection_established ( unsigned int  id) throw () [virtual]

Client has established a connection.

Whenever the client establishes a connection this is signaled to handlers with this method. You can register to a client at any time, you may even enqueue messages to a client while the connection is dead. If the client at some point gets connected again, the messages will then be send out in one go. You should use this in your application though to only send data if the connection is alive and you should let the user know about the connection status.

Parameters:
idthe id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 1238 of file netconf.cpp.

void fawkes::NetworkConfiguration::deregistered ( unsigned int  id) throw () [virtual]

We are no longer registered in Fawkes network client.

Ignored.

Parameters:
idthe id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 1015 of file netconf.cpp.

void fawkes::NetworkConfiguration::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:
pathpath to value

Implements fawkes::Configuration.

Definition at line 997 of file netconf.cpp.

void fawkes::NetworkConfiguration::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:
pathpath to value

Implements fawkes::Configuration.

Definition at line 1004 of file netconf.cpp.

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

Check if a given value exists.

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

Implements fawkes::Configuration.

Definition at line 177 of file netconf.cpp.

References get_value(), and fawkes::Configuration::ValueIterator::valid().

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

Get value from configuration which is of type bool.

Parameters:
pathpath to value
Returns:
value

Implements fawkes::Configuration.

Definition at line 432 of file netconf.cpp.

References fawkes::Mutex::lock(), fawkes::SQLiteConfiguration::get_bool(), fawkes::Exception::append(), fawkes::Mutex::unlock(), fawkes::FawkesNetworkMessage::msg(), fawkes::config_bool_value_msg_t::b, and fawkes::RefCount::unref().

std::string fawkes::NetworkConfiguration::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:
pathpath to value
Returns:
comment
Exceptions:
ConfigEntryNotFoundExceptionshall be thrown if value does not exist
ConfigurationExceptionshall be thrown on any other error

Implements fawkes::Configuration.

Definition at line 532 of file netconf.cpp.

References fawkes::Mutex::lock(), fawkes::SQLiteConfiguration::get_comment(), fawkes::Exception::append(), fawkes::Mutex::unlock(), fawkes::FawkesNetworkMessage::msgge(), fawkes::config_comment_msg_t::s, and fawkes::RefCount::unref().

std::string fawkes::NetworkConfiguration::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:
pathpath to value
Returns:
comment
Exceptions:
ConfigEntryNotFoundExceptionshall be thrown if value does not exist
ConfigurationExceptionshall be thrown on any other error

Implements fawkes::Configuration.

Definition at line 582 of file netconf.cpp.

References fawkes::Mutex::lock(), fawkes::SQLiteConfiguration::get_default_comment(), fawkes::Exception::append(), fawkes::Mutex::unlock(), fawkes::FawkesNetworkMessage::msgge(), fawkes::config_comment_msg_t::s, and fawkes::RefCount::unref().

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

Get value from configuration which is of type float.

Parameters:
pathpath to value
Returns:
value

Implements fawkes::Configuration.

Definition at line 282 of file netconf.cpp.

References fawkes::Mutex::lock(), fawkes::SQLiteConfiguration::get_float(), fawkes::Exception::append(), fawkes::Mutex::unlock(), fawkes::FawkesNetworkMessage::msg(), fawkes::config_float_value_msg_t::f, and fawkes::RefCount::unref().

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

Get value from configuration which is of type int.

Parameters:
pathpath to value
Returns:
value

Implements fawkes::Configuration.

Definition at line 382 of file netconf.cpp.

References fawkes::Mutex::lock(), fawkes::SQLiteConfiguration::get_int(), fawkes::Exception::append(), fawkes::Mutex::unlock(), fawkes::FawkesNetworkMessage::msg(), fawkes::config_int_value_msg_t::i, and fawkes::RefCount::unref().

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

Get value from configuration which is of type string.

Parameters:
pathpath to value
Returns:
value

Implements fawkes::Configuration.

Definition at line 482 of file netconf.cpp.

References fawkes::Mutex::lock(), fawkes::SQLiteConfiguration::get_string(), fawkes::Exception::append(), fawkes::Mutex::unlock(), fawkes::FawkesNetworkMessage::msgge(), fawkes::config_string_value_msg_t::s, and fawkes::RefCount::unref().

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

Get type of field.

Parameters:
pathpath
Returns:
string of type

Implements fawkes::Configuration.

Definition at line 201 of file netconf.cpp.

References fawkes::Mutex::lock(), fawkes::SQLiteConfiguration::get_type(), fawkes::Mutex::unlock(), get_value(), and fawkes::Configuration::ValueIterator::type().

Referenced by is_float(), is_uint(), is_int(), is_bool(), and is_string().

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

Get value from configuration which is of type unsigned int.

Parameters:
pathpath to value
Returns:
value

Implements fawkes::Configuration.

Definition at line 332 of file netconf.cpp.

References fawkes::Mutex::lock(), fawkes::SQLiteConfiguration::get_uint(), fawkes::Exception::append(), fawkes::Mutex::unlock(), fawkes::FawkesNetworkMessage::msg(), fawkes::config_uint_value_msg_t::u, and fawkes::RefCount::unref().

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

Get value from configuration.

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

Implements fawkes::Configuration.

Definition at line 633 of file netconf.cpp.

References fawkes::Mutex::lock(), fawkes::SQLiteConfiguration::get_value(), fawkes::Exception::append(), fawkes::Mutex::unlock(), fawkes::config_getval_msg_t::cp, fawkes::config_descriptor_t::path, fawkes::FawkesNetworkClient::enqueue_and_wait(), and fawkes::RefCount::unref().

Referenced by exists(), is_default(), and get_type().

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

Check if a value is of type bool.

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

Implements fawkes::Configuration.

Definition at line 240 of file netconf.cpp.

References get_type().

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

Check if a value was read from the default config.

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

Implements fawkes::Configuration.

Definition at line 187 of file netconf.cpp.

References get_value(), and fawkes::Configuration::ValueIterator::is_default().

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

Check if a value is of type float.

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

Implements fawkes::Configuration.

Definition at line 219 of file netconf.cpp.

References get_type().

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

Check if a value is of type int.

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

Implements fawkes::Configuration.

Definition at line 233 of file netconf.cpp.

References get_type().

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

Check if a value is of type string.

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

Implements fawkes::Configuration.

Definition at line 247 of file netconf.cpp.

References get_type().

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

Check if a value is of type unsigned int.

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

Implements fawkes::Configuration.

Definition at line 226 of file netconf.cpp.

References get_type().

Configuration::ValueIterator * fawkes::NetworkConfiguration::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 1344 of file netconf.cpp.

References fawkes::SQLiteConfiguration::iterator().

Configuration::ValueIterator * fawkes::NetworkConfiguration::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 1355 of file netconf.cpp.

References fawkes::SQLiteConfiguration::iterator_default().

Configuration::ValueIterator * fawkes::NetworkConfiguration::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 1366 of file netconf.cpp.

References fawkes::SQLiteConfiguration::iterator_hostspecific().

void fawkes::NetworkConfiguration::load ( const char *  name,
const char *  defaults_name,
const char *  tag = NULL 
) [virtual]

Load configuration.

This is a noop for the NetworkConfiguration.

Parameters:
namename of the host-based database. This should be a name of the form hostname.db, where hostname is the unqualified part of the hostname.
defaults_namename of the default database. Should be defaults.db
tagoptional tag to restore

Implements fawkes::Configuration.

Definition at line 119 of file netconf.cpp.

void fawkes::NetworkConfiguration::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 1323 of file netconf.cpp.

References fawkes::Mutex::lock().

void fawkes::NetworkConfiguration::rem_change_handler ( ConfigurationChangeHandler h) [virtual]

Remove a configuration change handler.

The handler is removed from the change handler list and no longer called on config changes.

Parameters:
hconfiguration change handler

Reimplemented from fawkes::Configuration.

Definition at line 1257 of file netconf.cpp.

References fawkes::Configuration::rem_change_handler().

Configuration::ValueIterator * fawkes::NetworkConfiguration::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 path start with the given strings are returned. A call like

   config->search("");

is effectively the same as a call to iterator().

Parameters:
pathstart of path
Returns:
iterator to search results

Implements fawkes::Configuration.

Definition at line 1377 of file netconf.cpp.

References fawkes::SQLiteConfiguration::search().

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

Set new value in configuration of type bool.

Parameters:
pathpath to value
bnew bool value

Implements fawkes::Configuration.

Definition at line 835 of file netconf.cpp.

Referenced by copy().

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

Set new comment for existing value.

Parameters:
pathpath to value
commentnew comment string

Implements fawkes::Configuration.

Definition at line 955 of file netconf.cpp.

void fawkes::NetworkConfiguration::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:
pathpath to value
commentnew comment string

Implements fawkes::Configuration.

Definition at line 941 of file netconf.cpp.

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

Set new default value in configuration of type bool.

Parameters:
pathpath to value
bnew bool value

Implements fawkes::Configuration.

Definition at line 842 of file netconf.cpp.

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

Set new default comment for existing default configuration value.

Parameters:
pathpath to value
commentnew comment string

Implements fawkes::Configuration.

Definition at line 962 of file netconf.cpp.

void fawkes::NetworkConfiguration::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:
pathpath to value
commentnew comment string

Implements fawkes::Configuration.

Definition at line 948 of file netconf.cpp.

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

Set new default value in configuration of type float.

Parameters:
pathpath to value
fnew float value

Implements fawkes::Configuration.

Definition at line 717 of file netconf.cpp.

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

Set new default value in configuration of type int.

Parameters:
pathpath to value
inew int value

Implements fawkes::Configuration.

Definition at line 799 of file netconf.cpp.

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

Set new default value in configuration of type string.

Parameters:
pathpath to value
snew string value

Implements fawkes::Configuration.

Definition at line 901 of file netconf.cpp.

void fawkes::NetworkConfiguration::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:
pathpath to value
snew string value

Implements fawkes::Configuration.

Definition at line 887 of file netconf.cpp.

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

Set new default value in configuration of type unsigned int.

Parameters:
pathpath to value
uintnew unsigned int value

Implements fawkes::Configuration.

Definition at line 760 of file netconf.cpp.

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

Set new value in configuration of type float.

Parameters:
pathpath to value
fnew float value

Implements fawkes::Configuration.

Definition at line 710 of file netconf.cpp.

Referenced by copy().

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

Set new value in configuration of type int.

Parameters:
pathpath to value
inew int value

Implements fawkes::Configuration.

Definition at line 792 of file netconf.cpp.

Referenced by copy().

void fawkes::NetworkConfiguration::set_mirror_mode ( bool  mirror) [virtual]

Enable or disable mirror mode.

Parameters:
mirrortrue to enable mirror mode, false to disable

Definition at line 1270 of file netconf.cpp.

References fawkes::SQLiteConfiguration::load(), fawkes::Mutex::lock(), fawkes::FawkesNetworkClient::enqueue(), fawkes::InterruptibleBarrier::wait(), and fawkes::Mutex::unlock().

Referenced by ~NetworkConfiguration(), and ConfigTreeView::set_network_client().

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

Set new value in configuration of type string.

Parameters:
pathpath to value
snew string value

Implements fawkes::Configuration.

Definition at line 894 of file netconf.cpp.

Referenced by copy().

void fawkes::NetworkConfiguration::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:
pathpath to value
snew string value

Implements fawkes::Configuration.

Definition at line 880 of file netconf.cpp.

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

Set new value in configuration of type unsigned int.

Parameters:
pathpath to value
uintnew unsigned int value

Implements fawkes::Configuration.

Definition at line 753 of file netconf.cpp.

Referenced by copy().

void fawkes::NetworkConfiguration::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:
tagtag for this version

Implements fawkes::Configuration.

Definition at line 158 of file netconf.cpp.

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

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

List of tags.

Returns:
list of tags

Implements fawkes::Configuration.

Definition at line 167 of file netconf.cpp.

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

bool fawkes::NetworkConfiguration::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 1330 of file netconf.cpp.

References fawkes::Mutex::try_lock().

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

Unlock the config.

Modifications and queries are possible again.

Implements fawkes::Configuration.

Definition at line 1337 of file netconf.cpp.

References fawkes::Mutex::unlock().


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