Changed integer types from std::size_t to uint, where it is required ordinary numbers
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Mon, 7 Mar 2011 09:17:18 +0000 (10:17 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Mon, 7 Mar 2011 09:17:18 +0000 (10:17 +0100)
src/config/configuration.cpp
src/config/configuration.h
src/config/configurationreader.cpp
src/config/configurationreader.h
src/ping/boostpinger.cpp
src/ping/boostpinger.h
src/ping/host.cpp
src/ping/host.h
src/ping/pingcheck.cpp
src/ping/pinger.h

index 654a384..f9a97fa 100644 (file)
@@ -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) );
 
index 229e747..4aba3cc 100644 (file)
@@ -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<HostItem> get_hosts() const;
     void set_hosts( const std::vector<HostItem> &hosts_list );
 
 private:
     std::string ConfigFileName;
-    std::size_t LimitToNotify;
+    uint LimitToNotify;
     std::vector<HostItem> Hosts;
 
-    const std::size_t MinLimitToNotify;
-    const std::size_t MaxLimitToNotify;
+    const uint MinLimitToNotify;
+    const uint MaxLimitToNotify;
 
 };
 
index a60481a..31a2529 100644 (file)
@@ -108,9 +108,9 @@ options_description ConfigurationReader::get_configuration_options() const
 {
     options_description options( "Configuration" );
     options.add_options()
-        ( LimitToNotifyCmdStr.c_str(), value<size_t>()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() )
+        ( LimitToNotifyCmdStr.c_str(), value<uint>()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() )
         ( HostNameCmdStr.c_str(), value< vector<string> >(), HostNameCmdDesc.c_str() )
-        ( HostIntervalCmdStr.c_str(), value< vector<size_t> >(), HostIntervalCmdDesc.c_str() )
+        ( HostIntervalCmdStr.c_str(), value< vector<uint> >(), 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<size_t> ();
+        uint limit_to_notify = vm[ LimitToNotifyCmdStr ].as<uint> ();
         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<HostItem> 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<HostItem> hosts_list = Config.get_hosts();
         vector<HostItem>::iterator hosts_it = hosts_list.begin();
 
-        vector<size_t> hosts_intervals = vm[ HostIntervalCmdStr ].as< vector<size_t> > ();
-        BOOST_FOREACH( size_t host_interval, hosts_intervals )
+        vector<uint> hosts_intervals = vm[ HostIntervalCmdStr ].as< vector<uint> > ();
+        BOOST_FOREACH( uint host_interval, hosts_intervals )
         {
             HostItem host_item = *hosts_it;
             host_item->set_interval( host_interval );
index a50b383..a0e9ee8 100644 (file)
@@ -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;
 
index 79fce87..8e44269 100644 (file)
@@ -36,7 +36,7 @@ BoostPinger::BoostPinger(
     RepliesCount( 0 ),
     TimesToPingTotal( 0 ),
     MinTimesToPing( 0 ),
-    MaxTimesToPing( numeric_limits<size_t>::max() )
+    MaxTimesToPing( numeric_limits<uint>::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
index 635c430..46ac454 100644 (file)
@@ -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;
 
 };
 
index beba7cd..fff6da0 100644 (file)
@@ -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<std::size_t>::max() ) );
+    BOOST_ASSERT( ( 0 < interval ) && ( interval < std::numeric_limits<uint>::max() ) );
 
     this->Interval = interval;
 }
index 08c1c56..3eb5534 100644 (file)
@@ -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<std::string> get_options() const;
     void set_options( const std::vector<std::string> &options );
@@ -31,7 +31,7 @@ public:
 private:
     std::string Address;
     uint16_t Port;
-    std::size_t Interval;
+    uint Interval;
     std::vector<std::string> Options;
 
 };
index 18013f7..d7b1bd5 100644 (file)
@@ -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();
 }
index 41a7b8b..5703937 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef PINGER_H
 #define PINGER_H
 
+#include <sys/types.h>
 #include <string>
 
 //-----------------------------------------------------------------------------
@@ -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;
 
 };