1/*
2 SPDX-FileCopyrightText: 2019 Jan Grulich <jgrulich@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "wireguarddevice.h"
8#include "manager_p.h"
9#include "wireguarddevice_p.h"
10
11NetworkManager::WireGuardDevicePrivate::WireGuardDevicePrivate(const QString &path, WireGuardDevice *q)
12 : DevicePrivate(path, q)
13#ifdef NMQT_STATIC
14 , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus())
15#else
16 , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus())
17#endif
18 , listenPort(0)
19 , fwMark(0)
20{
21}
22
23NetworkManager::WireGuardDevicePrivate::~WireGuardDevicePrivate()
24{
25}
26
27NetworkManager::WireGuardDevice::WireGuardDevice(const QString &path, QObject *parent)
28 : Device(*new WireGuardDevicePrivate(path, this), parent)
29{
30 Q_D(WireGuardDevice);
31
32 QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(interfaceName: d->iface.staticInterfaceName(), path);
33 if (!initialProperties.isEmpty()) {
34 d->propertiesChanged(properties: initialProperties);
35 }
36}
37
38NetworkManager::WireGuardDevice::~WireGuardDevice()
39{
40}
41
42NetworkManager::Device::Type NetworkManager::WireGuardDevice::type() const
43{
44 return NetworkManager::Device::WireGuard;
45}
46
47QByteArray NetworkManager::WireGuardDevice::publicKey() const
48{
49 Q_D(const WireGuardDevice);
50
51 return d->publicKey;
52}
53
54uint NetworkManager::WireGuardDevice::listenPort() const
55{
56 Q_D(const WireGuardDevice);
57
58 return d->listenPort;
59}
60
61uint NetworkManager::WireGuardDevice::fwMark() const
62{
63 Q_D(const WireGuardDevice);
64
65 return d->fwMark;
66}
67
68void NetworkManager::WireGuardDevicePrivate::propertyChanged(const QString &property, const QVariant &value)
69{
70 Q_Q(WireGuardDevice);
71
72 if (property == QLatin1String("PublicKey")) {
73 publicKey = value.toByteArray();
74 Q_EMIT q->publicKeyChanged(publicKey);
75 } else if (property == QLatin1String("ListenPort")) {
76 listenPort = value.toUInt();
77 Q_EMIT q->listenPortChanged(listenPort);
78 } else if (property == QLatin1String("FwMark")) {
79 fwMark = value.toUInt();
80 Q_EMIT q->fwMarkChanged(fwMark);
81 } else {
82 DevicePrivate::propertyChanged(property, value);
83 }
84}
85
86#include "moc_wireguarddevice.cpp"
87

source code of networkmanager-qt/src/wireguarddevice.cpp