blob: 2e4deacc556c78b248cd1fe581935a29e9a88521 (
plain)
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
|
#ifndef UPDATED_CONFIG_H
#define UPDATED_CONFIG_H
#include <QObject>
#include "Config.h"
#include "SslClient.h"
class QTimer;
/**
* @brief singleton class that can update it's configuration<br/>
* -# ServerEntry is read from servers list
* -# Trying to connect every Config::ServerEntry::retryTimeout
* -# When total time for all retries exceeds Config::ServerEntry::timeout go to the next ServerEntry
*/
class UpdatedConfig: public QObject, public Config
{
Q_OBJECT
public:
/**
* @brief Retrieve application-wide instance of Config class
* @return Pointer to singleton instance of Config class
*/
static UpdatedConfig *CurrentConfig();
/**
* @brief Get valid server address to communicate with
* @return address of server to communicate with ot empty string
*/
string GetServerAddr();
signals:
/**
* @brief Signal is emitted when client configuration is updated
*/
void updated();
private:
/**
* @brief creates an instance and tries to connect to servers from config.cfg<br/>
* one by one until working server is found or no other ServerEntry records left
*/
UpdatedConfig();
/**
* @brief Pointer to the singleton Config instance
*/
static UpdatedConfig *self;
/**
* @brief SslClient instance that connects to server and retrieves config
*/
SslClient *client;
/**
* @brief timer that is responsible on config updates and reconnection retries
*/
QTimer *configUpdateTimer;
/**
* @brief bool value that is true if config is actual and was updated recently<br/>
* and false if it isn't actual and has to be updated
*/
bool configValid;
/**
* @brief Count time between subsequent request retries
*/
unsigned time;
/**
* @brief index of Config::servers that is currently being tried to connect or being worked with
*/
unsigned activeSrvIndex;
/**
* @brief value indicating whether last connetion attempt failed or not
*/
bool retryFailed;
/**
* @brief value indicating which config parts are already updated<br/>
* to check if some part is updated just apply & to this<br/>
* value and any of SslClient::RequestType values
*/
unsigned char updateStatus;
private slots:
void update();
void connectionError();
void gotServerReply(SslClient::RequestType &type, QByteArray &confdata);
};
#endif
|