From: Guilherme Maciel Ferreira Date: Tue, 13 Sep 2011 02:00:33 +0000 (-0300) Subject: Bring aboard "source-network-interface" configuration option class. X-Git-Tag: v1.3~11^2~34^2~28 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=870d9384f4ec41a1e30a3b9ebfc2d6b4591b3824;p=pingcheck Bring aboard "source-network-interface" configuration option class. --- diff --git a/src/config/option/sourcenetworkinterfaceoption.cpp b/src/config/option/sourcenetworkinterfaceoption.cpp new file mode 100644 index 0000000..63aab7b --- /dev/null +++ b/src/config/option/sourcenetworkinterfaceoption.cpp @@ -0,0 +1,73 @@ +/* + 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/sourcenetworkinterfaceoption.h" + +#include + +using namespace std; +using boost::program_options::value; +using boost::program_options::variables_map; +using I2n::Logger::GlobalLogger; + +//----------------------------------------------------------------------------- +// SourceNetworkInterfaceOption +//----------------------------------------------------------------------------- + +SourceNetworkInterfaceOption::SourceNetworkInterfaceOption() : + ConfigurationOption( + "source-network-interface", + value(), + "The network interface from where the packets will be received and originated" + ) +{ +} + +SourceNetworkInterfaceOption::~SourceNetworkInterfaceOption() +{ +} + +bool SourceNetworkInterfaceOption::validate( const variables_map& vm ) const +{ + // TODO validate if it is a valid interface + bool is_valid = ( vm.count( get_command_string() ) > 0 ); + + return is_valid; +} + +bool SourceNetworkInterfaceOption::parse( + const variables_map& vm, + Configuration *configuration +) const +{ + // source-network-interface + if ( vm.count( get_command_string() ) > 0 ) + { + string source_network_interface = vm[ get_command_string() ].as (); + configuration->set_source_network_interface( source_network_interface ); + + GlobalLogger.info() << get_command_string() << "=" + << source_network_interface << endl; + + return true; + } + + return false; +} diff --git a/src/config/option/sourcenetworkinterfaceoption.h b/src/config/option/sourcenetworkinterfaceoption.h new file mode 100644 index 0000000..3aa7f17 --- /dev/null +++ b/src/config/option/sourcenetworkinterfaceoption.h @@ -0,0 +1,53 @@ +/* + 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 SOURCE_NETWORK_INTERFACE_OPTION_H +#define SOURCE_NETWORK_INTERFACE_OPTION_H + +#include + +#include "config/option/configurationoption.h" + +//----------------------------------------------------------------------------- +// SourceNetworkInterfaceOption +//----------------------------------------------------------------------------- + +/** + * @brief This class represents the "source-network-interface" configuration + * option. + */ +class SourceNetworkInterfaceOption : public ConfigurationOption +{ +public: + SourceNetworkInterfaceOption(); + virtual ~SourceNetworkInterfaceOption(); + + 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 // SOURCE_NETWORK_INTERFACE_OPTION_H