From 6b63b75836202b8647c867acb9a0d0e695e23761 Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Thu, 20 May 2010 17:01:32 +0200 Subject: [PATCH] Added config option for starting in offline mode. --- src/config.cpp | 19 +++++++++++++++++++ src/config.h | 3 +++ src/main.cpp | 5 ++++- 3 files changed, 26 insertions(+), 1 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 24f720b..efce38b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -52,6 +52,7 @@ Config::Config() , ProxyPort(0) , ExternalWarningLog("") , ExternalWarningLevel(0) + , StartOffline(false) { // Available service description config options po::options_description opt_desc_service("Service description options"); @@ -88,6 +89,7 @@ Config::Config() ("http_proxy_port",po::value(),"Port of the proxy.") ("external_warning_log",po::value()->default_value(""),"External programm to pass warning log messages to.") ("external_warning_level",po::value()->default_value(0),"Warning messages of which loglevel should be passed to external programm.") + ("start_offline",po::value()->default_value(false),"Start in offline mode.") ; // Define valid command line parameters @@ -121,6 +123,7 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder) , ProxyPort(0) , ExternalWarningLog("") , ExternalWarningLevel(0) + , StartOffline(false) { // Available service description config options po::options_description opt_desc_service("Service description options"); @@ -157,6 +160,7 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder) ("http_proxy_port",po::value(),"Port of the proxy.") ("external_warning_log",po::value()->default_value(""),"External programm to pass warning log messages to.") ("external_warning_level",po::value()->default_value(0),"Warning messages of which loglevel should be passed to external programm.") + ("start_offline",po::value()->default_value(false),"Start in offline mode.") ; // Define valid command line parameters @@ -301,6 +305,9 @@ int Config::parse_cmd_line(int argc, char *argv[]) if ( VariablesMap.count("external_warning_level") ) ExternalWarningLevel = VariablesMap["external_warning_level"].as(); + if ( VariablesMap.count("start_offline") ) + StartOffline = VariablesMap["start_offline"].as(); + } catch( const po::unknown_option& e ) { @@ -552,6 +559,9 @@ int Config::load_main_config_file(const string& full_filename) if ( VariablesMap.count("external_warning_level") ) ExternalWarningLevel = VariablesMap["external_warning_level"].as(); + if ( VariablesMap.count("start_offline") ) + StartOffline = VariablesMap["start_offline"].as(); + } catch( const po::unknown_option& e ) // at the moment 04-08-2009 this exception is never thrown :-( { @@ -769,3 +779,12 @@ int Config::get_external_warning_level() const return ExternalWarningLevel; } + +/** + * Get member StartOffline + * @return StartOffline + */ +bool Config::get_start_offline() const +{ + return StartOffline; +} diff --git a/src/config.h b/src/config.h index 8de595b..d6e8d45 100644 --- a/src/config.h +++ b/src/config.h @@ -46,6 +46,7 @@ private: int ProxyPort; std::string ExternalWarningLog; int ExternalWarningLevel; + bool StartOffline; Service::Ptr create_service(const std::string& protocol, const std::string& server, const std::string& hostname, const std::string& login, const std::string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl); int load_main_config_file(const std::string& full_filename); @@ -95,6 +96,8 @@ public: std::string get_external_warning_log() const; + bool get_start_offline() const; + }; #endif diff --git a/src/main.cpp b/src/main.cpp index 683a7bd..eb0dac9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,7 @@ using namespace std; Updater::Ptr updater; -bool is_online = true; +bool is_online = false; /** * Checks if a bpdyndnsd process is already running. @@ -272,6 +272,9 @@ int main(int argc, char *argv[]) if ( init_daemon_mode(updater->get_config()->get_daemon_mode()) != 0 ) return -1; + // Should we start in offline mode? + is_online = !updater->get_config()->get_start_offline(); + // service processing starts here do { -- 1.7.1