ModemManagerQt

modemoma.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Lukas Tinkl <ltinkl@redhat.com>
3 SPDX-FileCopyrightText: 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 "modemoma.h"
9#include "mmdebug_p.h"
10#include "modemoma_p.h"
11#ifdef MMQT_STATIC
12#include "dbus/fakedbus.h"
13#else
14#include "dbus/dbus.h"
15#endif
16
17ModemManager::ModemOmaPrivate::ModemOmaPrivate(const QString &path, ModemOma *q)
18 : InterfacePrivate(path, q)
19#ifdef MMQT_STATIC
20 , omaIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::sessionBus())
21#else
22 , omaIface(QLatin1String(MMQT_DBUS_SERVICE), path, QDBusConnection::systemBus())
23#endif
24 , q_ptr(q)
25{
26 if (omaIface.isValid()) {
27 features = (ModemOma::Features)omaIface.features();
28 pendingNetworkInitiatedSessions = omaIface.pendingNetworkInitiatedSessions();
29 sessionType = (MMOmaSessionType)omaIface.sessionType();
30 sessionState = (MMOmaSessionState)omaIface.sessionState();
31 }
32}
33
34ModemManager::ModemOma::ModemOma(const QString &path, QObject *parent)
35 : Interface(*new ModemOmaPrivate(path, this), parent)
36{
37 Q_D(ModemOma);
38
39 qRegisterMetaType<QFlags<MMOmaFeature>>();
40 qRegisterMetaType<MMOmaSessionType>();
41 qRegisterMetaType<MMOmaSessionState>();
42 qRegisterMetaType<MMOmaSessionStateFailedReason>();
43
44 connect(&d->omaIface, &OrgFreedesktopModemManager1ModemOmaInterface::SessionStateChanged, d, &ModemOmaPrivate::onSessionStateChanged);
45#ifdef MMQT_STATIC
47 d->uni,
48 QLatin1String(DBUS_INTERFACE_PROPS),
49 QStringLiteral("PropertiesChanged"),
50 d,
51 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
52#else
54 d->uni,
55 QLatin1String(DBUS_INTERFACE_PROPS),
56 QStringLiteral("PropertiesChanged"),
57 d,
58 SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
59#endif
60}
61
62ModemManager::ModemOma::~ModemOma()
63{
64}
65
67{
68 Q_D(const ModemOma);
69
70 return d->features;
71}
72
74{
75 Q_D(const ModemOma);
76 return d->pendingNetworkInitiatedSessions;
77}
78
80{
81 Q_D(const ModemOma);
82 return d->sessionType;
83}
84
85MMOmaSessionState ModemManager::ModemOma::sessionState() const
86{
87 Q_D(const ModemOma);
88 return d->sessionState;
89}
90
92{
94 return d->omaIface.Setup((uint)features);
95}
96
98{
100 return d->omaIface.StartClientInitiatedSession((uint)sessionType);
101}
102
104{
105 Q_D(ModemOma);
106 return d->omaIface.AcceptNetworkInitiatedSession(sessionId, accept);
107}
108
110{
111 Q_D(ModemOma);
112 return d->omaIface.CancelSession();
113}
114
116{
117 Q_D(ModemOma);
118 d->omaIface.setTimeout(timeout);
119}
120
122{
123 Q_D(const ModemOma);
124 return d->omaIface.timeout();
125}
126
127void ModemManager::ModemOmaPrivate::onSessionStateChanged(int oldState, int newState, uint failedReason)
128{
129 Q_Q(ModemOma);
130 sessionState = (MMOmaSessionState)newState;
131 Q_EMIT q->sessionStateChanged((MMOmaSessionState)oldState, (MMOmaSessionState)newState, (MMOmaSessionStateFailedReason)failedReason);
132}
133void ModemManager::ModemOmaPrivate::onPropertiesChanged(const QString &interface, const QVariantMap &properties, const QStringList &invalidatedProps)
134{
135 Q_Q(ModemOma);
136 Q_UNUSED(invalidatedProps);
137 qCDebug(MMQT) << interface << properties.keys();
138
139 if (interface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_OMA)) {
140 QVariantMap::const_iterator it = properties.constFind(QLatin1String(MM_MODEM_OMA_PROPERTY_FEATURES));
141 if (it != properties.constEnd()) {
142 features = (ModemOma::Features)it->toUInt();
143 Q_EMIT q->featuresChanged(features);
144 }
145 it = properties.constFind(QLatin1String(MM_MODEM_OMA_PROPERTY_PENDINGNETWORKINITIATEDSESSIONS));
146 if (it != properties.constEnd()) {
147 pendingNetworkInitiatedSessions = qdbus_cast<OmaSessionTypes>(*it);
148 Q_EMIT q->pendingNetworkInitiatedSessionsChanged(pendingNetworkInitiatedSessions);
149 }
150 it = properties.constFind(QLatin1String(MM_MODEM_OMA_PROPERTY_SESSIONTYPE));
151 if (it != properties.constEnd()) {
152 sessionType = (MMOmaSessionType)it->toUInt();
153 Q_EMIT q->sessionTypeChanged(sessionType);
154 }
155 it = properties.constFind(QLatin1String(MM_MODEM_OMA_PROPERTY_SESSIONSTATE));
156 if (it != properties.constEnd()) {
157 // Should be handled by sessionStateChanged() signal
158 }
159 }
160}
161
162#include "moc_modemoma.cpp"
The ModemManager Open Mobile Alliance interface.
Definition modemoma.h:35
QDBusPendingReply< void > setup(Features features)
Configures which OMA device management features should be enabled.
Definition modemoma.cpp:91
QDBusPendingReply< void > acceptNetworkInitiatedSession(uint sessionId, bool accept)
Accepts or rejects a network-initiated device management session.
Definition modemoma.cpp:103
OmaSessionTypes pendingNetworkInitiatedSessions() const
Definition modemoma.cpp:73
MMOmaSessionState sessionState() const
Definition modemoma.cpp:85
MMOmaSessionType sessionType() const
Definition modemoma.cpp:79
QDBusPendingReply< void > startClientInitiatedSession(MMOmaSessionType sessionType)
Starts a client-initiated device management session.
Definition modemoma.cpp:97
QDBusPendingReply< void > cancelSession()
Cancels the current on-going device management session.
Definition modemoma.cpp:109
void setTimeout(int timeout)
Sets the timeout in milliseconds for all async method DBus calls.
Definition modemoma.cpp:115
int timeout() const
Returns the current value of the DBus timeout in milliseconds.
Definition modemoma.cpp:121
Features features() const
Definition modemoma.cpp:66
QString path(const QString &relativePath)
KGuiItem properties()
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.