Implemented command line parser for dialup mode
[bpdyndnsd] / src / config.cpp
index dea7544..87affb5 100644 (file)
@@ -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<int>()->default_value(0),"Warning messages of which loglevel should be passed to external programm.")
         ("external_log_only_once",po::value<bool>()->default_value(false),"Log the same external message only once until next reload or restart.")
         ("start_offline",po::value<bool>()->default_value(false),"Start in offline mode.")
+        ("dialup_mode",po::value<bool>()->default_value(false),"Enable dialup mode (sleep periods between network traffic)")
+        ("dialup_burst_period_seconds",po::value<int>()->default_value(120),"Seconds of normal operation before entering dialup mode")
+        ("dialup_sleep_seconds",po::value<int>()->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<int>()->default_value(0),"Warning messages of which loglevel should be passed to external programm.")
         ("external_log_only_once",po::value<bool>()->default_value(false),"Log the same external message only once until next reload or restart.")
         ("start_offline",po::value<bool>()->default_value(false),"Start in offline mode.")
+        ("dialup_mode",po::value<bool>()->default_value(false),"Enable dialup mode (sleep periods between network traffic)")
+        ("dialup_burst_period_seconds",po::value<int>()->default_value(120),"Seconds of normal operation before entering dialup mode")
+        ("dialup_sleep_seconds",po::value<int>()->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<bool>();
 
+        if ( VariablesMap.count("dialup_mode") )
+            DialupMode = VariablesMap["dialup_mode"].as<bool>();
+        if ( VariablesMap.count("dialup_burst_period_seconds") )
+            DialupBurstPeriodSeconds = VariablesMap["dialup_burst_period_seconds"].as<int>();
+        if ( VariablesMap.count("dialup_sleep_seconds") )
+            DialupSleepSeconds = VariablesMap["dialup_sleep_seconds"].as<int>();
     }
     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<bool>();
 
+            if ( VariablesMap.count("dialup_mode") )
+                DialupMode = VariablesMap["dialup_mode"].as<bool>();
+            if ( VariablesMap.count("dialup_burst_period_seconds") )
+                DialupBurstPeriodSeconds = VariablesMap["dialup_burst_period_seconds"].as<int>();
+            if ( VariablesMap.count("dialup_sleep_seconds") )
+                DialupSleepSeconds = VariablesMap["dialup_sleep_seconds"].as<int>();
         }
         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;
+}