-#include "ping/pinganalyzer.h"
+#include "ping/hoststatusanalyzer.h"
#include <iostream>
using namespace boost;
//-----------------------------------------------------------------------------
-// PingAnalyzer
+// HostStatusAnalyzer
//-----------------------------------------------------------------------------
-PingAnalyzer::PingAnalyzer(
+/**
+ * @param host_address the address of the host it has to analyze.
+ * @param ping_fail_percentage_limit the percentage threshold of pings that can
+ * fail.
+ * @param notifier the object used to notify the status of the host.
+ */
+HostStatusAnalyzer::HostStatusAnalyzer(
const string &host_address,
const int ping_fail_percentage_limit,
shared_ptr<StatusNotifier> notifier
BOOST_ASSERT( ( 0 <= PingFailPercentageLimit ) && ( PingFailPercentageLimit <= 100 ) );
}
-PingAnalyzer::~PingAnalyzer()
+HostStatusAnalyzer::~HostStatusAnalyzer()
{
}
-void PingAnalyzer::set_resolved_ip_count( const int resolved_ip_count )
+/**
+ * @param resolved_ip_count the number of IPs resolved for the host.
+ */
+void HostStatusAnalyzer::set_resolved_ip_count( const int resolved_ip_count )
{
BOOST_ASSERT( 1 <= resolved_ip_count );
ResolvedIpCount = resolved_ip_count;
}
-bool PingAnalyzer::exceeded_ping_failed_limit() const
+/**
+ * @return true if the amount of failed pings given to the host exceeded the
+ * limit.
+ */
+bool HostStatusAnalyzer::exceeded_ping_failed_limit() const
{
return ExceededPingFailedLimit;
}
-void PingAnalyzer::update_ping_statistics( bool ping_success )
+/**
+ * Adds a ping status (success or failure).
+ * @param ping_success
+ */
+void HostStatusAnalyzer::update_ping_statistics( bool ping_success )
{
BOOST_ASSERT( 1 <= ResolvedIpCount );
BOOST_ASSERT( 0 <= PingsPerformedCount );
BOOST_ASSERT( PingsFailedCount <= PingsPerformedCount );
}
-bool PingAnalyzer::tried_all_resolved_ip() const
+bool HostStatusAnalyzer::tried_all_resolved_ip() const
{
BOOST_ASSERT( ( 0 <= PingsPerformedCount ) && ( PingsPerformedCount <= ResolvedIpCount ) );
return ( PingsPerformedCount == ResolvedIpCount );
}
-void PingAnalyzer::analyze_ping_statistics()
+void HostStatusAnalyzer::analyze_ping_statistics()
{
BOOST_ASSERT( !HostAddress.empty() );
BOOST_ASSERT( PingsPerformedCount == ResolvedIpCount );
}
-void PingAnalyzer::reset_ping_counters()
+void HostStatusAnalyzer::reset_ping_counters()
{
PingsPerformedCount = 0;
PingsFailedCount = 0;
}
-void PingAnalyzer::increase_ping_performed_count()
+void HostStatusAnalyzer::increase_ping_performed_count()
{
++PingsPerformedCount;
BOOST_ASSERT( ( 0 <= PingsPerformedCount ) && ( PingsPerformedCount <= ResolvedIpCount ) );
}
-void PingAnalyzer::increase_ping_failed_count()
+void HostStatusAnalyzer::increase_ping_failed_count()
{
++PingsFailedCount;
BOOST_ASSERT( ( 0 <= PingsFailedCount ) && ( PingsFailedCount <= PingsPerformedCount ) );
}
-void PingAnalyzer::analyze_ping_failed_count()
+void HostStatusAnalyzer::analyze_ping_failed_count()
{
BOOST_ASSERT( ( 0 <= PingFailPercentageLimit ) && ( PingFailPercentageLimit <= 100 ) );
BOOST_ASSERT( ( 0 <= PingsFailedCount ) && ( PingsFailedCount <= PingsPerformedCount ) );
-#ifndef PINGANALYZER_H
-#define PINGANALYZER_H
+#ifndef HOSTSTATUSANALYZER_H
+#define HOSTSTATUSANALYZER_H
#include <string>
class StatusNotifier;
//-----------------------------------------------------------------------------
-// PingAnalyzer
+// HostStatusAnalyzer
//-----------------------------------------------------------------------------
/**
- * @brief This class analyze the ping status (success or failure) and decides
- * what to do.
+ * @brief This class analyze the host status (up or down) based on the pings
+ * responses (success or failure). And notifies its status.
* Scope: one object per host.
*/
-class PingAnalyzer
+class HostStatusAnalyzer
{
public:
- PingAnalyzer(
+ HostStatusAnalyzer(
const std::string &host_address,
const int ping_fail_percentage_limit,
boost::shared_ptr<StatusNotifier> notifier
);
- virtual ~PingAnalyzer();
+ virtual ~HostStatusAnalyzer();
void set_resolved_ip_count( const int resolved_ip_count );
bool exceeded_ping_failed_limit() const;
};
-#endif /* PINGANALYZER_H */
+#endif /* HOSTSTATUSANALYZER_H */