From: Guilherme Maciel Ferreira Date: Tue, 13 Sep 2011 02:03:59 +0000 (-0300) Subject: Bring aboard "link-up-interval" configuration option class. X-Git-Tag: v1.3~11^2~34^2~25 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=c7da05e1080dfdbf6efb006a8fc9dac9b43bbb3b;p=pingcheck Bring aboard "link-up-interval" configuration option class. --- diff --git a/src/config/option/linkupintervaloption.cpp b/src/config/option/linkupintervaloption.cpp new file mode 100644 index 0000000..89b5845 --- /dev/null +++ b/src/config/option/linkupintervaloption.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/linkupintervaloption.h" + +#include + +using namespace std; +using boost::program_options::value; +using boost::program_options::variables_map; +using I2n::Logger::GlobalLogger; + +//----------------------------------------------------------------------------- +// LinkUpIntervalOption +//----------------------------------------------------------------------------- + +LinkUpIntervalOption::LinkUpIntervalOption() : + ConfigurationOption( + "link-up-interval", + value()->default_value( 5 ), // 5 minutes + "How long the link must be responsive in order to consider it stable." + ) +{ +} + +LinkUpIntervalOption::~LinkUpIntervalOption() +{ +} + +bool LinkUpIntervalOption::validate( const variables_map& vm ) const +{ + bool is_valid = ( vm.count( get_command_string() ) > 0 ); + + return is_valid; +} + +bool LinkUpIntervalOption::parse( + const variables_map& vm, + Configuration *configuration +) const +{ + // link-up-interval + if ( vm.count( get_command_string() ) > 0 ) + { + int link_up_interval_in_min = vm[ get_command_string() ].as(); + configuration->set_link_up_interval_in_min( link_up_interval_in_min ); + + GlobalLogger.info() << get_command_string() << "=" + << link_up_interval_in_min << endl; + + return true; + } + + return false; +} diff --git a/src/config/option/linkupintervaloption.h b/src/config/option/linkupintervaloption.h new file mode 100644 index 0000000..b77beaa --- /dev/null +++ b/src/config/option/linkupintervaloption.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_UP_INTERVAL_OPTION_H +#define LINK_UP_INTERVAL_OPTION_H + +#include + +#include "config/option/configurationoption.h" + +//----------------------------------------------------------------------------- +// LinkUpIntervalOption +//----------------------------------------------------------------------------- + +/** + * @brief This class represents the "link-up-interval" configuration option. + */ +class LinkUpIntervalOption : public ConfigurationOption +{ +public: + LinkUpIntervalOption(); + virtual ~LinkUpIntervalOption(); + + 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_UP_INTERVAL_OPTION_H