Added config option for starting in offline mode.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Thu, 20 May 2010 15:01:32 +0000 (17:01 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Thu, 20 May 2010 15:01:32 +0000 (17:01 +0200)
src/config.cpp
src/config.h
src/main.cpp

index 24f720b..efce38b 100644 (file)
@@ -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<int>(),"Port of the proxy.")
         ("external_warning_log",po::value<string>()->default_value(""),"External programm to pass warning log messages to.")
         ("external_warning_level",po::value<int>()->default_value(0),"Warning messages of which loglevel should be passed to external programm.")
+        ("start_offline",po::value<bool>()->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<int>(),"Port of the proxy.")
         ("external_warning_log",po::value<string>()->default_value(""),"External programm to pass warning log messages to.")
         ("external_warning_level",po::value<int>()->default_value(0),"Warning messages of which loglevel should be passed to external programm.")
+        ("start_offline",po::value<bool>()->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<int>();
 
+        if ( VariablesMap.count("start_offline") )
+            StartOffline = VariablesMap["start_offline"].as<bool>();
+
     }
     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<int>();
 
+            if ( VariablesMap.count("start_offline") )
+                StartOffline = VariablesMap["start_offline"].as<bool>();
+
         }
         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;
+}
index 8de595b..d6e8d45 100644 (file)
@@ -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
index 683a7bd..eb0dac9 100644 (file)
@@ -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
     {