-
Notifications
You must be signed in to change notification settings - Fork 1
/
packet.h
101 lines (100 loc) · 2.61 KB
/
packet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @file packet.h
* @brief Packet class header
* @author mnxoid
*
* Copyright 2014 by mnxoid,
*
* This software is the confidential and proprietary information
* of mnxoid ("Confidential Information"). You
* shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement
* you entered into with mnxoid.
**/
#ifndef PACKET_H
#define PACKET_H
#include <QByteArray>
#include <QTcpServer>
/**
* @brief Enumeration with types of requests
**/
typedef enum
{
AUTH, //!< Authentication
PIC_SEND, //!< Sending picture
RESP_OK, //!< Good server response
RESP_ERR, //!< Bad server response
INT_ERR, //!< Internal error
EMPTY //!< No request
} RQTYPE;
/**
* @brief A class for Client-Server communication
**/
class Packet : public QTcpServer
{
private:
RQTYPE REQUEST_ID; //!< Request type
int SESSION_ID; //!< Session key
int SIZE; //!< Data size
char* DATA; //!< Raw packet data
public:
/**
* @brief Default Packet constructor
**/
Packet();
/**
* @brief Copy Packet constructor
**/
Packet(Packet& p);
/**
* @brief Full-parameter Packet constructor
* @param [in] REQUEST_ID - Request type
* @param [in] SESSION_ID - Session key
* @param [in] SIZE - Data size
* @param [in] DATA - Raw packet data
**/
Packet(RQTYPE REQUEST_ID, int SESSION_ID, int SIZE, char* DATA);
/**
* @brief Packet destructor
**/
~Packet();
/**
* @brief Raw packet getter
* @return QByteArray - packet (ready to be sent)
**/
QByteArray getBytes();
/**
* @brief Communication function
* @param [in] IP - server IP-address
* @param [in] port - server port
* @return Packet - server response
**/
Packet *send(QString IP,int port);
/**
* @brief Request ID getter
* @return RQTYPE - Request ID
* @see RQTYPE
**/
RQTYPE getRequestID();
/**
* @brief Session ID getter
* @return int - Session ID
**/
int getSessionID();
/**
* @brief Raw data size getter
* @return int - Raw data size
**/
int getDataSize();
/**
* @brief Raw data getter
* @return char* - Raw data
**/
char* rawData();
/**
* @brief Packet validator
* @return bool - result
**/
bool validate();
};
#endif // PACKET_H