File indexing completed on 2023-09-24 04:02:11
0001 /* 0002 * SPDX-FileCopyrightText: 2018 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 "mediainterface.h" 0008 0009 #include <QDBusConnection> 0010 #include <QDBusMessage> 0011 #include <QDBusPendingCall> 0012 0013 MediaInterface::MediaInterface(const QDBusObjectPath &path, QObject *parent) 0014 : QDBusAbstractAdaptor(parent) 0015 { 0016 setName(QStringLiteral("org.bluez.Media1")); 0017 setPath(path); 0018 } 0019 0020 void MediaInterface::runAction(const QString &actionName, const QVariantMap &properties) 0021 { 0022 if (actionName == QLatin1String("set-configuration")) { 0023 runSetConfigurationAction(properties); 0024 } else if (actionName == QLatin1String("select-configuration")) { 0025 runSelectConfigurationAction(properties); 0026 } else if (actionName == QLatin1String("clear-configuration")) { 0027 runClearConfigurationAction(properties); 0028 } else if (actionName == QLatin1String("release")) { 0029 runReleaseAction(); 0030 } 0031 } 0032 0033 void MediaInterface::RegisterEndpoint(const QDBusObjectPath &path, const QVariantMap &properties, const QDBusMessage &msg) 0034 { 0035 m_endpoint = path; 0036 m_service = msg.service(); 0037 m_properties = properties; 0038 } 0039 0040 void MediaInterface::UnregisterEndpoint(const QDBusObjectPath &path, const QDBusMessage &msg) 0041 { 0042 if (m_endpoint == path && m_service == msg.service()) { 0043 m_endpoint = QDBusObjectPath(); 0044 m_service.clear(); 0045 m_properties.clear(); 0046 } 0047 } 0048 0049 void MediaInterface::runSetConfigurationAction(const QVariantMap &properties) 0050 { 0051 QDBusMessage call = 0052 QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("SetConfiguration")); 0053 call << QVariant::fromValue(properties.value(QStringLiteral("Transport")).value<QDBusObjectPath>()); 0054 call << properties.value(QStringLiteral("Properties")); 0055 QDBusConnection::sessionBus().asyncCall(call); 0056 } 0057 0058 void MediaInterface::runSelectConfigurationAction(const QVariantMap &properties) 0059 { 0060 QDBusMessage call = 0061 QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("SelectConfiguration")); 0062 call << properties.value(QStringLiteral("Capabilities")); 0063 QDBusConnection::sessionBus().asyncCall(call); 0064 } 0065 0066 void MediaInterface::runClearConfigurationAction(const QVariantMap &properties) 0067 { 0068 QDBusMessage call = 0069 QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("ClearConfiguration")); 0070 call << QVariant::fromValue(properties.value(QStringLiteral("Transport")).value<QDBusObjectPath>()); 0071 QDBusConnection::sessionBus().asyncCall(call); 0072 } 0073 0074 void MediaInterface::runReleaseAction() 0075 { 0076 QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("Release")); 0077 QDBusConnection::sessionBus().asyncCall(call); 0078 } 0079 0080 #include "moc_mediainterface.cpp"