From: Thomas Jarosch Date: Mon, 11 Oct 2010 09:16:24 +0000 (+0200) Subject: Implemented command line parser for dialup mode X-Git-Tag: v1.1~65 X-Git-Url: http://developer.intra2net.com/git/?p=bpdyndnsd;a=commitdiff_plain;h=2e9bd873ffdda4cdb24dcad9614b942bfb169d34 Implemented command line parser for dialup mode --- diff --git a/src/config.cpp b/src/config.cpp index dea7544..87affb5 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -55,6 +55,9 @@ Config::Config() , StartOffline(false) , WebcheckEnabled(false) , ExternalLogOnlyOnce(false) + , DialupMode(false) + , DialupBurstPeriodSeconds(120) + , DialupSleepSeconds(10 * 60) { // Available service description config options po::options_description opt_desc_service("Service description options"); @@ -94,6 +97,9 @@ Config::Config() ("external_warning_level",po::value()->default_value(0),"Warning messages of which loglevel should be passed to external programm.") ("external_log_only_once",po::value()->default_value(false),"Log the same external message only once until next reload or restart.") ("start_offline",po::value()->default_value(false),"Start in offline mode.") + ("dialup_mode",po::value()->default_value(false),"Enable dialup mode (sleep periods between network traffic)") + ("dialup_burst_period_seconds",po::value()->default_value(120),"Seconds of normal operation before entering dialup mode") + ("dialup_sleep_seconds",po::value()->default_value(10 * 60),"Seconds to sleep between network traffic") ; // Define valid command line parameters @@ -114,6 +120,7 @@ Config::Config() /** * Constructor with Logger and Serviceholder objects. Available command line and config file options with their default values are defined here. + * @todo Move the program options init code to a function used by both constructors */ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder) : Log(_log) @@ -130,6 +137,9 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder) , StartOffline(false) , WebcheckEnabled(false) , ExternalLogOnlyOnce(false) + , DialupMode(false) + , DialupBurstPeriodSeconds(120) + , DialupSleepSeconds(10 * 60) { // Available service description config options po::options_description opt_desc_service("Service description options"); @@ -169,6 +179,9 @@ Config::Config(Logger::Ptr _log, Serviceholder::Ptr _serviceholder) ("external_warning_level",po::value()->default_value(0),"Warning messages of which loglevel should be passed to external programm.") ("external_log_only_once",po::value()->default_value(false),"Log the same external message only once until next reload or restart.") ("start_offline",po::value()->default_value(false),"Start in offline mode.") + ("dialup_mode",po::value()->default_value(false),"Enable dialup mode (sleep periods between network traffic)") + ("dialup_burst_period_seconds",po::value()->default_value(120),"Seconds of normal operation before entering dialup mode") + ("dialup_sleep_seconds",po::value()->default_value(10 * 60),"Seconds to sleep between network traffic") ; // Define valid command line parameters @@ -324,6 +337,12 @@ int Config::parse_cmd_line(int argc, char *argv[]) if ( VariablesMap.count("start_offline") ) StartOffline = VariablesMap["start_offline"].as(); + if ( VariablesMap.count("dialup_mode") ) + DialupMode = VariablesMap["dialup_mode"].as(); + if ( VariablesMap.count("dialup_burst_period_seconds") ) + DialupBurstPeriodSeconds = VariablesMap["dialup_burst_period_seconds"].as(); + if ( VariablesMap.count("dialup_sleep_seconds") ) + DialupSleepSeconds = VariablesMap["dialup_sleep_seconds"].as(); } catch( const po::unknown_option& e ) { @@ -585,6 +604,12 @@ int Config::load_main_config_file(const string& full_filename) if ( VariablesMap.count("start_offline") ) StartOffline = VariablesMap["start_offline"].as(); + if ( VariablesMap.count("dialup_mode") ) + DialupMode = VariablesMap["dialup_mode"].as(); + if ( VariablesMap.count("dialup_burst_period_seconds") ) + DialupBurstPeriodSeconds = VariablesMap["dialup_burst_period_seconds"].as(); + if ( VariablesMap.count("dialup_sleep_seconds") ) + DialupSleepSeconds = VariablesMap["dialup_sleep_seconds"].as(); } catch( const po::unknown_option& e ) // at the moment 04-08-2009 this exception is never thrown :-( { @@ -841,3 +866,31 @@ bool Config::get_external_log_only_once() const { return ExternalLogOnlyOnce; } + + +/** + * Get member DialupMode + * @return DIalupMode +*/ +bool Config::get_dialup_mode() const +{ + return DialupMode; +} + +/** + * Get member DialupBurstPeriodSeconds + * @return DialupBurstPeriodSeconds +*/ +int Config::get_dialup_burst_period_seconds() const +{ + return DialupBurstPeriodSeconds; +} + +/** + * Get member DialupSleepSeconds + * @return DialupSleepSeconds +*/ +int Config::get_dialup_sleep_seconds() const +{ + return DialupSleepSeconds; +} diff --git a/src/config.hpp b/src/config.hpp index 8be4128..9c94754 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -49,6 +49,9 @@ private: bool StartOffline; bool WebcheckEnabled; bool ExternalLogOnlyOnce; + bool DialupMode; + int DialupBurstPeriodSeconds; + int DialupSleepSeconds; 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); @@ -106,6 +109,9 @@ public: bool get_external_log_only_once() const; + bool get_dialup_mode() const; + int get_dialup_burst_period_seconds() const; + int get_dialup_sleep_seconds() const; }; #endif