-
Notifications
You must be signed in to change notification settings - Fork 21
/
wifiapi.h
124 lines (107 loc) · 3.83 KB
/
wifiapi.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
#ifndef WIFIAPI_H
#define WIFIAPI_H
#include <QObject>
#include <QDebug>
#include <QDir>
#include <QException>
#include <QUuid>
#include <unistd.h>
#include <liboxide.h>
#include "apibase.h"
#include "wlan.h"
#include "network.h"
#include "bss.h"
#define wifiAPI WifiAPI::singleton()
class WifiAPI : public APIBase {
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", OXIDE_WIFI_INTERFACE)
Q_PROPERTY(int state READ state NOTIFY stateChanged)
Q_PROPERTY(QStringList blobs READ blobs)
Q_PROPERTY(QList<QDBusObjectPath> bSSs READ bSSs)
Q_PROPERTY(int link READ link NOTIFY linkChanged)
Q_PROPERTY(int rssi READ rssi NOTIFY rssiChanged)
Q_PROPERTY(QDBusObjectPath network READ network)
Q_PROPERTY(QList<QDBusObjectPath> networks READ getNetworkPaths)
Q_PROPERTY(bool scanning READ scanning NOTIFY scanningChanged)
public:
static WifiAPI* singleton(WifiAPI* self = nullptr);
WifiAPI(QObject* parent);
void shutdown();
void setEnabled(bool enabled);
bool getEnabled();
QList<Wlan*> getWlans();
QList<Interface*> getInterfaces();
enum State { Unknown, Off, Disconnected, Offline, Online};
Q_ENUM(State)
int state();
void setState(int state);
Q_INVOKABLE bool enable();
Q_INVOKABLE void disable();
Q_INVOKABLE QDBusObjectPath addNetwork(QString ssid, QVariantMap properties);
Q_INVOKABLE QList<QDBusObjectPath> getNetwork(QVariantMap properties);
Q_INVOKABLE QList<QDBusObjectPath> getBSS(QVariantMap properties);
Q_INVOKABLE void scan(bool active = false);
Q_INVOKABLE void reconnect();
Q_INVOKABLE void reassosiate();
Q_INVOKABLE void disconnect();
Q_INVOKABLE void flushBSSCache(uint age);
Q_INVOKABLE void addBlob(QString name, QByteArray blob);
Q_INVOKABLE void removeBlob(QString name);
Q_INVOKABLE QByteArray getBlob(QString name, QByteArray blob);
QStringList blobs();
QList<QDBusObjectPath> bSSs();
int link();
int rssi();
QDBusObjectPath network();
QList<QDBusObjectPath> getNetworkPaths();
bool scanning();
// Interface signals
void BSSAdded(Wlan* wlan, const QDBusObjectPath& path, const QVariantMap& properties);
void BSSRemoved(Wlan* wlan, const QDBusObjectPath& path);
void BlobAdded(Wlan* wlan, const QString& name);
void BlobRemoved(Wlan* wlan, const QString& name);
void NetworkAdded(Wlan* wlan, const QDBusObjectPath& path, const QVariantMap& properties);
void NetworkRemoved(Wlan* wlan, const QDBusObjectPath& path);
void NetworkSelected(Wlan* wlan, const QDBusObjectPath& path);
void InterfacePropertiesChanged(Wlan* wlan, const QVariantMap& properties);
void ScanDone(Wlan* wlan, bool success);
// BSS signals
void BSSPropertiesChanged(const QVariantMap& properties);
void stopUpdating();
void resumeUpdating();
signals:
void stateChanged(int);
void linkChanged(int);
void rssiChanged(int);
void networkAdded(QDBusObjectPath);
void networkRemoved(QDBusObjectPath);
void networkConnected(QDBusObjectPath);
void disconnected();
void bssFound(QDBusObjectPath);
void bssRemoved(QDBusObjectPath);
void scanningChanged(bool);
private slots:
// wpa_supplicant signals
void InterfaceAdded(const QDBusObjectPath &path, const QVariantMap &properties);
void InterfaceRemoved(const QDBusObjectPath &path);
void PropertiesChanged(const QVariantMap &properties);
private:
bool m_enabled;
QTimer* timer;
QList<Wlan*> wlans;
QList<Network*> networks;
int m_state;
QDBusObjectPath m_currentNetwork;
int m_link;
int m_rssi;
QList<BSS*> bsss;
bool m_scanning;
Wpa_Supplicant* supplicant;
QList<Interface*> interfaces();
void validateSupplicant();
void loadNetworks();
void update();
State getCurrentState();
QString getPath(QString type, QString id);
};
#endif // WIFIAPI_H