diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2017-06-26 18:34:20 -0700 |
---|---|---|
committer | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2017-06-30 19:29:06 +0000 |
commit | 5cd7736e1e104c6ff779dcca1026aad208ed4b1d (patch) | |
tree | a1b71c0844892d0ea56f00a9dc2d68d4b6b40280 /app/dbus.cpp | |
parent | b7cd2250f9b34fa65ea92da8eb35775c6f5c61c8 (diff) |
binding: bluetooth: switch from dbus calls to system bindingdab_3.99.2dab/3.99.23.99.2
Use the system wide binding for Bluetooth access to get AVRCP
metadata, and triggers controls.
Bug-AGL: SPEC-610 SPEC-615
Change-Id: Ic894c75d663b797b8a331236ff756b3b94bc13c8
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'app/dbus.cpp')
-rw-r--r-- | app/dbus.cpp | 224 |
1 files changed, 0 insertions, 224 deletions
diff --git a/app/dbus.cpp b/app/dbus.cpp deleted file mode 100644 index a562989..0000000 --- a/app/dbus.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (C) 2017 Konsulko Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dbus.h" - - -DbusService::DbusService(QObject *parent) : QObject(parent) -{ -} - -/* - * Bluetooth - */ - -void DbusService::setBluezPath(const QString& path) -{ - this->bluezPath = path; -} - -QString DbusService::getBluezPath() const -{ - return this->bluezPath; -} - -bool DbusService::enableBluetooth() -{ - QDBusConnection system_bus = QDBusConnection::systemBus(); - QString interface = "org.freedesktop.DBus.ObjectManager"; - bool ret; - - if (!system_bus.isConnected()) - return false; - - if (deviceConnected(system_bus)) - initialBluetoothData(system_bus); - - ret = system_bus.connect(QString("org.bluez"), QString("/"), interface, "InterfacesAdded", this, SLOT(newBluetoothDevice(QDBusObjectPath,QVariantMap))); - - if (!ret) - return false; - - ret = system_bus.connect(QString("org.bluez"), QString("/"), interface, "InterfacesRemoved", this, SLOT(removeBluetoothDevice(QDBusObjectPath,QStringList))); - - /* - * Unregister InterfacesAdded on error condition - */ - if (!ret) - system_bus.disconnect(QString("org.bluez"), QString("/"), interface, "InterfacesAdded", this, SLOT(newBluetoothDevice(QString,QVariantMap))); - - return ret; -} - -bool DbusService::checkIfPlayer(const QString& path) const -{ - QRegExp regex("^.*/player\\d$"); - if (regex.exactMatch(path)) - return true; - - return false; -} - -bool DbusService::deviceConnected(const QDBusConnection& system_bus) -{ - QDBusInterface interface("org.bluez", "/", "org.freedesktop.DBus.ObjectManager", system_bus); - QDBusMessage result = interface.call("GetManagedObjects"); - const QDBusArgument argument = result.arguments().at(0).value<QDBusArgument>(); - bool ret = false; - - if (argument.currentType() != QDBusArgument::MapType) - return false; - - argument.beginMap(); - - while (!argument.atEnd()) { - QString key; - - argument.beginMapEntry(); - argument >> key; - argument.endMapEntry(); - - ret = checkIfPlayer(key); - - if (ret) { - newBluetoothDevice(QDBusObjectPath(key), QVariantMap()); - break; - } - } - - argument.endMap(); - - return ret; -} - -void DbusService::initialBluetoothData(const QDBusConnection& system_bus) -{ - QDBusInterface interface("org.bluez", getBluezPath(), "org.freedesktop.DBus.Properties", system_bus); - - QDBusMessage result = interface.call("GetAll", "org.bluez.MediaPlayer1"); - const QDBusArgument argument = result.arguments().at(0).value<QDBusArgument>(); - QString status, artist, title; - int position = 0, duration = 0; - - if (argument.currentType() != QDBusArgument::MapType) - return; - - argument.beginMap(); - - while (!argument.atEnd()) { - QString key; - QVariant value; - - argument.beginMapEntry(); - argument >> key >> value; - - if (key == "Position") { - position = value.toInt(); - } else if (key == "Status") { - status = value.toString(); - } else if (key == "Track") { - const QDBusArgument argument1 = qvariant_cast<QDBusArgument>(value); - QString key1; - QVariant value1; - - argument1.beginMap(); - - while (!argument1.atEnd()) { - argument1.beginMapEntry(); - argument1 >> key1 >> value1; - if (key1 == "Artist") - artist = value1.toString(); - else if (key1 == "Title") - title = value1.toString(); - else if (key1 == "Duration") - duration = value1.toInt(); - argument1.endMapEntry(); - } - argument1.endMap(); - } - argument.endMapEntry(); - } - argument.endMap(); - - emit processPlaylistHide(); - emit displayBluetoothMetadata(artist, title, duration); - emit updatePlayerStatus(status); - emit updatePosition(position); -} - -void DbusService::newBluetoothDevice(const QDBusObjectPath& item, const QVariantMap&) -{ - QString path = item.path(); - if (!checkIfPlayer(path)) - return; - - if (!getBluezPath().isEmpty()) { - qWarning() << "Another Bluetooth Player already connected"; - return; - } - - emit processPlaylistHide(); - - QDBusConnection system_bus = QDBusConnection::systemBus(); - system_bus.connect(QString("org.bluez"), path, "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(processBluetoothEvent(QString,QVariantMap,QStringList))); - - setBluezPath(path); -} - -void DbusService::removeBluetoothDevice(const QDBusObjectPath& item, const QStringList&) -{ - QString path = item.path(); - if (!checkIfPlayer(path)) - return; - - if (getBluezPath().isEmpty()) { - qWarning() << "No Bluetooth Player connected"; - return; - } - - QDBusConnection system_bus = QDBusConnection::systemBus(); - system_bus.disconnect(QString("org.bluez"), path, "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(processBluetoothEvent(QString,QVariantMap,QStringList))); - - setBluezPath(QString()); - emit processPlaylistShow(); -} - -void DbusService::processBluetoothEvent(const QString&, const QVariantMap& map, const QStringList&) -{ - if (map.contains("Track")) { - QVariantMap track; - map["Track"].value<QDBusArgument>() >> track; - emit displayBluetoothMetadata(track["Artist"].toString(), track["Title"].toString(), track["Duration"].toInt()); - } - - if (map.contains("Position")) - emit updatePosition(map["Position"].toInt()); - - if (map.contains("Status")) - emit updatePlayerStatus(map["Status"].toString()); -} - -void DbusService::processQMLEvent(const QString& state) -{ - QDBusInterface interface("org.bluez", getBluezPath(), "org.bluez.MediaPlayer1", QDBusConnection::systemBus()); - interface.call(state); -} - -long DbusService::getCurrentPosition() -{ - QDBusInterface interface("org.bluez", getBluezPath(), "org.bluez.MediaPlayer1", QDBusConnection::systemBus()); - return interface.property("Position").toInt(); -} |