ModemManagerQt

bearer.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Lukas Tinkl <ltinkl@redhat.com>
3 SPDX-FileCopyrightText: 2013-2015 Jan Grulich <jgrulich@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "bearer_p.h"
9#include "mmdebug_p.h"
10#ifdef MMQT_STATIC
11#include "dbus/fakedbus.h"
12#else
13#include "dbus/dbus.h"
14#endif
15
16// logging category for this framework, default: log stuff >= warning
17Q_LOGGING_CATEGORY(MMQT, "kf.modemmanagerqt", QtWarningMsg)
18
19namespace ModemManager
20{
21class ModemManager::IpConfig::Private
22{
23public:
24 Private()
25 {
26 }
27 MMBearerIpMethod method{MM_BEARER_IP_METHOD_UNKNOWN};
28
29 QString address;
30 uint prefix{0};
31 QString dns1;
32 QString dns2;
33 QString dns3;
34 QString gateway;
35};
36
37}
38
40 : d(new Private())
41{
42}
43
45 : d(new Private)
46{
47 *this = other;
48}
49
51{
52 delete d;
53}
54
55MMBearerIpMethod ModemManager::IpConfig::method() const
56{
57 return d->method;
58}
59
60void ModemManager::IpConfig::setMethod(MMBearerIpMethod method)
61{
62 d->method = method;
63}
64
66{
67 return d->address;
68}
69
71{
72 d->address = address;
73}
74
76{
77 return d->prefix;
78}
79
81{
82 d->prefix = prefix;
83}
84
86{
87 return d->dns1;
88}
89
91{
92 d->dns1 = dns1;
93}
94
96{
97 return d->dns2;
98}
99
101{
102 d->dns2 = dns2;
103}
104
106{
107 return d->dns3;
108}
109
111{
112 d->dns3 = dns3;
113}
114
116{
117 return d->gateway;
118}
119
121{
122 d->gateway = gateway;
123}
124
126{
127 if (this == &other) {
128 return *this;
129 }
130
131 *d = *other.d;
132 return *this;
133}
134
135ModemManager::BearerPrivate::BearerPrivate(const QString &path, Bearer *q)
136#ifdef MMQT_STATIC
137 : bearerIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::sessionBus())
138#else
139 : bearerIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::systemBus())
140#endif
141 , uni(path)
142 , q_ptr(q)
143{
144 if (bearerIface.isValid()) {
145 bearerInterface = bearerIface.interface();
146 isConnected = bearerIface.connected();
147 isSuspended = bearerIface.suspended();
148 ipv4Config = ipConfigFromMap(bearerIface.ip4Config());
149 ipv6Config = ipConfigFromMap(bearerIface.ip6Config());
150 ipTimeout = bearerIface.ipTimeout();
151 bearerProperties = bearerIface.properties();
152 }
153}
154
155ModemManager::Bearer::Bearer(const QString &path, QObject *parent)
156 : QObject(parent)
157 , d_ptr(new BearerPrivate(path, this))
158{
159 Q_D(Bearer);
160
161#ifdef MMQT_STATIC
163 path,
164 DBUS_INTERFACE_PROPS,
165 QStringLiteral("PropertiesChanged"),
166 d,
167 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
168#else
170 path,
171 DBUS_INTERFACE_PROPS,
172 QStringLiteral("PropertiesChanged"),
173 d,
174 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
175#endif
176}
177
178ModemManager::Bearer::~Bearer()
179{
180 delete d_ptr;
181}
182
184{
185 Q_D(const Bearer);
186 return d->bearerInterface;
187}
188
190{
191 Q_D(const Bearer);
192 return d->isConnected;
193}
194
196{
197 Q_D(const Bearer);
198 return d->isSuspended;
199}
200
202{
203 Q_D(const Bearer);
204 return d->ipv4Config;
205}
206
208{
209 Q_D(const Bearer);
210 return d->ipv6Config;
211}
212
214{
215 Q_D(const Bearer);
216 return d->ipTimeout;
217}
218
220{
221 Q_D(const Bearer);
222 return d->bearerProperties;
223}
224
226{
227 Q_D(Bearer);
228 return d->bearerIface.Connect();
229}
230
232{
233 Q_D(Bearer);
234 return d->bearerIface.Disconnect();
235}
236
238{
239 Q_D(Bearer);
240 d->bearerIface.setTimeout(timeout);
241}
242
244{
245 Q_D(const Bearer);
246 return d->bearerIface.timeout();
247}
248
249ModemManager::IpConfig ModemManager::BearerPrivate::ipConfigFromMap(const QVariantMap &map)
250{
252 result.setMethod((MMBearerIpMethod)map.value(QStringLiteral("method")).toUInt());
253
254 if (result.method() == MM_BEARER_IP_METHOD_STATIC) {
255 result.setAddress(map.value(QStringLiteral("address")).toString());
256 result.setPrefix(map.value(QStringLiteral("prefix")).toUInt());
257 result.setDns1(map.value(QStringLiteral("dns1")).toString());
258 result.setDns2(map.value(QStringLiteral("dns2")).toString());
259 result.setDns3(map.value(QStringLiteral("dns3")).toString());
260 result.setGateway(map.value(QStringLiteral("gateway")).toString());
261 }
262
263 return result;
264}
265
266void ModemManager::BearerPrivate::onPropertiesChanged(const QString &interface, const QVariantMap &properties, const QStringList &invalidatedProps)
267{
268 Q_Q(Bearer);
269 Q_UNUSED(invalidatedProps);
270 qCDebug(MMQT) << interface << properties.keys();
271
272 if (interface == QLatin1String(MMQT_DBUS_INTERFACE_BEARER)) {
273 QVariantMap::const_iterator it = properties.constFind(QLatin1String(MM_BEARER_PROPERTY_INTERFACE));
274 if (it != properties.constEnd()) {
275 bearerInterface = it->toString();
276 Q_EMIT q->interfaceChanged(bearerInterface);
277 }
278 it = properties.constFind(QLatin1String(MM_BEARER_PROPERTY_CONNECTED));
279 if (it != properties.constEnd()) {
280 isConnected = it->toBool();
281 Q_EMIT q->connectedChanged(isConnected);
282 }
283 it = properties.constFind(QLatin1String(MM_BEARER_PROPERTY_SUSPENDED));
284 if (it != properties.constEnd()) {
285 isSuspended = it->toBool();
286 Q_EMIT q->suspendedChanged(isSuspended);
287 }
288 it = properties.constFind(QLatin1String(MM_BEARER_PROPERTY_IP4CONFIG));
289 if (it != properties.constEnd()) {
290 ipv4Config = ipConfigFromMap(qdbus_cast<QVariantMap>(*it));
291 Q_EMIT q->ip4ConfigChanged(ipv4Config);
292 }
293 it = properties.constFind(QLatin1String(MM_BEARER_PROPERTY_IP6CONFIG));
294 if (it != properties.constEnd()) {
295 ipv6Config = ipConfigFromMap(qdbus_cast<QVariantMap>(*it));
296 Q_EMIT q->ip6ConfigChanged(ipv6Config);
297 }
298 it = properties.constFind(QLatin1String(MM_BEARER_PROPERTY_IPTIMEOUT));
299 if (it != properties.constEnd()) {
300 ipTimeout = it->toUInt();
301 Q_EMIT q->ipTimeoutChanged(ipTimeout);
302 }
303 it = properties.constFind(QLatin1String(MM_BEARER_PROPERTY_PROPERTIES));
304 if (it != properties.constEnd()) {
305 bearerProperties = qdbus_cast<QVariantMap>(*it);
306 Q_EMIT q->propertiesChanged(bearerProperties);
307 }
308 }
309}
310
312{
313 Q_D(const Bearer);
314 return d->uni;
315}
316
317#include "moc_bearer.cpp"
318#include "moc_bearer_p.cpp"
The Bearer class.
Definition bearer.h:131
void setTimeout(int timeout)
Sets the timeout in milliseconds for all async method DBus calls.
Definition bearer.cpp:237
bool isSuspended() const
In some devices, packet data service will be suspended while the device is handling other communicati...
Definition bearer.cpp:195
QString interface() const
Definition bearer.cpp:183
QDBusPendingReply< void > connectBearer()
Requests activation of a packet data connection with the network using this bearer's properties.
Definition bearer.cpp:225
IpConfig ip4Config() const
If the bearer was configured for IPv4 addressing, upon activation this property contains the addressi...
Definition bearer.cpp:201
uint ipTimeout() const
Definition bearer.cpp:213
QVariantMap properties() const
Definition bearer.cpp:219
bool isConnected() const
Definition bearer.cpp:189
QString uni() const
Definition bearer.cpp:311
QDBusPendingReply< void > disconnectBearer()
Disconnect and deactivate this packet data connection.
Definition bearer.cpp:231
IpConfig ip6Config() const
If the bearer was configured for IPv6 addressing, upon activation this property contains the addressi...
Definition bearer.cpp:207
int timeout() const
Returns the current value of the DBus timeout in milliseconds.
Definition bearer.cpp:243
This class represents IP configuration.
Definition bearer.h:28
void setMethod(MMBearerIpMethod method)
Sets the MMBearerIpMethod.
Definition bearer.cpp:60
QString dns3() const
Returns the IP address of the third DNS server.
Definition bearer.cpp:105
IpConfig()
Constructs an empty IP config object.
Definition bearer.cpp:39
void setGateway(const QString &gateway)
Sets the IP address of the default gateway.
Definition bearer.cpp:120
QString dns1() const
Returns the IP address of the first DNS server.
Definition bearer.cpp:85
QString dns2() const
Returns the IP address of the second DNS server.
Definition bearer.cpp:95
void setAddress(const QString &address)
Sets the IP address.
Definition bearer.cpp:70
QString gateway() const
Returns the IP address of the default gateway.
Definition bearer.cpp:115
void setDns3(const QString &dns3)
Sets the IP address of the third DNS server.
Definition bearer.cpp:110
~IpConfig()
Destroys this IpConfig object.
Definition bearer.cpp:50
QString address() const
Returns the IP address.
Definition bearer.cpp:65
MMBearerIpMethod method() const
Returns the MMBearerIpMethod.
Definition bearer.cpp:55
IpConfig & operator=(const IpConfig &other)
Makes a copy of the IpConfig object other.
Definition bearer.cpp:125
void setDns2(const QString &dns2)
Sets the IP address of the second DNS server.
Definition bearer.cpp:100
void setPrefix(uint prefix)
Sets the numeric CIDR network prefix.
Definition bearer.cpp:80
void setDns1(const QString &dns1)
Sets the IP address of the first DNS server.
Definition bearer.cpp:90
uint prefix() const
Returns the numeric CIDR network prefix (ie, 24, 32, etc)
Definition bearer.cpp:75
QString path(const QString &relativePath)
KGuiItem properties()
This namespace allows to query the underlying system to discover the available modem interfaces respo...
Definition bearer.cpp:20
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:49:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.