ensured LogPrefix is used in DNS and PingScheduler; shortened lines; remove vim end...
[pingcheck] / src / host / pingscheduler.cpp
index e2267fd..0f08565 100644 (file)
@@ -51,7 +51,7 @@ using I2n::Logger::GlobalLogger;
  * @brief Parameterized constructor.
  *
  * @param io_serv The one @c io_serv object that controls async processing
- * @param network_interface The name of the network interface originating the pings.
+ * @param network_interface The name of the network interface sending the pings.
  * @param destination_address The remote address to ping.
  * @param destination_port The remote port to ping.
  * @param ping_protocol_list A list of protocols to use.
@@ -84,7 +84,8 @@ PingScheduler::PingScheduler(
     NextPingTimer( *io_serv ),
     TimeSentLastPing( microsec_clock::universal_time() ),
     PingReplyTimeout( ping_reply_timeout ),
-    HostAnalyzer( destination_address, ping_fail_percentage_limit, link_analyzer ),
+    HostAnalyzer( destination_address, ping_fail_percentage_limit,
+                  link_analyzer ),
     Resolver(),
     Ping(),
     WantToPing( false ),
@@ -113,13 +114,13 @@ PingScheduler::~PingScheduler()
 
 void PingScheduler::stop_pinging()
 {
-    // stop pinger, which will probably call ping_done_handler --> re-new NextPingTimer
-    GlobalLogger.debug() << "scheduler: stop pinging" << endl;
+    // stop pinger and resolver
+    GlobalLogger.debug() << LogPrefix << "scheduler: stop pinging";
     Ping->stop_pinging();
     Resolver->cancel_resolve();
 
-    // now cancel the own timer
-    GlobalLogger.debug() << "scheduler: cancel timer" << endl;
+    // now cancel the own timer in case that pinger cancelation called callback
+    GlobalLogger.debug() << LogPrefix << "scheduler: cancel timer";
     NextPingTimer.cancel();
 }
 
@@ -132,9 +133,10 @@ void PingScheduler::stop_pinging()
 void PingScheduler::start_pinging()
 {
     if ( FirstDelay > 0 )
-        GlobalLogger.info() << "Delaying first ping by " << FirstDelay << "s";
+        GlobalLogger.info() << LogPrefix << "Delaying first ping by "
+                                         << FirstDelay << "s";
     else
-        GlobalLogger.info() << "Schedule ping as soon as possible";
+        GlobalLogger.info() << LogPrefix << "Schedule ping as soon as possible";
 
     (void) NextPingTimer.expires_from_now( seconds( FirstDelay ) );
     NextPingTimer.async_wait( bind( &PingScheduler::ping, this,
@@ -150,12 +152,11 @@ void PingScheduler::ping(const boost::system::error_code &error)
     if ( error )
     {   // get here, e.g. by NextPingTimer.cancel in stop_pinging
         if ( error ==  boost::asio::error::operation_aborted )
-            GlobalLogger.error() << "Timer for ping was cancelled! "
-                                 << "Stopping" << endl;
+            GlobalLogger.error() << LogPrefix << "Timer for ping was cancelled!"
+                                 << " --> Stopping";
         else
-            GlobalLogger.error() << "Received error " << error
-                                 << " waiting for ping! Stopping"
-                                 << endl;
+            GlobalLogger.error() << LogPrefix << "Received error " << error
+                                 << " waiting for ping! Stopping";
         return;
     }
 
@@ -169,19 +170,19 @@ void PingScheduler::ping_when_ready()
 {
     if ( !WantToPing )
     {
-        GlobalLogger.info() << "PingScheduler: not pinging (not requested to)";
+        GlobalLogger.info() << LogPrefix << "not pinging (not requested to)";
         return;
     }
     else if ( Resolver && Resolver->is_resolving() )
     {
-        GlobalLogger.info() << "PingScheduler: not pinging (DNS not finished)";
+        GlobalLogger.info() << LogPrefix << "not pinging (DNS not finished)";
         return;
     }
     else if ( !Resolver )
         // should not happen, but check anyway
         GlobalLogger.warning() << LogPrefix << "Have no resolver!";
 
-    GlobalLogger.info() << "PingScheduler: start ping";
+    GlobalLogger.info() << LogPrefix << "start ping";
     WantToPing = false;
 
     // try to get an up-to-date IP
@@ -249,15 +250,15 @@ void PingScheduler::update_ping_interval()
     {
         PingIntervalInSec.speed_up();
 
-        GlobalLogger.debug() << "- Speeding up ping interval to: " << PingIntervalInSec << "s"
-                << endl;
+        GlobalLogger.debug() << LogPrefix << "- Speeding up ping interval to: "
+                             << PingIntervalInSec << "s";
     }
     else
     {
         PingIntervalInSec.back_to_original();
 
-        GlobalLogger.debug() << "- Stick to the original ping interval: " << PingIntervalInSec << "s"
-                << endl;
+        GlobalLogger.debug() << LogPrefix << "- Stick to the original ping "
+                             << "interval: " << PingIntervalInSec << "s";
     }
 }
 
@@ -266,7 +267,8 @@ void PingScheduler::update_ping_elapsed_time()
     ptime now = microsec_clock::universal_time();
     time_resolution_traits_adapted64_impl::int_type elapsed_time_in_sec =
             (now - TimeSentLastPing).total_seconds();
-    GlobalLogger.debug() << "- Time elapsed since last ping: " << elapsed_time_in_sec << "s" << endl;
+    GlobalLogger.debug() << LogPrefix << "- Time elapsed since last ping: "
+                                      << elapsed_time_in_sec << "s";
 
     TimeSentLastPing = microsec_clock::universal_time();
 }
@@ -310,8 +312,9 @@ void PingScheduler::get_next_ping_protocol()
 
 bool PingScheduler::can_change_ping_protocol() const
 {
-    // TODO can_change_ping_protocol() and get_next_ping_protocol() may be implemented in a Algorithm
-    // class that can be exchanged in this class to provide an algorithm neutral class
+    // TODO can_change_ping_protocol() and get_next_ping_protocol() may be
+    // implemented in a Algorithm class that can be exchanged in this class to
+    // provide an algorithm neutral class
     return true;
 }
 
@@ -334,8 +337,8 @@ void PingScheduler::update_dns_resolver( PingProtocol current_protocol )
 {
     if (Resolver && Resolver->is_resolving())
     {
-        GlobalLogger.warning() << "Resolver still seems to be resolving "
-                               << "--> cancel!";
+        GlobalLogger.warning() << LogPrefix
+                          << "Resolver still seems to be resolving --> cancel!";
         Resolver->cancel_resolve();
     }
 
@@ -348,7 +351,7 @@ void PingScheduler::update_dns_resolver( PingProtocol current_protocol )
     if ( Resolver->have_up_to_date_ip() )
     {
         if (!Resolver->is_resolving())
-            GlobalLogger.warning() << "PingScheduler: have up to date IPs but "
+            GlobalLogger.warning() << LogPrefix << "have up to date IPs but "
                 << "resolver seems to be resolving all the same... "
                 << "Start pinging anyway!";
         ping_when_ready();
@@ -366,7 +369,7 @@ void PingScheduler::start_resolving_ping_address()
 void PingScheduler::dns_resolve_callback(const bool was_success,
                                          const int cname_count)
 {
-    GlobalLogger.info() << "PingScheduler: dns resolution finished "
+    GlobalLogger.info() << LogPrefix << "dns resolution finished "
                         << "with success = " << was_success << " "
                         << "and cname_count = " << cname_count;