1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include <QObject>
41#include <QList>
42#include <QtDBus/QtDBus>
43#include <QtDBus/QDBusConnection>
44#include <QtDBus/QDBusError>
45#include <QtDBus/QDBusInterface>
46#include <QtDBus/QDBusMessage>
47#include <QtDBus/QDBusReply>
48#include <QtDBus/QDBusPendingCallWatcher>
49#include <QtDBus/QDBusObjectPath>
50#include <QtDBus/QDBusPendingCall>
51
52#include "qofonoservice_linux_p.h"
53
54#ifndef QT_NO_DBUS
55
56QDBusArgument &operator<<(QDBusArgument &argument, const ObjectPathProperties &item)
57{
58 argument.beginStructure();
59 argument << item.path << item.properties;
60 argument.endStructure();
61 return argument;
62}
63
64const QDBusArgument &operator>>(const QDBusArgument &argument, ObjectPathProperties &item)
65{
66 argument.beginStructure();
67 argument >> item.path >> item.properties;
68 argument.endStructure();
69 return argument;
70}
71
72QT_BEGIN_NAMESPACE
73
74QOfonoManagerInterface::QOfonoManagerInterface( QObject *parent)
75 : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
76 QLatin1String(OFONO_MANAGER_PATH),
77 OFONO_MANAGER_INTERFACE,
78 QDBusConnection::systemBus(), parent)
79{
80 qDBusRegisterMetaType<ObjectPathProperties>();
81 qDBusRegisterMetaType<PathPropertiesList>();
82
83 QDBusConnection::systemBus().connect(service: QLatin1String(OFONO_SERVICE),
84 path: QLatin1String(OFONO_MANAGER_PATH),
85 interface: QLatin1String(OFONO_MANAGER_INTERFACE),
86 name: QLatin1String("ModemAdded"),
87 receiver: this,SLOT(modemAdded(QDBusObjectPath,QVariantMap)));
88 QDBusConnection::systemBus().connect(service: QLatin1String(OFONO_SERVICE),
89 path: QLatin1String(OFONO_MANAGER_PATH),
90 interface: QLatin1String(OFONO_MANAGER_INTERFACE),
91 name: QLatin1String("ModemRemoved"),
92 receiver: this,SLOT(modemRemoved(QDBusObjectPath)));
93}
94
95QOfonoManagerInterface::~QOfonoManagerInterface()
96{
97}
98
99QStringList QOfonoManagerInterface::getModems()
100{
101 if (modemList.isEmpty()) {
102 QDBusPendingReply<PathPropertiesList> reply = call(mode: QDBus::Block, method: QLatin1String("GetModems"));
103 reply.waitForFinished();
104 if (!reply.isError()) {
105 const auto modems = reply.value();
106 for (const ObjectPathProperties &modem : modems)
107 modemList << modem.path.path();
108 }
109 }
110
111 return modemList;
112}
113
114QString QOfonoManagerInterface::currentModem()
115{
116 const QStringList modems = getModems();
117 for (const QString &modem : modems) {
118 QOfonoModemInterface device(modem);
119 if (device.isPowered() && device.isOnline()
120 && device.interfaces().contains(str: QLatin1String("org.ofono.NetworkRegistration")))
121 return modem;
122 }
123 return QString();
124}
125
126void QOfonoManagerInterface::modemAdded(const QDBusObjectPath &path, const QVariantMap &/*var*/)
127{
128 if (!modemList.contains(str: path.path())) {
129 modemList << path.path();
130 Q_EMIT modemChanged();
131 }
132}
133
134void QOfonoManagerInterface::modemRemoved(const QDBusObjectPath &path)
135{
136 if (modemList.contains(str: path.path())) {
137 modemList.removeOne(t: path.path());
138 Q_EMIT modemChanged();
139 }
140}
141
142
143QOfonoModemInterface::QOfonoModemInterface(const QString &dbusPathName, QObject *parent)
144 : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
145 dbusPathName,
146 OFONO_MODEM_INTERFACE,
147 QDBusConnection::systemBus(), parent)
148{
149 QDBusConnection::systemBus().connect(service: QLatin1String(OFONO_SERVICE),
150 path: path(),
151 OFONO_MODEM_INTERFACE,
152 name: QLatin1String("PropertyChanged"),
153 receiver: this,SLOT(propertyChanged(QString,QDBusVariant)));
154}
155
156QOfonoModemInterface::~QOfonoModemInterface()
157{
158}
159
160void QOfonoModemInterface::propertyChanged(const QString &name,const QDBusVariant &value)
161{
162 propertiesMap[name] = value.variant();
163}
164
165bool QOfonoModemInterface::isPowered()
166{
167 QVariant var = getProperty(QStringLiteral("Powered"));
168 return qdbus_cast<bool>(v: var);
169}
170
171bool QOfonoModemInterface::isOnline()
172{
173 QVariant var = getProperty(QStringLiteral("Online"));
174 return qdbus_cast<bool>(v: var);
175}
176
177QStringList QOfonoModemInterface::interfaces()
178{
179 const QVariant var = getProperty(QStringLiteral("Interfaces"));
180 return var.toStringList();
181}
182
183QVariantMap QOfonoModemInterface::getProperties()
184{
185 if (propertiesMap.isEmpty()) {
186 QDBusPendingReply<QVariantMap> reply = call(mode: QDBus::Block, method: QLatin1String("GetProperties"));
187 if (!reply.isError()) {
188 propertiesMap = reply.value();
189 }
190 }
191 return propertiesMap;
192}
193
194QVariant QOfonoModemInterface::getProperty(const QString &property)
195{
196 QVariant var;
197 QVariantMap map = getProperties();
198 if (map.contains(akey: property))
199 var = map.value(akey: property);
200 return var;
201}
202
203
204QOfonoNetworkRegistrationInterface::QOfonoNetworkRegistrationInterface(const QString &dbusPathName, QObject *parent)
205 : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
206 dbusPathName,
207 OFONO_NETWORK_REGISTRATION_INTERFACE,
208 QDBusConnection::systemBus(), parent)
209{
210}
211
212QOfonoNetworkRegistrationInterface::~QOfonoNetworkRegistrationInterface()
213{
214}
215
216QString QOfonoNetworkRegistrationInterface::getTechnology()
217{
218 QVariant var = getProperty(QStringLiteral("Technology"));
219 return qdbus_cast<QString>(v: var);
220}
221
222QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property)
223{
224 QVariant var;
225 QVariantMap map = getProperties();
226 if (map.contains(akey: property))
227 var = map.value(akey: property);
228 return var;
229}
230
231QVariantMap QOfonoNetworkRegistrationInterface::getProperties()
232{
233 if (propertiesMap.isEmpty()) {
234 QDBusPendingReply<QVariantMap> reply = call(mode: QDBus::Block, method: QLatin1String("GetProperties"));
235 reply.waitForFinished();
236 if (!reply.isError()) {
237 propertiesMap = reply.value();
238 }
239 }
240 return propertiesMap;
241}
242
243QOfonoDataConnectionManagerInterface::QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent)
244 : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
245 dbusPathName,
246 OFONO_DATA_CONNECTION_MANAGER_INTERFACE,
247 QDBusConnection::systemBus(), parent)
248{
249 QDBusConnection::systemBus().connect(service: QLatin1String(OFONO_SERVICE),
250 path: path(),
251 interface: QLatin1String(OFONO_MODEM_INTERFACE),
252 name: QLatin1String("PropertyChanged"),
253 receiver: this,SLOT(propertyChanged(QString,QDBusVariant)));
254}
255
256QOfonoDataConnectionManagerInterface::~QOfonoDataConnectionManagerInterface()
257{
258}
259
260QStringList QOfonoDataConnectionManagerInterface::contexts()
261{
262 if (contextList.isEmpty()) {
263 QDBusPendingReply<PathPropertiesList > reply = call(method: QLatin1String("GetContexts"));
264 reply.waitForFinished();
265 if (!reply.isError()) {
266 const auto contexts = reply.value();
267 for (const ObjectPathProperties &context : contexts)
268 contextList << context.path.path();
269 }
270 }
271 return contextList;
272}
273
274PathPropertiesList QOfonoDataConnectionManagerInterface::contextsWithProperties()
275{
276 if (contextListProperties.isEmpty()) {
277 QDBusPendingReply<PathPropertiesList > reply = call(method: QLatin1String("GetContexts"));
278 reply.waitForFinished();
279 if (!reply.isError()) {
280 contextListProperties = reply.value();
281 }
282 }
283 return contextListProperties;
284}
285
286bool QOfonoDataConnectionManagerInterface::roamingAllowed()
287{
288 QVariant var = getProperty(QStringLiteral("RoamingAllowed"));
289 return qdbus_cast<bool>(v: var);
290}
291
292QString QOfonoDataConnectionManagerInterface::bearer()
293{
294 QVariant var = getProperty(QStringLiteral("Bearer"));
295 return qdbus_cast<QString>(v: var);
296}
297
298QVariant QOfonoDataConnectionManagerInterface::getProperty(const QString &property)
299{
300 return getProperties().value(akey: property);
301}
302
303QVariantMap &QOfonoDataConnectionManagerInterface::getProperties()
304{
305 if (propertiesMap.isEmpty()) {
306 QDBusPendingReply<QVariantMap> reply = call(mode: QDBus::Block, method: QLatin1String("GetProperties"));
307 if (!reply.isError()) {
308 propertiesMap = reply.value();
309 }
310 }
311 return propertiesMap;
312}
313
314void QOfonoDataConnectionManagerInterface::propertyChanged(const QString &name, const QDBusVariant &value)
315{
316 propertiesMap[name] = value.variant();
317 if (name == QLatin1String("RoamingAllowed"))
318 Q_EMIT roamingAllowedChanged(value.variant().toBool());
319}
320
321
322QOfonoConnectionContextInterface::QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent)
323 : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),
324 dbusPathName,
325 OFONO_CONNECTION_CONTEXT_INTERFACE,
326 QDBusConnection::systemBus(), parent)
327{
328 QDBusConnection::systemBus().connect(service: QLatin1String(OFONO_SERVICE),
329 path: path(),
330 interface: QLatin1String(OFONO_MODEM_INTERFACE),
331 name: QLatin1String("PropertyChanged"),
332 receiver: this,SLOT(propertyChanged(QString,QDBusVariant)));
333}
334
335QOfonoConnectionContextInterface::~QOfonoConnectionContextInterface()
336{
337}
338
339QVariantMap QOfonoConnectionContextInterface::getProperties()
340{
341 if (propertiesMap.isEmpty()) {
342 QDBusPendingReply<QVariantMap> reply = call(mode: QDBus::Block, method: QLatin1String("GetProperties"));
343 if (!reply.isError()) {
344 propertiesMap = reply.value();
345 }
346 }
347 return propertiesMap;
348}
349
350void QOfonoConnectionContextInterface::propertyChanged(const QString &name, const QDBusVariant &value)
351{
352 propertiesMap[name] = value.variant();
353}
354
355QVariant QOfonoConnectionContextInterface::getProperty(const QString &property)
356{
357 QVariant var;
358 QVariantMap map = getProperties();
359 if (map.contains(akey: property))
360 var = map.value(akey: property);
361 return var;
362}
363
364bool QOfonoConnectionContextInterface::active()
365{
366 QVariant var = getProperty(QStringLiteral("Active"));
367 return qdbus_cast<bool>(v: var);
368}
369
370QString QOfonoConnectionContextInterface::accessPointName()
371{
372 QVariant var = getProperty(QStringLiteral("AccessPointName"));
373 return qdbus_cast<QString>(v: var);
374}
375
376QString QOfonoConnectionContextInterface::name()
377{
378 QVariant var = getProperty(QStringLiteral("Name"));
379 return qdbus_cast<QString>(v: var);
380}
381
382QT_END_NAMESPACE
383
384#endif // QT_NO_DBUS
385

source code of qtbase/src/plugins/bearer/linux_common/qofonoservice_linux.cpp