Changeset View
Changeset View
Standalone View
Standalone View
autotests/fakebluez/media.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 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 "media.h" | ||||
22 | | ||||
23 | #include <QDebug> | ||||
24 | #include <QDBusMessage> | ||||
25 | #include <QDBusConnection> | ||||
26 | #include <QDBusPendingCall> | ||||
27 | | ||||
28 | Media::Media(QObject *parent) | ||||
29 | : QDBusAbstractAdaptor(parent) | ||||
30 | { | ||||
31 | setName(QStringLiteral("org.bluez.Media1")); | ||||
32 | setPath(QDBusObjectPath(QStringLiteral("/org/bluez"))); | ||||
33 | } | ||||
34 | | ||||
35 | void Media::runAction(const QString &actionName, const QVariantMap &properties) | ||||
36 | { | ||||
37 | if (actionName == QLatin1String("set-configuration")) { | ||||
38 | runSetConfigurationAction(properties); | ||||
39 | } else if (actionName == QLatin1String("select-configuration")) { | ||||
40 | runSelectConfigurationAction(properties); | ||||
41 | } else if (actionName == QLatin1String("clear-configuration")) { | ||||
42 | runClearConfigurationAction(properties); | ||||
43 | } else if (actionName == QLatin1String("release")) { | ||||
44 | runReleaseAction(); | ||||
45 | } | ||||
46 | } | ||||
47 | | ||||
48 | void Media::RegisterEndpoint(const QDBusObjectPath &path, const QVariantMap &properties, const QDBusMessage &msg) | ||||
49 | { | ||||
50 | m_endpoint = path; | ||||
51 | m_service = msg.service(); | ||||
52 | m_properties = properties; | ||||
53 | } | ||||
54 | | ||||
55 | void Media::UnregisterEndpoint(const QDBusObjectPath &path, const QDBusMessage &msg) | ||||
56 | { | ||||
57 | if (m_endpoint == path && m_service == msg.service()) { | ||||
58 | m_endpoint = QDBusObjectPath(); | ||||
59 | m_service.clear(); | ||||
60 | m_properties.clear(); | ||||
61 | } | ||||
62 | } | ||||
63 | | ||||
64 | void Media::runSetConfigurationAction(const QVariantMap &properties) | ||||
65 | { | ||||
66 | QDBusMessage call = QDBusMessage::createMethodCall(m_service, | ||||
67 | m_endpoint.path(), | ||||
68 | QStringLiteral("org.bluez.MediaEndpoint1"), | ||||
69 | QStringLiteral("SetConfiguration")); | ||||
70 | call << QVariant::fromValue(properties.value(QStringLiteral("Transport")).value<QDBusObjectPath>()); | ||||
71 | call << properties.value(QStringLiteral("Properties")); | ||||
72 | QDBusConnection::sessionBus().asyncCall(call); | ||||
73 | } | ||||
74 | | ||||
75 | void Media::runSelectConfigurationAction(const QVariantMap &properties) | ||||
76 | { | ||||
77 | QDBusMessage call = QDBusMessage::createMethodCall(m_service, | ||||
78 | m_endpoint.path(), | ||||
79 | QStringLiteral("org.bluez.MediaEndpoint1"), | ||||
80 | QStringLiteral("SelectConfiguration")); | ||||
81 | call << properties.value(QStringLiteral("Capabilities")); | ||||
82 | QDBusConnection::sessionBus().asyncCall(call); | ||||
83 | } | ||||
84 | | ||||
85 | void Media::runClearConfigurationAction(const QVariantMap &properties) | ||||
86 | { | ||||
87 | QDBusMessage call = QDBusMessage::createMethodCall(m_service, | ||||
88 | m_endpoint.path(), | ||||
89 | QStringLiteral("org.bluez.MediaEndpoint1"), | ||||
90 | QStringLiteral("ClearConfiguration")); | ||||
91 | call << QVariant::fromValue(properties.value(QStringLiteral("Transport")).value<QDBusObjectPath>()); | ||||
92 | QDBusConnection::sessionBus().asyncCall(call); | ||||
93 | } | ||||
94 | | ||||
95 | void Media::runReleaseAction() | ||||
96 | { | ||||
97 | QDBusMessage call = QDBusMessage::createMethodCall(m_service, | ||||
98 | m_endpoint.path(), | ||||
99 | QStringLiteral("org.bluez.MediaEndpoint1"), | ||||
100 | QStringLiteral("Release")); | ||||
101 | QDBusConnection::sessionBus().asyncCall(call); | ||||
102 | } |