/
qconnectionagent.h
182 lines (145 loc) · 5.03 KB
/
qconnectionagent.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd
** Contact: lorn.potter@gmail.com
**
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
****************************************************************************/
#ifndef QCONNECTIONAGENT_H
#define QCONNECTIONAGENT_H
#include <QObject>
#include <QMap>
#include <QStringList>
#include <QVariant>
#include <QDBusMessage>
#include <QDBusObjectPath>
#include <QQueue>
#include <QPair>
#include <QElapsedTimer>
#include <QVector>
class UserAgent;
class SessionAgent;
class ConnAdaptor;
class NetworkManager;
class NetworkService;
class QOfonoConnectionContext;
class NetworkTechnology;
class WakeupWatcher;
class QTimer;
class QConnectionAgent : public QObject
{
Q_OBJECT
public:
~QConnectionAgent();
static QConnectionAgent &instance();
Q_SIGNALS:
void userInputRequested(const QString &servicePath, const QVariantMap &fields);
void userInputCanceled();
void errorReported(const QString &servicePath, const QString &error);
void connectionRequest();
void configurationNeeded(const QString &type);
void connectionState(const QString &state, const QString &type);
void connectNow(const QString &path);
void requestBrowser(const QString &url);
void tetheringFinished(bool);
public Q_SLOTS:
void onUserInputRequested(const QString &servicePath, const QVariantMap &fields);
void onUserInputCanceled();
void onErrorReported(const QString &servicePath, const QString &error);
void onConnectionRequest();
void sendConnectReply(const QString &in0, int in1);
void sendUserReply(const QVariantMap &input);
void connectToType(const QString &type);
void startTethering(const QString &type);
void stopTethering(bool keepPowered = false);
private:
class Service
{
public:
QString path;
NetworkService *service;
bool operator==(const Service &other) const {
return other.path == path;
}
};
class ServiceList : public QVector<Service>
{
public:
int indexOf(const QString &path, int from = 0) const {
Service key;
key.path = path;
return QVector<Service>::indexOf(key, from);
}
bool contains(const QString &path) const {
Service key;
key.path = path;
return QVector<Service>::indexOf(key) >= 0;
}
void remove(const QString &path) {
Service key;
key.path = path;
int pos = QVector<Service>::indexOf(key);
if (pos >= 0)
QVector<Service>::remove(pos);
}
};
explicit QConnectionAgent(QObject *parent = 0);
static QConnectionAgent *self;
ConnAdaptor *connectionAdaptor;
UserAgent *ua;
NetworkManager *netman;
SessionAgent *sessionAgent;
QString currentNetworkState;
ServiceList orderedServicesList;
QStringList techPreferenceList;
bool isEthernet;
bool connmanAvailable;
bool isStateOnline(const QString &state);
QOfonoConnectionContext *oContext;
NetworkTechnology *tetheringWifiTech;
bool tetheringEnabled;
bool flightModeSuppression;
WakeupWatcher *mceWatch;
uint scanTimeoutInterval;
QTimer *scanTimer;
QStringList knownTechnologies;
bool isBestService(NetworkService *service);
QString findBestConnectableService();
void removeAllTypes(const QString &type);
bool tetheringStarted;
bool delayedTethering;
private slots:
void onScanFinished();
void updateServices();
void serviceErrorChanged(const QString &error);
void serviceStateChanged(const QString &state);
void networkStateChanged(const QString &state);
void connmanAvailabilityChanged(bool b);
void setup();
void servicesError(const QString &);
void ofonoServicesError(const QString &);
void technologyPowerChanged(bool);
void browserRequest(const QString &servicePath, const QString &url);
void techChanged();
void serviceAdded(const QString &);
void servicesListChanged(const QStringList &);
void offlineModeChanged(bool);
void flightModeDialogSuppressionTimeout();
void displayStateChanged(const QString &);
// void sleepStateChanged(bool);
void serviceAutoconnectChanged(bool);
void scanTimeout();
void techTetheringChanged(bool b);
void servicesChanged();
void openConnectionDialog(const QString &type);
void setWifiTetheringEnabled();
};
#endif // QCONNECTIONAGENT_H