From f087c7cadccb8149774091a52a287e8713b2b5c7 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Mon, 12 Sep 2011 23:05:52 -0300 Subject: [PATCH] Bring aboard "link-down-interval" configuration option class. --- src/config/option/linkdownintervaloption.cpp | 72 ++++++++++++++++++++++++++ src/config/option/linkdownintervaloption.h | 52 ++++++++++++++++++ 2 files changed, 124 insertions(+), 0 deletions(-) create mode 100644 src/config/option/linkdownintervaloption.cpp create mode 100644 src/config/option/linkdownintervaloption.h diff --git a/src/config/option/linkdownintervaloption.cpp b/src/config/option/linkdownintervaloption.cpp new file mode 100644 index 0000000..47511b7 --- /dev/null +++ b/src/config/option/linkdownintervaloption.cpp @@ -0,0 +1,72 @@ +/* + The software in this package is distributed under the GNU General + Public License version 2 (with a special exception described below). + + A copy of GNU General Public License (GPL) is included in this distribution, + in the file COPYING.GPL. + + As a special exception, if other files instantiate templates or use macros + or inline functions from this file, or you compile this file and link it + with other works to produce a work based on this file, this file + does not by itself cause the resulting work to be covered + by the GNU General Public License. + + However the source code for this file must still be made available + in accordance with section (3) of the GNU General Public License. + + This exception does not invalidate any other reasons why a work based + on this file might be covered by the GNU General Public License. + */ + +#include "config/option/linkdownintervaloption.h" + +#include + +using namespace std; +using boost::program_options::value; +using boost::program_options::variables_map; +using I2n::Logger::GlobalLogger; + +//----------------------------------------------------------------------------- +// LinkDownIntervalOption +//----------------------------------------------------------------------------- + +LinkDownIntervalOption::LinkDownIntervalOption() : + ConfigurationOption( + "link-down-interval", + value()->default_value( 2 ), // 2 minutes + "How long the link must be offline in order to consider it down." + ) +{ +} + +LinkDownIntervalOption::~LinkDownIntervalOption() +{ +} + +bool LinkDownIntervalOption::validate( const variables_map& vm ) const +{ + bool is_valid = ( vm.count( get_command_string() ) > 0 ); + + return is_valid; +} + +bool LinkDownIntervalOption::parse( + const variables_map& vm, + Configuration *configuration +) const +{ + // link-down-interval + if ( vm.count( get_command_string() ) > 0 ) + { + int link_down_interval_in_min = vm[ get_command_string() ].as(); + configuration->set_link_down_interval_in_min( link_down_interval_in_min ); + + GlobalLogger.info() << get_command_string() << "=" + << link_down_interval_in_min << endl; + + return true; + } + + return false; +} diff --git a/src/config/option/linkdownintervaloption.h b/src/config/option/linkdownintervaloption.h new file mode 100644 index 0000000..22d90f4 --- /dev/null +++ b/src/config/option/linkdownintervaloption.h @@ -0,0 +1,52 @@ +/* + The software in this package is distributed under the GNU General + Public License version 2 (with a special exception described below). + + A copy of GNU General Public License (GPL) is included in this distribution, + in the file COPYING.GPL. + + As a special exception, if other files instantiate templates or use macros + or inline functions from this file, or you compile this file and link it + with other works to produce a work based on this file, this file + does not by itself cause the resulting work to be covered + by the GNU General Public License. + + However the source code for this file must still be made available + in accordance with section (3) of the GNU General Public License. + + This exception does not invalidate any other reasons why a work based + on this file might be covered by the GNU General Public License. + */ + +#ifndef LINK_DOWN_INTERVAL_OPTION_H +#define LINK_DOWN_INTERVAL_OPTION_H + +#include + +#include "config/option/configurationoption.h" + +//----------------------------------------------------------------------------- +// LinkDownIntervalOption +//----------------------------------------------------------------------------- + +/** + * @brief This class represents the "link-down-interval" configuration option. + */ +class LinkDownIntervalOption : public ConfigurationOption +{ +public: + LinkDownIntervalOption(); + virtual ~LinkDownIntervalOption(); + + virtual bool validate( + const boost::program_options::variables_map &vm + ) const; + + virtual bool parse( + const boost::program_options::variables_map &vm, + Configuration *configuration + ) const; + +}; + +#endif // LINK_DOWN_INTERVAL_OPTION_H -- 1.7.1