Added Effective C++ warnings level (-Weffc++)
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Mon, 21 Feb 2011 09:43:54 +0000 (10:43 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Mon, 21 Feb 2011 10:02:13 +0000 (11:02 +0100)
- Detects possible misuses of C++ features

CMakeLists.txt
src/ping/boostpinger.cpp
src/ping/boostpinger.h
src/ping/host.cpp
src/ping/host.h
src/ping/pingcheck.cpp
src/ping/pingcheck.h
src/ping/pingmanager.cpp
src/ping/pingmanager.h

index ea9aa73..2ddab70 100644 (file)
@@ -16,7 +16,9 @@ set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} )
 set( CMAKE_VERBOSE_MAKEFILE OFF )
 
 # add definitions, compiler switches, etc.
-add_definitions( -Werror -Wall -Wextra -O2 )
+add_definitions(
+    -Werror -Wall -Wextra -Weffc++ -O2 -DVERSION_STRING=${VERSION_STRING}
+)
 
 # more build in the source folder
 add_subdirectory( src )
index 9119a89..e4b42cc 100644 (file)
@@ -11,6 +11,8 @@
 #include "ipv4_header.h"
 #include "boostpinger.h"
 
+namespace posix_time = boost::posix_time;
+
 //-----------------------------------------------------------------------------
 // BoostPinger
 //-----------------------------------------------------------------------------
 BoostPinger::BoostPinger(
         boost::asio::io_service& io_service
 ) :
-    resolver( io_service ), timer( io_service ), sequence_number( 0 ),
-    num_replies( 0 ), socket( io_service, icmp::v4() )
+    resolver( io_service ),
+    destination_endpoint(),
+    socket( io_service, icmp::v4() ),
+    timer( io_service ),
+    sequence_number( 0 ),
+    time_sent( posix_time::microsec_clock::universal_time() ),
+    reply_buffer( 0 ),
+    num_replies( 0 )
 {
 #if 0
     try
@@ -42,8 +50,9 @@ BoostPinger::~BoostPinger()
 
 void BoostPinger::ping( const Host &host )
 {
-    std::string destination = host.getIp();
+    std::string destination = host.get_ip();
     // TODO what if it is an DNS?
+    // TODO what about ping multiple hosts?
 
     icmp::resolver::query query( icmp::v4(), destination, "" );
     destination_endpoint = *resolver.resolve( query );
@@ -82,7 +91,7 @@ void BoostPinger::start_send()
 
 void BoostPinger::handle_timeout()
 {
-    if (num_replies == 0)
+    if ( num_replies == 0 )
         std::cout << "Request timed out" << std::endl;
 
     // Requests must be sent no less than one second apart.
@@ -98,7 +107,8 @@ void BoostPinger::start_receive()
     // Wait for a reply. We prepare the buffer to receive up to 64KB.
     socket.async_receive(
             reply_buffer.prepare( 65536 ),
-            boost::bind( &BoostPinger::handle_receive, this, _2 ) );
+            boost::bind( &BoostPinger::handle_receive, this, _2 )
+    );
 }
 
 void BoostPinger::handle_receive( std::size_t length )
@@ -116,12 +126,12 @@ void BoostPinger::handle_receive( std::size_t length )
     // We can receive all ICMP packets received by the host, so we need to
     // filter out only the echo replies that match the our identifier and
     // expected sequence number.
-    if (is && icmp_hdr.type() == IcmpHeader::EchoReply
+    if ( is && icmp_hdr.type() == IcmpHeader::EchoReply
             && icmp_hdr.identifier() == get_identifier()
-            && icmp_hdr.sequence_number() == sequence_number)
+            && icmp_hdr.sequence_number() == sequence_number )
     {
         // If this is the first reply, interrupt the five second timeout.
-        if (num_replies++ == 0)
+        if ( num_replies++ == 0 )
             timer.cancel();
 
         // Print out some information about the reply packet.
@@ -130,8 +140,7 @@ void BoostPinger::handle_receive( std::size_t length )
                 << ipv4_hdr.source_address() << ": icmp_seq="
                 << icmp_hdr.sequence_number() << ", ttl="
                 << ipv4_hdr.time_to_live() << ", time="
-                << (now - time_sent).total_milliseconds() << " ms"
-                << std::endl;
+                << (now - time_sent).total_milliseconds() << " ms" << std::endl;
     }
 
     start_receive();
index a7c9f3f..734ca24 100644 (file)
@@ -9,8 +9,6 @@ using boost::asio::ip::address;
 using boost::asio::ip::icmp;
 using boost::asio::deadline_timer;
 
-namespace posix_time = boost::posix_time;
-
 //-----------------------------------------------------------------------------
 // BoostPinger
 //-----------------------------------------------------------------------------
@@ -32,12 +30,13 @@ private:
 
     static uint16_t get_identifier();
 
+private:
     icmp::resolver resolver;
     icmp::endpoint destination_endpoint;
     icmp::socket socket;
     deadline_timer timer;
     uint16_t sequence_number;
-    posix_time::ptime time_sent;
+    boost::posix_time::ptime time_sent;
     boost::asio::streambuf reply_buffer;
     std::size_t num_replies;
 
index 4ee1c19..1476a9c 100644 (file)
@@ -1,6 +1,11 @@
 #include "host.h"
 
-Host::Host( std::string address )
+Host::Host( std::string address ) :
+    ip( "" ),
+    dns( address ),
+    port( 0 ),
+    interval( 0 ),
+    options()
 {
 }
 
@@ -8,51 +13,51 @@ Host::~Host()
 {
 }
 
-std::string Host::getDns() const
+std::string Host::get_dns() const
 {
     return dns;
 }
 
-void Host::setDns( std::string dns )
+void Host::set_dns( std::string dns )
 {
     this->dns = dns;
 }
 
-uint32_t Host::getInterval() const
+uint32_t Host::get_interval() const
 {
     return interval;
 }
 
-void Host::setInterval( uint32_t interval )
+void Host::set_interval( uint32_t interval )
 {
     this->interval = interval;
 }
 
-std::string Host::getIp() const
+std::string Host::get_ip() const
 {
     return ip;
 }
 
-void Host::setIp( std::string ip )
+void Host::set_ip( std::string ip )
 {
     this->ip = ip;
 }
-std::vector<std::string> Host::getOptions() const
+std::vector<std::string> Host::get_options() const
 {
     return options;
 }
 
-void Host::setOptions( std::vector<std::string> options )
+void Host::set_options( std::vector<std::string> options )
 {
     this->options = options;
 }
 
-uint16_t Host::getPort() const
+uint16_t Host::get_port() const
 {
     return port;
 }
 
-void Host::setPort( uint16_t port )
+void Host::set_port( uint16_t port )
 {
     this->port = port;
 }
index 36b8772..f07aafb 100644 (file)
@@ -12,20 +12,20 @@ public:
     Host( std::string address );
     virtual ~Host();
 
-    std::string getDns() const;
-    void setDns( std::string dns );
+    std::string get_dns() const;
+    void set_dns( std::string dns );
 
-    uint32_t getInterval() const;
-    void setInterval( uint32_t interval );
+    uint32_t get_interval() const;
+    void set_interval( uint32_t interval );
 
-    std::string getIp() const;
-    void setIp( std::string ip );
+    std::string get_ip() const;
+    void set_ip( std::string ip );
 
-    std::vector<std::string> getOptions() const;
-    void setOptions( std::vector<std::string> options );
+    std::vector<std::string> get_options() const;
+    void set_options( std::vector<std::string> options );
 
-    uint16_t getPort() const;
-    void setPort( uint16_t port );
+    uint16_t get_port() const;
+    void set_port( uint16_t port );
 
 private:
     std::string ip;
index 262b3f8..af8288a 100644 (file)
@@ -1,36 +1,27 @@
-#include "configurationreader.h"
-
 #include "pingcheck.h"
 
 PingCheck::PingCheck() :
-    configuration( NULL )
+    configuration( NULL ),
+    ping_managers()
 {
+}
 
+PingCheck::PingCheck( const PingCheck& ) :
+    configuration( NULL ),
+    ping_managers()
+{
 }
 
 PingCheck::~PingCheck()
 {
 }
 
-void PingCheck::read_configuration()
+PingCheck& PingCheck::operator=( const PingCheck& )
 {
-    //  sends the program command line to be parsed by the configuration reader
-    //  check if it reads correctly
-
-    //
-    //
-    //
-    //
-    //
-    //
-    //
-    //
-    //
-    //
-    //
+    return *this;
 }
 
-void PingCheck::init_ping_managers()
+void PingCheck::init_ping_managers() const
 {
     // starts N ping managers with a host and an interval, this was read in configuration
     //  for each host in configuration
index fafb59f..965cfa9 100644 (file)
@@ -10,10 +10,12 @@ class PingCheck
 {
 public:
     PingCheck();
+    PingCheck( const PingCheck& other );
     virtual ~PingCheck();
 
-    void read_configuration();
-    void init_ping_managers();
+    PingCheck& operator=( const PingCheck& other );
+
+    void init_ping_managers() const;
 
 private:
     Configuration *configuration;
index 9ceee4e..680cf06 100644 (file)
@@ -1,14 +1,28 @@
 #include "pingmanager.h"
 
-PingManager::PingManager()
+PingManager::PingManager() :
+    pinger( NULL ),
+    interval( 0 ),
+    host( NULL )
 {
+}
 
+PingManager::PingManager( const PingManager& ) :
+    pinger( NULL ),
+    interval( 0 ),
+    host( NULL )
+{
 }
 
 PingManager::~PingManager()
 {
 }
 
-void PingManager::ping()
+PingManager& PingManager::operator=( const PingManager& )
+{
+    return *this;
+}
+
+void PingManager::ping() const
 {
 }
index de79ce2..8619a41 100644 (file)
@@ -8,9 +8,12 @@ class PingManager
 {
 public:
     PingManager();
+    PingManager( const PingManager& );
     virtual ~PingManager();
 
-    void ping();
+    PingManager& operator=( const PingManager& );
+
+    void ping() const;
 
 private:
     Pinger *pinger;