Remote configuration via Fawkes net. More...
#include <>>
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) |
virtual void | rem_change_handler (ConfigurationChangeHandler *h) |
virtual void | load (const char *filename, const char *defaults_filename, const char *tag=NULL) |
Load configuration. | |
virtual void | tag (const char *tag) |
virtual std::list< std::string > | tags () |
virtual bool | exists (const char *path) |
virtual bool | is_float (const char *path) |
virtual bool | is_uint (const char *path) |
virtual bool | is_int (const char *path) |
virtual bool | is_bool (const char *path) |
virtual bool | is_string (const char *path) |
virtual bool | is_default (const char *path) |
virtual float | get_float (const char *path) |
virtual unsigned int | get_uint (const char *path) |
virtual int | get_int (const char *path) |
virtual bool | get_bool (const char *path) |
virtual std::string | get_string (const char *path) |
virtual ValueIterator * | get_value (const char *path) |
virtual std::string | get_comment (const char *path) |
virtual std::string | get_default_comment (const char *path) |
virtual std::string | get_type (const char *path) |
Get type of field. | |
virtual void | set_float (const char *path, float f) |
virtual void | set_uint (const char *path, unsigned int uint) |
virtual void | set_int (const char *path, int i) |
virtual void | set_bool (const char *path, bool b) |
virtual void | set_string (const char *path, std::string &s) |
virtual void | set_string (const char *path, const char *s) |
virtual void | set_comment (const char *path, std::string &comment) |
virtual void | set_comment (const char *path, const char *comment) |
virtual void | erase (const char *path) |
virtual void | set_default_float (const char *path, float f) |
virtual void | set_default_uint (const char *path, unsigned int uint) |
virtual void | set_default_int (const char *path, int i) |
virtual void | set_default_bool (const char *path, bool b) |
virtual void | set_default_string (const char *path, std::string &s) |
virtual void | set_default_string (const char *path, const char *s) |
virtual void | set_default_comment (const char *path, std::string &comment) |
virtual void | set_default_comment (const char *path, const char *comment) |
virtual void | erase_default (const char *path) |
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. | |
ValueIterator * | iterator () |
ValueIterator * | iterator_default () |
ValueIterator * | iterator_hostspecific () |
ValueIterator * | search (const char *path) |
void | lock () |
bool | try_lock () |
void | unlock () |
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.
Definition at line 48 of file netconf.h.
fawkes::NetworkConfiguration::NetworkConfiguration | ( | FawkesNetworkClient * | c, | |
unsigned int | mirror_timeout_sec = 15 | |||
) |
Constructor.
c | Fawkes network client (thread). | |
mirror_timeout_sec | timeout in seconds for initiating mirroring |
Definition at line 77 of file netconf.cpp.
References fawkes::Exception::append(), fawkes::FawkesNetworkClient::connected(), and fawkes::FawkesNetworkClient::register_handler().
fawkes::NetworkConfiguration::~NetworkConfiguration | ( | ) | [virtual] |
Destructor.
Definition at line 98 of file netconf.cpp.
References fawkes::FawkesNetworkClient::deregister_handler(), set_mirror_mode(), and fawkes::RefCount::unref().
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.
id | the id of the calling client |
Implements fawkes::FawkesNetworkClientHandler.
Definition at line 1227 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.
id | the id of the calling client |
Implements fawkes::FawkesNetworkClientHandler.
Definition at line 1237 of file netconf.cpp.
void fawkes::NetworkConfiguration::copy | ( | Configuration * | copyconf | ) | [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 |
Definition at line 133 of file netconf.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(), and fawkes::Configuration::unlock().
void fawkes::NetworkConfiguration::deregistered | ( | unsigned int | id | ) | throw () [virtual] |
We are no longer registered in Fawkes network client.
Ignored.
id | the id of the calling client |
Implements fawkes::FawkesNetworkClientHandler.
Definition at line 1014 of file netconf.cpp.
std::string fawkes::NetworkConfiguration::get_type | ( | const char * | path | ) | [virtual] |
Get type of field.
path | path |
Definition at line 200 of file netconf.cpp.
References fawkes::SQLiteConfiguration::get_type(), fawkes::Mutex::lock(), fawkes::Configuration::ValueIterator::type(), and fawkes::Mutex::unlock().
void fawkes::NetworkConfiguration::inbound_received | ( | FawkesNetworkMessage * | m, | |
unsigned int | id | |||
) | throw () [virtual] |
Called for incoming messages.
This is called when an incoming message has been received. If this method was called one or more times then the a previously carried out wait(cid) call will continue.
m | Message to handle | |
id | the id of the calling client |
Implements fawkes::FawkesNetworkClientHandler.
Definition at line 1020 of file netconf.cpp.
References fawkes::config_bool_value_msg_t::b, fawkes::config_list_bool_entity_t::b, fawkes::config_comment_msg_t::cp, fawkes::config_string_value_msg_t::cp, fawkes::config_bool_value_msg_t::cp, fawkes::config_int_value_msg_t::cp, fawkes::config_uint_value_msg_t::cp, fawkes::config_float_value_msg_t::cp, fawkes::config_value_erased_msg_t::cp, fawkes::config_list_entity_header_t::cp, fawkes::config_float_value_msg_t::f, fawkes::config_list_float_entity_t::f, fawkes::ConfigListContent::has_next(), fawkes::config_int_value_msg_t::i, fawkes::config_list_int_entity_t::i, fawkes::config_descriptor_t::is_default, fawkes::LibLogger::log_warn(), fawkes::ConfigListContent::next(), fawkes::config_descriptor_t::path, fawkes::config_comment_msg_t::s, fawkes::config_string_value_msg_t::s, fawkes::config_list_comment_entity_t::s, fawkes::config_list_string_entity_t::s, fawkes::config_list_entity_header_t::type, fawkes::config_uint_value_msg_t::u, and fawkes::config_list_uint_entity_t::u.
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.
name | name 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_name | name of the default database. Should be defaults.db | |
tag | optional tag to restore |
Definition at line 118 of file netconf.cpp.
void fawkes::NetworkConfiguration::set_mirror_mode | ( | bool | mirror | ) | [virtual] |
Enable or disable mirror mode.
mirror | true to enable mirror mode, false to disable |
Definition at line 1269 of file netconf.cpp.
References fawkes::FawkesNetworkClient::enqueue(), fawkes::SQLiteConfiguration::load(), fawkes::Mutex::lock(), fawkes::Mutex::unlock(), and fawkes::InterruptibleBarrier::wait().
Referenced by ConfigTreeView::set_network_client(), and ~NetworkConfiguration().