-
Notifications
You must be signed in to change notification settings - Fork 0
/
SAF.h
107 lines (93 loc) · 2.11 KB
/
SAF.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
/*
* File: SAF.h
* Author: Saleem Edah-Tally - [email protected]
* License : GPL v2
* Copyright Saleem Edah-Tally - © 2017
*
* Created on 6 mai 2017, 21:50
*/
#ifndef SAF_H
#define SAF_H
#include <iostream>
using namespace std;
#include <gloox/client.h>
#include <gloox/connectionlistener.h>
using namespace gloox;
class Connector;
class SAFConnListener;
/**
* gloox's connection listener.
*/
class SAFConnListener : public ConnectionListener
{
public:
SAFConnListener(Client * client);
virtual ~SAFConnListener();
virtual void onConnect() override;
/**
* Shows significant error messages.
* @param e
*/
virtual void onDisconnect(ConnectionError e) override;
/**
* Mandatory. Always returns true.
* @param info
* @return
*/
virtual bool onTLSConnect(const CertInfo& info) override;
ConnectionError GetLastError()
{
return m_lastError;
}
Client * GetClient() const
{
return m_client;
}
void SetConnector(Connector * connector)
{
m_connector = connector;
}
/**
* A server may disconnect an idle client.
* Prevents the application from being seen as idle.
* @param client
* @param saf
*/
static void WhiteSpacePing(Client * client, SAFConnListener * saf);
private:
typedef map<int, string> mapErrors;
mapErrors ConnErrorMap;
Client * m_client;
Connector * m_connector;
ConnectionError m_lastError;
};
/**
* Tries to connect to the server.
* Tries to reconnect if the server goes down,
* of if the server is not yet up.
* In all other cases where Client::connect fails,
* the application is allowed to exit.
*/
class Connector
{
public:
Connector(SAFConnListener * saf, const uint& retry, const uint& delay);
/**
* Disconnects from server.
*/
virtual ~Connector();
void DoConnect();
/**
* Resets the number of times we have tried to (re)connect.
*/
void ResetCounter()
{
m_count = 0;
}
private:
SAFConnListener * m_saf;
uint m_retry;
uint m_delay;
uint m_count;
};
#endif /* SAF_H */