-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgimmmconnection.h
68 lines (60 loc) · 2.33 KB
/
gimmmconnection.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
#ifndef GIMMMCONNECTION_H
#define GIMMMCONNECTION_H
#include "exponentialbackoff.h"
#include <memory>
#include <QObject>
#include <QtNetwork/QTcpSocket>
#include <QEvent>
#include <QThread>
#include <QJsonDocument>
#include <QDataStream>
#include <QtNetwork/QHostAddress>
class GimmmConnection: public QObject
{
Q_OBJECT
QTcpSocket __socket;
QDataStream __in;
QHostAddress __address;
quint16 __port;
std::string __sessionId;
int __connectAttempt;
ExponentialBackoff __exBackOff;
int __maxRetry;
public:
GimmmConnection(int max_retry = 6);
virtual ~GimmmConnection();
void connectToServer(const QHostAddress& hostadd,
quint16 portno,
const std::string& session_id);
//getter/setters
public slots:
void handleConnected();
void handleDisconnected();
void handleReadyRead();
void handleSendMessage(const QJsonDocument& upstream_msg);
signals:
void connectionStarted(int attemptno, int waittime);
void connectionEstablished();
void connectionShutdownStarted();
void connectionShutdownCompleted();
void connectionError(int errorno, QString error);
void connectionLost();
void sessionEstablished();
void connectionHandshakeStarted();
void maxConnectionAttemptReached(int max_attempt);
void newUpstreamMessage(const QJsonDocument& upstream_msg);
void newDownstreamAckMessage(const QJsonDocument& orig_msg);
void newDownstreamReceiptMessage(const QJsonDocument& orig_msg);
void newDownstreamRejectMessage(const QJsonDocument& orig_msg);
private:
void handleNewMessage(const QJsonDocument& jdoc);
void handleLogonResponseMessage(const QJsonDocument& jdoc);
void handleUpstreamMessage(const QJsonDocument& jdoc);
void handleDownstreamAckMessage(const QJsonDocument& jdoc);
void handleDownstreamRejectMessage(const QJsonDocument& jdoc);
void tryConnect();
void retryConnectWithBackoff();
void handleError(QAbstractSocket::SocketError error);
void sendMessage(const QJsonDocument& upstream_msg);
};
#endif // GIMMMCONNECTION_H