ModemManagerQt

fakemodem/modem.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 "modem.h"
8
9#include <QDBusConnection>
10#include <QDBusMessage>
11
12Modem::Modem(QObject *parent)
13 : QObject(parent)
14 , m_accessTechnologies(0)
15 , m_currentCapabilities(0)
16 , m_enabledNotifications(false)
17 , m_maxActiveBearers(0)
18 , m_maxBearers(0)
19 , m_powerState(0)
20 , m_state(0)
21 , m_stateFailedReason(0)
22 , m_supportedBands{0}
23 , m_supportedIpFamilies(0)
24 , m_unlockRequired(0)
25{
26}
27
28Modem::~Modem()
29{
30}
31
32uint Modem::accessTechnologies() const
33{
34 return m_accessTechnologies;
35}
36
37QList<QDBusObjectPath> Modem::bearers() const
38{
39 return m_bearers;
40}
41
42ModemManager::UIntList Modem::currentBands() const
43{
44 return m_currentBands;
45}
46
47uint Modem::currentCapabilities() const
48{
49 return m_currentCapabilities;
50}
51
52ModemManager::CurrentModesType Modem::currentModes() const
53{
54 return m_currentModes;
55}
56
57QString Modem::device() const
58{
59 return m_device;
60}
61
62QString Modem::deviceIdentifier() const
63{
64 return m_deviceIdentifier;
65}
66
67QStringList Modem::drivers() const
68{
69 return m_drivers;
70}
71
72QString Modem::equipmentIdentifier() const
73{
74 return m_equipmentIdentifier;
75}
76
77QString Modem::manufacturer() const
78{
79 return m_manufacturer;
80}
81
82uint Modem::maxActiveBearers() const
83{
84 return m_maxActiveBearers;
85}
86
87uint Modem::maxBearers() const
88{
89 return m_maxBearers;
90}
91
92QString Modem::modemPath() const
93{
94 return m_path;
95}
96
97QString Modem::model() const
98{
99 return m_model;
100}
101
102QStringList Modem::ownNumbers() const
103{
104 return m_ownNumbers;
105}
106
107QString Modem::plugin() const
108{
109 return m_plugin;
110}
111
112ModemManager::PortList Modem::ports() const
113{
114 return m_ports;
115}
116
117uint Modem::powerState() const
118{
119 return m_powerState;
120}
121
122QString Modem::primaryPort() const
123{
124 return m_primaryPort;
125}
126
127QString Modem::revision() const
128{
129 return m_revision;
130}
131
132ModemManager::SignalQualityPair Modem::signalQuality() const
133{
134 return m_signalQuality;
135}
136
137QDBusObjectPath Modem::sim() const
138{
139 return m_sim;
140}
141
142int Modem::state() const
143{
144 return m_state;
145}
146
147uint Modem::stateFailedReason() const
148{
149 return m_stateFailedReason;
150}
151
152ModemManager::UIntList Modem::supportedBands() const
153{
154 return m_supportedBands;
155}
156
157ModemManager::UIntList Modem::supportedCapabilities() const
158{
159 return m_supportedCapabilities;
160}
161
162uint Modem::supportedIpFamilies() const
163{
164 return m_supportedIpFamilies;
165}
166
167ModemManager::SupportedModesType Modem::supportedModes() const
168{
169 return m_supportedModes;
170}
171
172uint Modem::unlockRequired() const
173{
174 return m_unlockRequired;
175}
176
177ModemManager::UnlockRetriesMap Modem::unlockRetries() const
178{
179 return m_unlockRetries;
180}
181
182void Modem::addBearer(const QDBusObjectPath &bearer)
183{
184 m_bearers << bearer;
185}
186
187void Modem::removeBearer(const QDBusObjectPath &bearer)
188{
189 m_bearers.removeAll(bearer);
190}
191
192void Modem::setDevice(const QString &device)
193{
194 m_device = device;
195
196 if (m_enabledNotifications) {
197 QVariantMap map;
198 map.insert(QLatin1String("Device"), m_device);
199 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
200 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
202 }
203}
204
205void Modem::setEnableNotifications(bool enable)
206{
207 m_enabledNotifications = enable;
208}
209
210void Modem::setDeviceIdentifier(const QString &deviceIdentifier)
211{
212 m_deviceIdentifier = deviceIdentifier;
213
214 if (m_enabledNotifications) {
215 QVariantMap map;
216 map.insert(QLatin1String("DeviceIdentifier"), m_deviceIdentifier);
217 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
218 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
220 }
221}
222
223void Modem::setDrivers(const QStringList &drivers)
224{
225 m_drivers = drivers;
226
227 if (m_enabledNotifications) {
228 QVariantMap map;
229 map.insert(QLatin1String("Drivers"), m_deviceIdentifier);
230 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
231 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
233 }
234}
235
236void Modem::setEquipmentIdentifier(const QString &identifier)
237{
238 m_equipmentIdentifier = identifier;
239
240 if (m_enabledNotifications) {
241 QVariantMap map;
242 map.insert(QLatin1String("EquipmentIdentifier"), m_equipmentIdentifier);
243 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
244 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
246 }
247}
248
249void Modem::setManufacturer(const QString &manufacturer)
250{
251 m_manufacturer = manufacturer;
252
253 if (m_enabledNotifications) {
254 QVariantMap map;
255 map.insert(QLatin1String("Manufacturer"), m_manufacturer);
256 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
257 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
259 }
260}
261
262void Modem::setMaxActiveBearers(uint bearers)
263{
264 m_maxActiveBearers = bearers;
265
266 if (m_enabledNotifications) {
267 QVariantMap map;
268 map.insert(QLatin1String("MaxActiveBearers"), m_maxActiveBearers);
269 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
270 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
272 }
273}
274
275void Modem::setMaxBearers(uint bearers)
276{
277 m_maxBearers = bearers;
278
279 if (m_enabledNotifications) {
280 QVariantMap map;
281 map.insert(QLatin1String("MaxBearers"), m_maxBearers);
282 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
283 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
285 }
286}
287
288void Modem::setModemPath(const QString &path)
289{
290 m_path = path;
291}
292
293void Modem::setModel(const QString &model)
294{
295 m_model = model;
296
297 if (m_enabledNotifications) {
298 QVariantMap map;
299 map.insert(QLatin1String("Model"), m_model);
300 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
301 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
303 }
304}
305
306void Modem::setOwnNumbers(const QStringList &numbers)
307{
308 m_ownNumbers = numbers;
309
310 if (m_enabledNotifications) {
311 QVariantMap map;
312 map.insert(QLatin1String("OwnNumbers"), m_ownNumbers);
313 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
314 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
316 }
317}
318
319void Modem::setPlugin(const QString &plugin)
320{
321 m_plugin = plugin;
322
323 if (m_enabledNotifications) {
324 QVariantMap map;
325 map.insert(QLatin1String("Plugin"), m_plugin);
326 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
327 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
329 }
330}
331
332void Modem::setPorts(const ModemManager::PortList &ports)
333{
334 m_ports = ports;
335
336 if (m_enabledNotifications) {
337 QVariantMap map;
339 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
340 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
342 }
343}
344
345void Modem::setPrimaryPort(const QString &port)
346{
347 m_primaryPort = port;
348
349 if (m_enabledNotifications) {
350 QVariantMap map;
351 map.insert(QLatin1String("PrimaryPort"), m_primaryPort);
352 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
353 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
355 }
356}
357
358void Modem::setRevision(const QString &revision)
359{
360 m_revision = revision;
361
362 if (m_enabledNotifications) {
363 QVariantMap map;
364 map.insert(QLatin1String("Revision"), m_revision);
365 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
366 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
368 }
369}
370
371void Modem::setSignalQuality(const ModemManager::SignalQualityPair &signalQuality)
372{
373 m_signalQuality = signalQuality;
374
375 if (m_enabledNotifications) {
376 QVariantMap map;
377 map.insert(QLatin1String("SignalQuality"), QVariant::fromValue<ModemManager::SignalQualityPair>(m_signalQuality));
378 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
379 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
381 }
382}
383
384void Modem::setSim(const QDBusObjectPath &sim)
385{
386 m_sim = sim;
387
388 if (m_enabledNotifications) {
389 QVariantMap map;
391 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
392 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
394 }
395}
396
397void Modem::setState(int state)
398{
399 int previousState = m_state;
400 m_state = state;
401
402 if (m_enabledNotifications) {
403 Q_EMIT StateChanged(previousState, m_state, 0);
404 }
405}
406
407void Modem::setStateFailedReason(uint reason)
408{
409 m_stateFailedReason = reason;
410
411 if (m_enabledNotifications) {
412 QVariantMap map;
413 map.insert(QLatin1String("StateFailedReason"), m_stateFailedReason);
414 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
415 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
417 }
418}
419
420void Modem::setSupportedBands(const ModemManager::UIntList &bands)
421{
422 m_supportedBands = bands;
423
424 if (m_enabledNotifications) {
425 QVariantMap map;
426 map.insert(QLatin1String("SupportedBands"), QVariant::fromValue<ModemManager::UIntList>(m_supportedBands));
427 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
428 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
430 }
431}
432
433void Modem::setSupportedCapabilities(const ModemManager::UIntList &capabilities)
434{
435 m_supportedCapabilities = capabilities;
436
437 if (m_enabledNotifications) {
438 QVariantMap map;
439 map.insert(QLatin1String("SupportedCapabilities"), QVariant::fromValue<ModemManager::UIntList>(m_supportedCapabilities));
440 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
441 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
443 }
444}
445
446void Modem::setSupportedIpFamilies(uint families)
447{
448 m_supportedIpFamilies = families;
449
450 if (m_enabledNotifications) {
451 QVariantMap map;
452 map.insert(QLatin1String("SupportedIpFamilies"), m_supportedIpFamilies);
453 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
454 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
456 }
457}
458
459void Modem::setSupportedModes(const ModemManager::SupportedModesType &modes)
460{
461 m_supportedModes = modes;
462
463 if (m_enabledNotifications) {
464 QVariantMap map;
465 map.insert(QLatin1String("SupportedModes"), QVariant::fromValue<ModemManager::SupportedModesType>(m_supportedModes));
466 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
467 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
469 }
470}
471
472void Modem::setUnlockRequired(uint unlockRequired)
473{
474 m_unlockRequired = unlockRequired;
475
476 if (m_enabledNotifications) {
477 QVariantMap map;
478 map.insert(QLatin1String("UnlockRequired"), m_unlockRequired);
479 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
480 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
482 }
483}
484
485void Modem::setUnlockRetries(const ModemManager::UnlockRetriesMap &unlockRetries)
486{
487 m_unlockRetries = unlockRetries;
488
489 if (m_enabledNotifications) {
490 QVariantMap map;
491 map.insert(QLatin1String("UnlockRetries"), QVariant::fromValue<ModemManager::UnlockRetriesMap>(m_unlockRetries));
492 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
493 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
495 }
496}
497
498void Modem::setAccessTechnologies(uint technologies)
499{
500 m_accessTechnologies = technologies;
501
502 if (m_enabledNotifications) {
503 QVariantMap map;
504 map.insert(QLatin1String("AccessTechnologies"), m_accessTechnologies);
505 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
506 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
508 }
509}
510
511void Modem::SetCurrentBands(const QList<uint> &bands)
512{
513 m_currentBands = bands;
514
515 if (m_enabledNotifications) {
516 QVariantMap map;
517 map.insert(QLatin1String("CurrentBands"), QVariant::fromValue<QList<uint>>(m_currentBands));
518 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
519 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
521 }
522}
523
524void Modem::SetCurrentCapabilities(uint capabilities)
525{
526 m_currentCapabilities = capabilities;
527
528 if (m_enabledNotifications) {
529 QVariantMap map;
530 map.insert(QLatin1String("CurrentCapabilities"), m_currentCapabilities);
531 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
532 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
534 }
535}
536
537void Modem::SetCurrentModes(ModemManager::CurrentModesType modes)
538{
539 m_currentModes = modes;
540
541 if (m_enabledNotifications) {
542 QVariantMap map;
543 map.insert(QLatin1String("CurrentModes"), QVariant::fromValue<ModemManager::CurrentModesType>(m_currentModes));
544 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
545 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
547 }
548}
549
550void Modem::SetPowerState(uint state)
551{
552 m_powerState = state;
553
554 if (m_enabledNotifications) {
555 QVariantMap map;
556 map.insert(QLatin1String("PowerState"), m_powerState);
557 QDBusMessage message = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("PropertiesChanged"));
558 message << QLatin1String("org.kde.fakemodem.Modem") << map << QStringList();
560 }
561}
562
563QString Modem::Command(const QString &cmd, uint timeout)
564{
565 Q_UNUSED(cmd);
566 Q_UNUSED(timeout);
567 // TODO
568 return QString();
569}
570
571QDBusObjectPath Modem::CreateBearer(const QVariantMap &properties)
572{
573 Q_UNUSED(properties);
574 // TODO
575 return QDBusObjectPath();
576}
577
578void Modem::DeleteBearer(const QDBusObjectPath &bearer)
579{
580 Q_UNUSED(bearer);
581 // TODO
582}
583
584void Modem::Enable(bool enable)
585{
586 Q_UNUSED(enable);
587 // TODO
588}
589
590void Modem::FactoryReset(const QString &code)
591{
592 Q_UNUSED(code);
593 // TODO
594}
595
596QList<QDBusObjectPath> Modem::ListBearers()
597{
598 return m_bearers;
599}
600
601void Modem::Reset()
602{
603 // TODO
604}
605
606QVariantMap Modem::toMap() const
607{
608 QVariantMap map;
609 map.insert(QLatin1String(MM_MODEM_PROPERTY_SIM), QVariant::fromValue<QDBusObjectPath>(m_sim));
610#if MM_CHECK_VERSION(1, 2, 0)
611 map.insert(QLatin1String(MM_MODEM_PROPERTY_BEARERS), QVariant::fromValue<QList<QDBusObjectPath>>(m_bearers));
612#endif
613 map.insert(QLatin1String(MM_MODEM_PROPERTY_SUPPORTEDCAPABILITIES), QVariant::fromValue<ModemManager::UIntList>(m_supportedCapabilities));
614 map.insert(QLatin1String(MM_MODEM_PROPERTY_CURRENTCAPABILITIES), m_currentCapabilities);
615 map.insert(QLatin1String(MM_MODEM_PROPERTY_MAXBEARERS), m_maxBearers);
616 map.insert(QLatin1String(MM_MODEM_PROPERTY_MAXACTIVEBEARERS), m_maxActiveBearers);
617 map.insert(QLatin1String(MM_MODEM_PROPERTY_MANUFACTURER), m_manufacturer);
618 map.insert(QLatin1String(MM_MODEM_PROPERTY_MODEL), m_model);
619 map.insert(QLatin1String(MM_MODEM_PROPERTY_REVISION), m_revision);
620 map.insert(QLatin1String(MM_MODEM_PROPERTY_DEVICEIDENTIFIER), m_deviceIdentifier);
621 map.insert(QLatin1String(MM_MODEM_PROPERTY_DEVICE), m_device);
622 map.insert(QLatin1String(MM_MODEM_PROPERTY_DRIVERS), m_drivers);
623 map.insert(QLatin1String(MM_MODEM_PROPERTY_PLUGIN), m_plugin);
624 map.insert(QLatin1String(MM_MODEM_PROPERTY_PRIMARYPORT), m_primaryPort);
625 map.insert(QLatin1String(MM_MODEM_PROPERTY_PORTS), QVariant::fromValue<ModemManager::PortList>(m_ports));
626 map.insert(QLatin1String(MM_MODEM_PROPERTY_EQUIPMENTIDENTIFIER), m_equipmentIdentifier);
627 map.insert(QLatin1String(MM_MODEM_PROPERTY_UNLOCKREQUIRED), m_unlockRequired);
628 map.insert(QLatin1String(MM_MODEM_PROPERTY_UNLOCKRETRIES), QVariant::fromValue<ModemManager::UnlockRetriesMap>(m_unlockRetries));
629 map.insert(QLatin1String(MM_MODEM_PROPERTY_STATE), m_state);
630 map.insert(QLatin1String(MM_MODEM_PROPERTY_STATEFAILEDREASON), m_stateFailedReason);
631 map.insert(QLatin1String(MM_MODEM_PROPERTY_ACCESSTECHNOLOGIES), m_accessTechnologies);
632 map.insert(QLatin1String(MM_MODEM_PROPERTY_SIGNALQUALITY), QVariant::fromValue<ModemManager::SignalQualityPair>(m_signalQuality));
633 map.insert(QLatin1String(MM_MODEM_PROPERTY_OWNNUMBERS), m_ownNumbers);
634 map.insert(QLatin1String(MM_MODEM_PROPERTY_POWERSTATE), m_powerState);
635 map.insert(QLatin1String(MM_MODEM_PROPERTY_SUPPORTEDMODES), QVariant::fromValue<ModemManager::SupportedModesType>(m_supportedModes));
636 map.insert(QLatin1String(MM_MODEM_PROPERTY_CURRENTMODES), QVariant::fromValue<ModemManager::CurrentModesType>(m_currentModes));
637 map.insert(QLatin1String(MM_MODEM_PROPERTY_SUPPORTEDBANDS), QVariant::fromValue<ModemManager::UIntList>(m_supportedBands));
638 map.insert(QLatin1String(MM_MODEM_PROPERTY_CURRENTBANDS), QVariant::fromValue<ModemManager::UIntList>(m_currentBands));
639 map.insert(QLatin1String(MM_MODEM_PROPERTY_SUPPORTEDIPFAMILIES), m_supportedIpFamilies);
640 return map;
641}
642
643#include "moc_modem.cpp"
Capabilities capabilities()
QString path(const QString &relativePath)
bool send(const QDBusMessage &message) const const
QDBusConnection sessionBus()
QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
qsizetype removeAll(const AT &t)
Q_EMITQ_EMIT
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 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.