-limit-to-notify=5
\ No newline at end of file
+limit-to-notify=5
+
+[host]
+name=www.intra2net.com
Configuration::Configuration() :
config_file_name( "" ),
limit_to_notify( 0 ),
+ host( "" ),
MIN_LIMIT_TO_NOTIFY( 0 ),
MAX_LIMIT_TO_NOTIFY( 50 )
{
return config_file_name;
}
-void Configuration::set_config_file_name( std::string config_file_name )
+void Configuration::set_config_file_name( const std::string& config_file_name )
{
BOOST_ASSERT( !config_file_name.empty() );
return limit_to_notify;
}
-void Configuration::set_limit_to_notify( uint32_t limit_to_notify )
+void Configuration::set_limit_to_notify( const uint32_t limit_to_notify )
{
BOOST_ASSERT( ( MIN_LIMIT_TO_NOTIFY <= limit_to_notify ) && ( limit_to_notify <= MAX_LIMIT_TO_NOTIFY) );
this->limit_to_notify = limit_to_notify;
}
+
+Host Configuration::get_host() const
+{
+ return host;
+}
+
+void Configuration::set_host( const Host& host )
+{
+ this->host = host;
+}
+
#include <stdint.h>
#include <string>
+#include "host.h"
+
//-----------------------------------------------------------------------------
// Configuration
//-----------------------------------------------------------------------------
virtual ~Configuration();
std::string get_config_file_name() const;
- void set_config_file_name( std::string config_file_name );
+ void set_config_file_name( const std::string& config_file_name );
uint32_t get_limit_to_notify() const;
- void set_limit_to_notify( uint32_t limit_to_notify );
+ void set_limit_to_notify( const uint32_t limit_to_notify );
+
+ Host get_host() const;
+ void set_host( const Host& host );
private:
std::string config_file_name;
uint32_t limit_to_notify;
+ Host host;
const uint32_t MIN_LIMIT_TO_NOTIFY;
const uint32_t MAX_LIMIT_TO_NOTIFY;
DEFAULT_LIMIT_TO_NOTIFY( 4 ),
LIMIT_TO_NOTIFY_CMD_STR( "limit-to-notify" ),
LIMIT_TO_NOTIFY_CMD_DESC( "Limit of host that have to be down in order to notify." ),
- HOST_CMD_STR( "host" ),
- HOST_CMD_DESC( "Host address" )
+ HOST_NAME_CMD_STR( "host.name" ),
+ HOST_NAME_CMD_DESC( "Host address" )
{
}
options_description options( "Configuration" );
options.add_options()
( LIMIT_TO_NOTIFY_CMD_STR.c_str(), value<int>()->default_value( DEFAULT_LIMIT_TO_NOTIFY ), LIMIT_TO_NOTIFY_CMD_DESC.c_str() )
- ( HOST_CMD_STR.c_str(), value< vector<string> >(), HOST_CMD_DESC.c_str() );
+ ( HOST_NAME_CMD_STR.c_str(), value< string >(), HOST_NAME_CMD_DESC.c_str() );
return options;
}
visible.add( generic ).add( config );
positional_options_description p;
- p.add( HOST_CMD_STR.c_str(), -1 );
+ p.add( HOST_NAME_CMD_STR.c_str(), -1 );
store( command_line_parser( argc, argv ).
options( cmdline_options ).
char* argv[]
)
{
- BOOST_ASSERT( argc > 1 );
+ BOOST_ASSERT( argc > 0 );
BOOST_ASSERT( argv != NULL );
variables_map vm;
cout << LIMIT_TO_NOTIFY_CMD_STR << "=" << limit_to_notify << endl;
}
+ if ( vm.count( HOST_NAME_CMD_STR ) )
+ {
+ string host_name = vm[ HOST_NAME_CMD_STR ].as<string> ();
+ Host host = configuration.get_host();
+ host.set_address( host_name );
+ configuration.set_host( host );
+
+ cout << HOST_NAME_CMD_STR << "=" << host_name << endl;
+ }
+
return true;
}
{
return configuration;
}
-
const uint32_t DEFAULT_LIMIT_TO_NOTIFY;
const std::string LIMIT_TO_NOTIFY_CMD_STR;
const std::string LIMIT_TO_NOTIFY_CMD_DESC;
- const std::string HOST_CMD_STR;
- const std::string HOST_CMD_DESC;
+ const std::string HOST_NAME_CMD_STR;
+ const std::string HOST_NAME_CMD_DESC;
};
#include "host.h"
#include "boostpinger.h"
+using namespace std;
+
int main( int argc, char* argv[] )
{
// sends the program command line to be parsed by the configuration reader
{
boost::asio::io_service io_service;
BoostPinger p( io_service );
-// Configuration configuration = config_reader.getConfiguration();
-// Host host( configuration.get_hosts().at(0) ); // TODO pass Configuration object
- Host host( argv[1] );
+ Configuration config = config_reader.get_configuration();
+ Host host = config.get_host();
p.ping( host );
io_service.run();
}