From: Guilherme Maciel Ferreira Date: Mon, 7 Mar 2011 09:17:18 +0000 (+0100) Subject: Changed integer types from std::size_t to uint, where it is required ordinary numbers X-Git-Tag: v1.0~160 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=15b5c4c641669eaa63c9d575887e82fb8da2b01e;p=pingcheck Changed integer types from std::size_t to uint, where it is required ordinary numbers --- diff --git a/src/config/configuration.cpp b/src/config/configuration.cpp index 654a384..f9a97fa 100644 --- a/src/config/configuration.cpp +++ b/src/config/configuration.cpp @@ -33,12 +33,12 @@ void Configuration::set_config_file_name( const std::string &config_file_name ) this->ConfigFileName = config_file_name; } -std::size_t Configuration::get_limit_to_notify() const +uint Configuration::get_limit_to_notify() const { return LimitToNotify; } -void Configuration::set_limit_to_notify( const std::size_t limit_to_notify ) +void Configuration::set_limit_to_notify( const uint limit_to_notify ) { BOOST_ASSERT( ( MinLimitToNotify <= limit_to_notify ) && ( limit_to_notify <= MaxLimitToNotify) ); diff --git a/src/config/configuration.h b/src/config/configuration.h index 229e747..4aba3cc 100644 --- a/src/config/configuration.h +++ b/src/config/configuration.h @@ -20,19 +20,19 @@ public: std::string get_config_file_name() const; void set_config_file_name( const std::string &config_file_name ); - std::size_t get_limit_to_notify() const; - void set_limit_to_notify( const std::size_t limit_to_notify ); + uint get_limit_to_notify() const; + void set_limit_to_notify( const uint limit_to_notify ); std::vector get_hosts() const; void set_hosts( const std::vector &hosts_list ); private: std::string ConfigFileName; - std::size_t LimitToNotify; + uint LimitToNotify; std::vector Hosts; - const std::size_t MinLimitToNotify; - const std::size_t MaxLimitToNotify; + const uint MinLimitToNotify; + const uint MaxLimitToNotify; }; diff --git a/src/config/configurationreader.cpp b/src/config/configurationreader.cpp index a60481a..31a2529 100644 --- a/src/config/configurationreader.cpp +++ b/src/config/configurationreader.cpp @@ -108,9 +108,9 @@ options_description ConfigurationReader::get_configuration_options() const { options_description options( "Configuration" ); options.add_options() - ( LimitToNotifyCmdStr.c_str(), value()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() ) + ( LimitToNotifyCmdStr.c_str(), value()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() ) ( HostNameCmdStr.c_str(), value< vector >(), HostNameCmdDesc.c_str() ) - ( HostIntervalCmdStr.c_str(), value< vector >(), HostIntervalCmdDesc.c_str() ) + ( HostIntervalCmdStr.c_str(), value< vector >(), HostIntervalCmdDesc.c_str() ) ; return options; @@ -128,13 +128,13 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) if ( vm.count( LimitToNotifyCmdStr ) ) { - size_t limit_to_notify = vm[ LimitToNotifyCmdStr ].as (); + uint limit_to_notify = vm[ LimitToNotifyCmdStr ].as (); Config.set_limit_to_notify( limit_to_notify ); cout << LimitToNotifyCmdStr << "=" << limit_to_notify << endl; } - size_t hosts_names_total = 0; + uint hosts_names_total = 0; if ( vm.count( HostNameCmdStr ) ) { vector hosts_list; @@ -153,14 +153,14 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) hosts_names_total = hosts_names.size(); } - size_t hosts_interval_total = 0; + uint hosts_interval_total = 0; if ( vm.count( HostIntervalCmdStr ) ) { vector hosts_list = Config.get_hosts(); vector::iterator hosts_it = hosts_list.begin(); - vector hosts_intervals = vm[ HostIntervalCmdStr ].as< vector > (); - BOOST_FOREACH( size_t host_interval, hosts_intervals ) + vector hosts_intervals = vm[ HostIntervalCmdStr ].as< vector > (); + BOOST_FOREACH( uint host_interval, hosts_intervals ) { HostItem host_item = *hosts_it; host_item->set_interval( host_interval ); diff --git a/src/config/configurationreader.h b/src/config/configurationreader.h index a50b383..a0e9ee8 100644 --- a/src/config/configurationreader.h +++ b/src/config/configurationreader.h @@ -60,12 +60,12 @@ private: const std::string DefaultConfigFileName; const std::string ConfigFileCmdStr; const std::string ConfigFileCmdDesc; - const std::size_t DefaultLimitToNotify; + const uint DefaultLimitToNotify; const std::string LimitToNotifyCmdStr; const std::string LimitToNotifyCmdDesc; const std::string HostNameCmdStr; const std::string HostNameCmdDesc; - const std::size_t DefaultHostInterval; + const uint DefaultHostInterval; const std::string HostIntervalCmdStr; const std::string HostIntervalCmdDesc; diff --git a/src/ping/boostpinger.cpp b/src/ping/boostpinger.cpp index 79fce87..8e44269 100644 --- a/src/ping/boostpinger.cpp +++ b/src/ping/boostpinger.cpp @@ -36,7 +36,7 @@ BoostPinger::BoostPinger( RepliesCount( 0 ), TimesToPingTotal( 0 ), MinTimesToPing( 0 ), - MaxTimesToPing( numeric_limits::max() ) + MaxTimesToPing( numeric_limits::max() ) { } @@ -46,7 +46,7 @@ BoostPinger::~BoostPinger() void BoostPinger::ping( const string &destination, - const size_t times_to_ping + const uint times_to_ping ) { BOOST_ASSERT( !destination.empty() ); @@ -77,7 +77,7 @@ void BoostPinger::start_send() { IcmpPacket icmp_echo_request_packet = create_echo_request_packet(); - size_t times_already_pinged = SequenceNumber; + uint times_already_pinged = SequenceNumber; if ( times_already_pinged <= TimesToPingTotal ) { send_echo_request( icmp_echo_request_packet ); @@ -117,7 +117,7 @@ void BoostPinger::send_echo_request( const IcmpPacket &icmp_packet ) // Wait up to five seconds for a reply. RepliesCount = 0; - Timer.expires_at( TimeSent + seconds( 5 ) ); + Timer.expires_at( TimeSent + seconds( 5 ) ); // TODO configurable: Timer.async_wait( boost::bind( &BoostPinger::handle_timeout, this ) ); } @@ -143,11 +143,11 @@ void BoostPinger::start_receive() ); } -void BoostPinger::handle_receive( const size_t &length ) +void BoostPinger::handle_receive( const size_t &bytes_transferred ) { // The actual number of bytes received is committed to the buffer so that we // can extract it using a std::istream object. - ReplyBuffer.commit( length ); + ReplyBuffer.commit( bytes_transferred ); // Decode the reply packet. istream is( &ReplyBuffer ); @@ -166,7 +166,7 @@ void BoostPinger::handle_receive( const size_t &length ) ++RepliesCount; // Print out some information about the reply packet. - print_echo_reply( icmp_packet, length ); + print_echo_reply( icmp_packet, bytes_transferred ); } start_receive(); @@ -174,18 +174,18 @@ void BoostPinger::handle_receive( const size_t &length ) void BoostPinger::print_echo_reply( const IcmpPacket &icmp_packet, - const size_t &length + const size_t &bytes_transferred ) { Ipv4Header ipv4_hdr = icmp_packet.get_ip_header(); IcmpHeader icmp_hdr = icmp_packet.get_icmp_header(); - size_t bytes_received = length - ipv4_hdr.get_header_length(); + size_t bytes_received = bytes_transferred - ipv4_hdr.get_header_length(); string source_address = ipv4_hdr.get_source_address().to_string(); - size_t sequence_number = icmp_hdr.get_sequence_number(); - size_t ttl = ipv4_hdr.get_time_to_live(); + uint sequence_number = icmp_hdr.get_sequence_number(); + uint ttl = ipv4_hdr.get_time_to_live(); ptime now = microsec_clock::universal_time(); - size_t time = (now - TimeSent).total_milliseconds(); + uint time = (now - TimeSent).total_milliseconds(); cout << bytes_received << " bytes " << "from " << source_address diff --git a/src/ping/boostpinger.h b/src/ping/boostpinger.h index 635c430..46ac454 100644 --- a/src/ping/boostpinger.h +++ b/src/ping/boostpinger.h @@ -18,7 +18,7 @@ public: void ping( const std::string &destination, - const std::size_t times_to_ping + const uint times_to_ping ); private: @@ -31,10 +31,10 @@ private: void handle_timeout(); void start_receive(); - void handle_receive( const std::size_t &length ); + void handle_receive( const std::size_t &bytes_transferred ); void print_echo_reply( const IcmpPacket &icmp_packet, - const std::size_t &length + const std::size_t &bytes_transferred ); uint16_t get_identifier(); @@ -48,11 +48,11 @@ private: uint16_t SequenceNumber; boost::posix_time::ptime TimeSent; boost::asio::streambuf ReplyBuffer; - std::size_t RepliesCount; - std::size_t TimesToPingTotal; + uint RepliesCount; + uint TimesToPingTotal; - const std::size_t MinTimesToPing; - const std::size_t MaxTimesToPing; + const uint MinTimesToPing; + const uint MaxTimesToPing; }; diff --git a/src/ping/host.cpp b/src/ping/host.cpp index beba7cd..fff6da0 100644 --- a/src/ping/host.cpp +++ b/src/ping/host.cpp @@ -43,14 +43,14 @@ void Host::set_port( const uint16_t port ) this->Port = port; } -std::size_t Host::get_interval() const +uint Host::get_interval() const { return Interval; } -void Host::set_interval( const std::size_t interval ) +void Host::set_interval( const uint interval ) { - BOOST_ASSERT( ( 0 < interval ) && ( interval < std::numeric_limits::max() ) ); + BOOST_ASSERT( ( 0 < interval ) && ( interval < std::numeric_limits::max() ) ); this->Interval = interval; } diff --git a/src/ping/host.h b/src/ping/host.h index 08c1c56..3eb5534 100644 --- a/src/ping/host.h +++ b/src/ping/host.h @@ -22,8 +22,8 @@ public: uint16_t get_port() const; void set_port( const uint16_t port ); - std::size_t get_interval() const; - void set_interval( const std::size_t interval ); + uint get_interval() const; + void set_interval( const uint interval ); std::vector get_options() const; void set_options( const std::vector &options ); @@ -31,7 +31,7 @@ public: private: std::string Address; uint16_t Port; - std::size_t Interval; + uint Interval; std::vector Options; }; diff --git a/src/ping/pingcheck.cpp b/src/ping/pingcheck.cpp index 18013f7..d7b1bd5 100644 --- a/src/ping/pingcheck.cpp +++ b/src/ping/pingcheck.cpp @@ -24,8 +24,8 @@ PingCheck::~PingCheck() void PingCheck::start_pinging() { string destination = Host_.get_address(); - size_t ping_set_total = 3; // TODO configurable: - size_t ping_set_count = 0; + uint ping_set_total = 3; // TODO configurable: + uint ping_set_count = 0; while ( ping_set_count < ping_set_total ) { ping_and_wait( destination ); @@ -51,7 +51,7 @@ void PingCheck::ping_and_wait( const string &destination ) void PingCheck::ping( const string &destination ) throw ( exception& ) { - size_t times_to_ping = 3; // TODO configurable: this must be automatically selected + uint times_to_ping = 3; // TODO configurable: this must be automatically selected boost::asio::io_service io_service; BoostPinger pinger( io_service ); pinger.ping( destination, times_to_ping ); @@ -61,7 +61,7 @@ void PingCheck::wait() { boost::asio::io_service io_service; deadline_timer timer( io_service ); - size_t interval = Host_.get_interval(); // TODO configurable: + uint interval = Host_.get_interval(); // TODO configurable: timer.expires_from_now( boost::posix_time::seconds( interval ) ); timer.wait(); } diff --git a/src/ping/pinger.h b/src/ping/pinger.h index 41a7b8b..5703937 100644 --- a/src/ping/pinger.h +++ b/src/ping/pinger.h @@ -1,6 +1,7 @@ #ifndef PINGER_H #define PINGER_H +#include #include //----------------------------------------------------------------------------- @@ -15,7 +16,7 @@ public: virtual void ping( const std::string &destination, - const std::size_t times_to_ping + const uint times_to_ping ) = 0; };