Coding style changes.

This commit is contained in:
hiker 2015-11-05 08:02:17 +11:00
parent 73c59db858
commit c99ad34cb0
2 changed files with 23 additions and 10 deletions

View File

@ -21,23 +21,30 @@
#include "network/stk_host.hpp"
#include "utils/time.hpp"
/** Constructor. Stores the destination address and how often to ping.
* \param ping_dest: Destination of ping request.
* \param delay_between_pings: How often to ping.
*/
PingProtocol::PingProtocol(const TransportAddress& ping_dst,
double delay_between_pings)
: Protocol(PROTOCOL_SILENT)
{
m_ping_dst.copy(ping_dst);
m_delay_between_pings = delay_between_pings;
}
} // PingProtocol
// ----------------------------------------------------------------------------
PingProtocol::~PingProtocol()
{
}
} // ~PingProtocol
// ----------------------------------------------------------------------------
void PingProtocol::setup()
{
m_last_ping_time = 0;
}
} // setup
// ----------------------------------------------------------------------------
void PingProtocol::asynchronousUpdate()
{
if (StkTime::getRealTime() > m_last_ping_time+m_delay_between_pings)
@ -47,4 +54,4 @@ void PingProtocol::asynchronousUpdate()
STKHost::get()->sendRawPacket(&data, 1, m_ping_dst);
Log::info("PingProtocol", "Ping message sent");
}
}
} // asynchronousUpdate

View File

@ -6,8 +6,18 @@
class PingProtocol : public Protocol
{
public:
PingProtocol(const TransportAddress& ping_dst, double delay_between_pings);
private:
/** The destination for the ping request. */
TransportAddress m_ping_dst;
/** How frequently to ping. */
double m_delay_between_pings;
/** Time of last ping. */
double m_last_ping_time;
public:
PingProtocol(const TransportAddress& ping_dst,
double delay_between_pings);
virtual ~PingProtocol();
virtual bool notifyEvent(Event* event) { return true; }
@ -16,10 +26,6 @@ class PingProtocol : public Protocol
virtual void update() {}
virtual void asynchronousUpdate();
protected:
TransportAddress m_ping_dst;
double m_delay_between_pings;
double m_last_ping_time;
};
#endif // PING_PROTOCOL_HPP