-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtjsonsocketlib_v3.h
123 lines (83 loc) · 2.53 KB
/
qtjsonsocketlib_v3.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef QTJSONSOCKETLIB_V3_H
#define QTJSONSOCKETLIB_V3_H
#include <QObject>
#include <QTcpSocket>
#include <QMetaMethod>
#include <QSharedPointer>
#include <QDebug>
#include <QByteArray>
#include <QJsonObject>
#include <QJsonDocument>
#include "Dependency/qt_json_socket_lib.h"
namespace QtJsonSocketLib
{
class DebugLog :public QObject
{
Q_OBJECT
public:
static inline void ShowDebug(const QString& str, unsigned int line, QString FunctionName, QString FileName)
{
if(ShowDebugMessage == true)
{
qDebug()<<"[Debug] : " + FileName + " : " + FunctionName + ":" + QString::number(line) + " : " + str;
}
}
static bool ShowDebugMessage;
};
}
#define DEBUGLOG(X) QtJsonSocketLib::DebugLog::ShowDebug( X, __LINE__, __FUNCTION__, __FILE__)
enum QtJsonSocketError
{
None,
Connect,
SendSocketSize,
SendSocketSource,
SendTimeout,
RecvTimeout,
RecvSource,
RecvSize,
DecodeByteArrayToQJsonDocument,
};
class QtJsonSocketLib_v3 : public Qt_Json_Socket_Lib
{
Q_OBJECT
public:
QtJsonSocketLib_v3(QObject *parent = nullptr);
QtJsonSocketLib_v3(bool TimeoutActive, bool EmitEvent = false);
~QtJsonSocketLib_v3();
virtual bool make_QTcpSocket() override;
virtual bool SwapSocket(QTcpSocket* sock);
virtual bool SetSocket(QTcpSocket *sock);
virtual void set_socket(QTcpSocket* sock) override;
virtual QTcpSocket *get_socket() override;
virtual void set_defaulttimeout(int time);
virtual void ShowDebugMessage(bool b);
virtual bool send_QByteArray(QByteArray arr) override;
virtual QByteArray recv_QByteArray() override;
virtual bool send_Json(QJsonObject obj) override;
virtual QJsonObject RecvJson();
virtual QJsonDocument recv_Json() override;
virtual void connect_server(const QString& Ip, qint64 port) override;
virtual bool is_connect() override;
virtual void disconnect_server() override;
virtual void disconnect_socket() override;
virtual void delete_QTcpSocket() override;
virtual QString GetErrorString();
virtual unsigned int ErrorType();
protected:
void ErrorException(const QtJsonSocketError& e);
signals:
void OnRecvEvent();
void OnDisconnectEvent();
public slots:
void OnRecvEventFromSocket();
void OnDisconnectEventFromSocket();
protected:
QSharedPointer<QTcpSocket> Socket;
bool TimeoutActive;
bool EmitEvent;
unsigned int DefaultTimeout;
QtJsonSocketError ErrType;
QString ErrorString;
};
#endif // QTJSONSOCKETLIB_V3_H