File indexing completed on 2024-04-28 15:17:44

0001 /*
0002  * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 #include "leadvertisingmanagerinterface.h"
0008 
0009 #include <QDBusConnection>
0010 #include <QDBusMessage>
0011 #include <QDBusPendingCall>
0012 
0013 LEAdvertisingManagerInterface::LEAdvertisingManagerInterface(const QDBusObjectPath &path, QObject *parent)
0014     : QDBusAbstractAdaptor(parent)
0015 {
0016     setName(QStringLiteral("org.bluez.LEAdvertisingManager1"));
0017     setPath(path);
0018 }
0019 
0020 void LEAdvertisingManagerInterface::runAction(const QString &actionName, const QVariantMap & /*properties*/)
0021 {
0022     if (actionName == QLatin1String("release")) {
0023         runReleaseAction();
0024     }
0025 }
0026 
0027 void LEAdvertisingManagerInterface::RegisterAdvertisement(const QDBusObjectPath &path, const QVariantMap & /*options*/, const QDBusMessage &msg)
0028 {
0029     m_advertisement = path;
0030     m_service = msg.service();
0031 }
0032 
0033 void LEAdvertisingManagerInterface::UnregisterAdvertisement(const QDBusObjectPath &path, const QDBusMessage &msg)
0034 {
0035     if (m_advertisement == path && m_service == msg.service()) {
0036         m_advertisement = QDBusObjectPath();
0037         m_service.clear();
0038     }
0039 }
0040 
0041 void LEAdvertisingManagerInterface::runReleaseAction()
0042 {
0043     QDBusMessage call =
0044         QDBusMessage::createMethodCall(m_service, m_advertisement.path(), QStringLiteral("org.bluez.LEAdvertisement1"), QStringLiteral("Release"));
0045     QDBusConnection::sessionBus().asyncCall(call);
0046 }
0047 
0048 #include "moc_leadvertisingmanagerinterface.cpp"