ModemManagerQt

fakemodem.cpp
1/*
2 SPDX-FileCopyrightText: 2015 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 "fakemodem.h"
8#include "dbus/fakedbus.h"
9
10#include <QDBusConnection>
11#include <QDBusMessage>
12#include <QDBusMetaType>
13
14FakeModem::FakeModem(QObject *parent)
15 : QObject(parent)
16 , m_bearerCounter(0)
17 , m_modemCounter(0)
18 , m_objectManager(new ObjectManager(this))
19{
20 qDBusRegisterMetaType<ModemManager::MMVariantMapMap>();
21 qDBusRegisterMetaType<ModemManager::UIntList>();
22 qDBusRegisterMetaType<ModemManager::CurrentModesType>();
23 qDBusRegisterMetaType<ModemManager::SupportedModesType>();
24 qDBusRegisterMetaType<ModemManager::SignalQualityPair>();
25 qDBusRegisterMetaType<ModemManager::PortList>();
26 qDBusRegisterMetaType<ModemManager::UnlockRetriesMap>();
27 qDBusRegisterMetaType<ModemManager::Port>();
28 qDBusRegisterMetaType<ModemManager::LocationInformationMap>();
29
32 this,
34}
35
36FakeModem::~FakeModem()
37{
40}
41
42void FakeModem::addModem(Modem *modem)
43{
44 QString newModemPath = QStringLiteral("/org/kde/fakemodem/Modem/") + QString::number(m_modemCounter++);
45 modem->setModemPath(newModemPath);
46 // Start monitoring property changes
47 modem->setEnableNotifications(true);
48 m_modems.insert(QDBusObjectPath(newModemPath), modem);
50
52 interfaces.insert(QLatin1String(MMQT_DBUS_INTERFACE_MODEM), modem->toMap());
53
54 m_objectManager->addInterfaces(QDBusObjectPath(newModemPath), interfaces);
55}
56
57void FakeModem::removeModem(Modem *modem)
58{
59 m_modems.remove(QDBusObjectPath(modem->modemPath()));
61
62 m_objectManager->removeInterfaces(QDBusObjectPath(modem->modemPath()), {QLatin1String(MMQT_DBUS_INTERFACE_MODEM)});
63}
64
65void FakeModem::addBearer(Bearer *bearer)
66{
67 QString newBearerPath = QStringLiteral("/org/kde/fakemodem/Bearer/") + QString::number(m_bearerCounter++);
68 bearer->setBearerPath(newBearerPath);
69 bearer->setEnableNotifications(true);
70 m_bearers.insert(QDBusObjectPath(newBearerPath), bearer);
72 Q_FOREACH (Modem *modem, m_modems.values()) {
73 modem->addBearer(QDBusObjectPath(newBearerPath));
74 QVariantMap map;
75 map.insert(QLatin1String("Bearers"), QVariant::fromValue<QList<QDBusObjectPath>>(modem->bearers()));
76 QDBusMessage message =
77 QDBusMessage::createSignal(modem->modemPath(), QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
78 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
80 }
81}
82
83void FakeModem::removeBearer(Bearer *bearer)
84{
85 m_bearers.remove(QDBusObjectPath(bearer->bearerPath()));
86 QDBusConnection::sessionBus().unregisterObject(bearer->bearerPath());
87 Q_FOREACH (Modem *modem, m_modems.values()) {
88 modem->removeBearer(QDBusObjectPath(bearer->bearerPath()));
89 QVariantMap map;
90 map.insert(QLatin1String("Bearers"), QVariant::fromValue<QList<QDBusObjectPath>>(modem->bearers()));
91 QDBusMessage message =
92 QDBusMessage::createSignal(modem->modemPath(), QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
93 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
95 }
96}
97
98void FakeModem::addInterfaces(const QDBusObjectPath &object_path, const ModemManager::MMVariantMapMap &interfaces_and_properties)
99{
100 m_objectManager->addInterfaces(object_path, interfaces_and_properties);
101}
102
103void FakeModem::removeInterfaces(const QDBusObjectPath &object_path, const QStringList &interfaces)
104{
105 m_objectManager->removeInterfaces(object_path, interfaces);
106}
107
108void FakeModem::ScanDevices()
109{
110}
111
112void FakeModem::SetLogging(const QString &level)
113{
114 Q_UNUSED(level);
115}
116
117#include "moc_fakemodem.cpp"
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
bool registerService(const QString &serviceName)
bool send(const QDBusMessage &message) const const
QDBusConnection sessionBus()
void unregisterObject(const QString &path, UnregisterMode mode)
bool unregisterService(const QString &serviceName)
QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
iterator insert(const Key &key, const T &value)
size_type remove(const Key &key)
QList< T > values() const const
QString number(double n, char format, int precision)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.