1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QNETWORKMANAGERSERVICE_H
5#define QNETWORKMANAGERSERVICE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qvariant.h>
19#include <QtCore/qmap.h>
20#include <QtDBus/qdbusabstractinterface.h>
21
22#include <optional>
23
24// Matches 'NMDeviceState' from https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html
25enum NMDeviceState {
26 NM_DEVICE_STATE_UNKNOWN = 0,
27 NM_DEVICE_STATE_UNMANAGED = 10,
28 NM_DEVICE_STATE_UNAVAILABLE = 20,
29 NM_DEVICE_STATE_DISCONNECTED = 30,
30 NM_DEVICE_STATE_PREPARE = 40,
31 NM_DEVICE_STATE_CONFIG = 50,
32 NM_DEVICE_STATE_NEED_AUTH = 60,
33 NM_DEVICE_STATE_IP_CONFIG = 70,
34 NM_DEVICE_STATE_ACTIVATED = 100,
35 NM_DEVICE_STATE_DEACTIVATING = 110,
36 NM_DEVICE_STATE_FAILED = 120
37};
38
39QT_BEGIN_NAMESPACE
40
41class QDBusObjectPath;
42
43// This tiny class exists for the purpose of seeing if NetworkManager is available without
44// initializing everything the derived/full class needs.
45class QNetworkManagerInterfaceBase : public QDBusAbstractInterface
46{
47 Q_OBJECT
48public:
49 QNetworkManagerInterfaceBase(QObject *parent = nullptr);
50 ~QNetworkManagerInterfaceBase() = default;
51
52 static bool networkManagerAvailable();
53
54private:
55 Q_DISABLE_COPY_MOVE(QNetworkManagerInterfaceBase)
56};
57
58class QNetworkManagerInterface final : public QNetworkManagerInterfaceBase
59{
60 Q_OBJECT
61
62public:
63 // Matches 'NMState' from https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html
64 enum NMState {
65 NM_STATE_UNKNOWN = 0,
66 NM_STATE_ASLEEP = 10,
67 NM_STATE_DISCONNECTED = 20,
68 NM_STATE_DISCONNECTING = 30,
69 NM_STATE_CONNECTING = 40,
70 NM_STATE_CONNECTED_LOCAL = 50,
71 NM_STATE_CONNECTED_SITE = 60,
72 NM_STATE_CONNECTED_GLOBAL = 70
73 };
74 Q_ENUM(NMState);
75 // Matches 'NMConnectivityState' from
76 // https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMConnectivityState
77 enum NMConnectivityState {
78 NM_CONNECTIVITY_UNKNOWN = 0,
79 NM_CONNECTIVITY_NONE = 1,
80 NM_CONNECTIVITY_PORTAL = 2,
81 NM_CONNECTIVITY_LIMITED = 3,
82 NM_CONNECTIVITY_FULL = 4,
83 };
84 Q_ENUM(NMConnectivityState);
85 // Matches 'NMDeviceType' from
86 // https://developer-old.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMDeviceType
87 enum NMDeviceType {
88 NM_DEVICE_TYPE_UNKNOWN = 0,
89 NM_DEVICE_TYPE_GENERIC = 14,
90 NM_DEVICE_TYPE_ETHERNET = 1,
91 NM_DEVICE_TYPE_WIFI = 2,
92 NM_DEVICE_TYPE_UNUSED1 = 3,
93 NM_DEVICE_TYPE_UNUSED2 = 4,
94 NM_DEVICE_TYPE_BT = 5,
95 NM_DEVICE_TYPE_OLPC_MESH = 6,
96 NM_DEVICE_TYPE_WIMAX = 7,
97 NM_DEVICE_TYPE_MODEM = 8,
98 NM_DEVICE_TYPE_INFINIBAND = 9,
99 NM_DEVICE_TYPE_BOND = 10,
100 NM_DEVICE_TYPE_VLAN = 11,
101 NM_DEVICE_TYPE_ADSL = 12,
102 NM_DEVICE_TYPE_BRIDGE = 13,
103 NM_DEVICE_TYPE_TEAM = 15,
104 NM_DEVICE_TYPE_TUN = 16,
105 NM_DEVICE_TYPE_IP_TUNNEL = 17,
106 NM_DEVICE_TYPE_MACVLAN = 18,
107 NM_DEVICE_TYPE_VXLAN = 19,
108 NM_DEVICE_TYPE_VETH = 20,
109 NM_DEVICE_TYPE_MACSEC = 21,
110 NM_DEVICE_TYPE_DUMMY = 22,
111 NM_DEVICE_TYPE_PPP = 23,
112 NM_DEVICE_TYPE_OVS_INTERFACE = 24,
113 NM_DEVICE_TYPE_OVS_PORT = 25,
114 NM_DEVICE_TYPE_OVS_BRIDGE = 26,
115 NM_DEVICE_TYPE_WPAN = 27,
116 NM_DEVICE_TYPE_6LOWPAN = 28,
117 NM_DEVICE_TYPE_WIREGUARD = 29,
118 NM_DEVICE_TYPE_WIFI_P2P = 30,
119 NM_DEVICE_TYPE_VRF = 31,
120 };
121 // Matches 'NMMetered' from
122 // https://developer-old.gnome.org/NetworkManager/stable/nm-dbus-types.html#NMMetered
123 enum NMMetered {
124 NM_METERED_UNKNOWN,
125 NM_METERED_YES,
126 NM_METERED_NO,
127 NM_METERED_GUESS_YES,
128 NM_METERED_GUESS_NO,
129 };
130
131 QNetworkManagerInterface(QObject *parent = nullptr);
132 ~QNetworkManagerInterface();
133
134 NMState state() const;
135 NMConnectivityState connectivityState() const;
136 NMDeviceType deviceType() const;
137 NMMetered meteredState() const;
138
139Q_SIGNALS:
140 void stateChanged(NMState);
141 void connectivityChanged(NMConnectivityState);
142 void deviceTypeChanged(NMDeviceType);
143 void meteredChanged(NMMetered);
144
145private Q_SLOTS:
146 void setProperties(const QString &interfaceName, const QMap<QString, QVariant> &map,
147 const QStringList &invalidatedProperties);
148
149private:
150 Q_DISABLE_COPY_MOVE(QNetworkManagerInterface)
151
152 NMDeviceType extractDeviceType(const QDBusObjectPath &devicePath) const;
153 NMMetered extractDeviceMetered(const QDBusObjectPath &devicePath) const;
154
155 std::optional<QDBusObjectPath> primaryConnectionDevicePath() const;
156
157 QVariantMap propertyMap;
158};
159
160class PropertiesDBusInterface : public QDBusAbstractInterface
161{
162public:
163 PropertiesDBusInterface(const QString &service, const QString &path, const QString &interface,
164 const QDBusConnection &connection, QObject *parent = nullptr)
165 : QDBusAbstractInterface(service, path, interface.toLatin1().data(), connection, parent)
166 {
167 }
168};
169
170QT_END_NAMESPACE
171
172#endif
173

source code of qtbase/src/plugins/networkinformation/networkmanager/qnetworkmanagerservice.h