Debian Codegraph @

autotests/fakebluez/mediainterface.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer <[email protected]>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6
7 #include "mediainterface.h"
8
9 #include <QDBusConnection>
10 #include <QDBusMessage>
11 #include <QDBusPendingCall>
12
13 MediaInterface::MediaInterface(const QDBusObjectPath &path, QObject *parent)
14 : QDBusAbstractAdaptor(parent)
15 {
16 setName(QStringLiteral("org.bluez.Media1"));
17 setPath(path);
18 }
19
20 void MediaInterface::runAction(const QString &actionName, const QVariantMap &properties)
21 {
22 if (actionName == QLatin1String("set-configuration")) {
23 runSetConfigurationAction(properties);
24 } else if (actionName == QLatin1String("select-configuration")) {
25 runSelectConfigurationAction(properties);
26 } else if (actionName == QLatin1String("clear-configuration")) {
27 runClearConfigurationAction(properties);
28 } else if (actionName == QLatin1String("release")) {
29 runReleaseAction();
30 }
31 }
32
33 void MediaInterface::RegisterEndpoint(const QDBusObjectPath &path, const QVariantMap &properties, const QDBusMessage &msg)
34 {
35 m_endpoint = path;
36 m_service = msg.service();
37 m_properties = properties;
38 }
39
40 void MediaInterface::UnregisterEndpoint(const QDBusObjectPath &path, const QDBusMessage &msg)
41 {
42 if (m_endpoint == path && m_service == msg.service()) {
43 m_endpoint = QDBusObjectPath();
44 m_service.clear();
45 m_properties.clear();
46 }
47 }
48
49 void MediaInterface::runSetConfigurationAction(const QVariantMap &properties)
50 {
51 QDBusMessage call =
52 QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("SetConfiguration"));
53 call << QVariant::fromValue(properties.value(QStringLiteral("Transport")).value<QDBusObjectPath>());
54 call << properties.value(QStringLiteral("Properties"));
55 QDBusConnection::sessionBus().asyncCall(call);
56 }
57
58 void MediaInterface::runSelectConfigurationAction(const QVariantMap &properties)
59 {
60 QDBusMessage call =
61 QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("SelectConfiguration"));
62 call << properties.value(QStringLiteral("Capabilities"));
63 QDBusConnection::sessionBus().asyncCall(call);
64 }
65
66 void MediaInterface::runClearConfigurationAction(const QVariantMap &properties)
67 {
68 QDBusMessage call =
69 QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("ClearConfiguration"));
70 call << QVariant::fromValue(properties.value(QStringLiteral("Transport")).value<QDBusObjectPath>());
71 QDBusConnection::sessionBus().asyncCall(call);
72 }
73
74 void MediaInterface::runReleaseAction()
75 {
76 QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("Release"));
77 QDBusConnection::sessionBus().asyncCall(call);
78 }
79
80 #include "moc_mediainterface.cpp"