2018-04-02 00:25:08 +00:00
|
|
|
#pragma once
|
|
|
|
#include "../../util/Serializable.h"
|
|
|
|
#include "../Packet.h"
|
|
|
|
#include "Opcode.h"
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
namespace ki
|
|
|
|
{
|
2018-04-03 16:02:30 +00:00
|
|
|
namespace protocol
|
|
|
|
{
|
|
|
|
namespace control
|
|
|
|
{
|
|
|
|
class Ping final : public util::Serializable
|
2018-04-02 00:25:08 +00:00
|
|
|
{
|
2018-04-03 16:02:30 +00:00
|
|
|
public:
|
|
|
|
Ping(uint16_t session_id = 0,
|
|
|
|
uint16_t milliseconds = 0, uint8_t minutes = 0);
|
|
|
|
virtual ~Ping() = default;
|
2018-04-02 00:25:08 +00:00
|
|
|
|
2018-04-03 16:02:30 +00:00
|
|
|
uint16_t get_session_id() const;
|
|
|
|
void set_session_id(uint16_t session_id);
|
2018-04-02 00:25:08 +00:00
|
|
|
|
2018-04-03 16:02:30 +00:00
|
|
|
uint16_t get_milliseconds() const;
|
|
|
|
void set_milliseconds(uint16_t milliseconds);
|
2018-04-02 00:25:08 +00:00
|
|
|
|
2018-04-03 16:02:30 +00:00
|
|
|
uint8_t get_minutes() const;
|
|
|
|
void set_minutes(uint8_t minutes);
|
2018-04-02 00:25:08 +00:00
|
|
|
|
2018-04-03 16:02:30 +00:00
|
|
|
void write_to(std::ostream &ostream) const override final;
|
|
|
|
void read_from(std::istream &istream) override final;
|
|
|
|
size_t get_size() const override final;
|
2018-04-02 00:25:08 +00:00
|
|
|
|
2018-04-03 16:02:30 +00:00
|
|
|
static Packet *create_packet(uint16_t session_id = 0,
|
|
|
|
uint16_t milliseconds = 0, uint8_t minutes = 0,
|
|
|
|
bool response = false)
|
|
|
|
{
|
|
|
|
Ping data(session_id, milliseconds, minutes);
|
|
|
|
auto *packet = new Packet(true,
|
|
|
|
(uint8_t)(response ? Opcode::PING_RSP : Opcode::PING));
|
|
|
|
packet->set_payload_data(data);
|
|
|
|
return packet;
|
2018-04-02 00:25:08 +00:00
|
|
|
}
|
2018-04-03 16:02:30 +00:00
|
|
|
private:
|
|
|
|
uint16_t m_session_id;
|
|
|
|
uint16_t m_milliseconds;
|
|
|
|
uint8_t m_minutes;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2018-04-02 00:25:08 +00:00
|
|
|
}
|