Changeset View
Changeset View
Standalone View
Standalone View
autotests/fakebluez/leadvertisingmanagerinterface.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Manuel Weichselbaumer <mincequi@web.de> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | * Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "leadvertisingmanagerinterface.h" | ||||
22 | | ||||
23 | #include <QDebug> | ||||
24 | #include <QDBusMessage> | ||||
25 | #include <QDBusConnection> | ||||
26 | #include <QDBusPendingCall> | ||||
27 | | ||||
28 | LEAdvertisingManagerInterface::LEAdvertisingManagerInterface(const QDBusObjectPath &path, QObject *parent) | ||||
29 | : QDBusAbstractAdaptor(parent) | ||||
30 | { | ||||
31 | setName(QStringLiteral("org.bluez.LEAdvertisingManager1")); | ||||
32 | setPath(path); | ||||
33 | } | ||||
34 | | ||||
35 | void LEAdvertisingManagerInterface::runAction(const QString &actionName, const QVariantMap &/*properties*/) | ||||
36 | { | ||||
37 | if (actionName == QLatin1String("release")) { | ||||
38 | runReleaseAction(); | ||||
39 | } | ||||
40 | } | ||||
41 | | ||||
42 | void LEAdvertisingManagerInterface::RegisterAdvertisement(const QDBusObjectPath &path, const QVariantMap &/*options*/, const QDBusMessage &msg) | ||||
43 | { | ||||
44 | m_advertisement = path; | ||||
45 | m_service = msg.service(); | ||||
46 | } | ||||
47 | | ||||
48 | void LEAdvertisingManagerInterface::UnregisterAdvertisement(const QDBusObjectPath &path, const QDBusMessage &msg) | ||||
49 | { | ||||
50 | if (m_advertisement == path && m_service == msg.service()) { | ||||
51 | m_advertisement = QDBusObjectPath(); | ||||
52 | m_service.clear(); | ||||
53 | } | ||||
54 | } | ||||
55 | | ||||
56 | void LEAdvertisingManagerInterface::runReleaseAction() | ||||
57 | { | ||||
58 | QDBusMessage call = QDBusMessage::createMethodCall(m_service, | ||||
59 | m_advertisement.path(), | ||||
60 | QStringLiteral("org.bluez.LEAdvertisement1"), | ||||
61 | QStringLiteral("Release")); | ||||
62 | QDBusConnection::sessionBus().asyncCall(call); | ||||
63 | } |