diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,10 @@ device.cpp device_p.cpp input.cpp + media.cpp + media_p.cpp + mediaendpoint.cpp + mediaendpointadaptor.cpp mediaplayer.cpp mediaplayer_p.cpp mediaplayertrack.cpp @@ -47,6 +51,8 @@ qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.AgentManager1.xml bluezagentmanager1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.ProfileManager1.xml bluezprofilemanager1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Device1.xml bluezdevice1) +qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Media1.xml bluezmedia1) +qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.MediaEndpoint1.xml bluezmediaendpoint1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.MediaPlayer1.xml bluezmediaplayer1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.obex.AgentManager1.xml obexagentmanager1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.obex.Client1.xml obexclient1) diff --git a/src/interfaces/org.bluez.Media1.xml b/src/interfaces/org.bluez.Media1.xml new file mode 100644 --- /dev/null +++ b/src/interfaces/org.bluez.Media1.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/interfaces/org.bluez.MediaEndpoint1.xml b/src/interfaces/org.bluez.MediaEndpoint1.xml new file mode 100644 --- /dev/null +++ b/src/interfaces/org.bluez.MediaEndpoint1.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/media.h b/src/media.h new file mode 100644 --- /dev/null +++ b/src/media.h @@ -0,0 +1,100 @@ +/* + * BluezQt - Asynchronous BlueZ wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIA_H +#define BLUEZQT_MEDIA_H + +#include + +#include "bluezqt_export.h" + +namespace BluezQt +{ + +class MediaEndpoint; +class PendingCall; + +/** + * @class BluezQt::Media Media.h + * + * Bluetooth Media. + * + * This allows media endpoints to be established in accordance with the + * capabilities of a specific media service profile. + * + * For example, an A2DP media endpoint could be created allowing data from a + * remote device to be streamed to/from the sender. + * + * Each media endpoint is associated with a service object instance that + * implements the required behaviours of the endpoint. The service object + * must be created at a given path before it is registered. + * + * @see MediaEndpoint, ObexAgent, Profile + */ +class BLUEZQT_EXPORT Media : public QObject +{ + Q_OBJECT + +public: + /** + * Creates a new Media object. + * + * @param parent + */ + explicit Media(QObject *parent = nullptr); + + /** + * Destroys a Media object. + */ + ~Media(); + + /** + * Registers endpoint. + * + * Register a local end point to sender, the sender can register as many end points as it likes. + * + * Note: If the sender disconnects the end points are automatically unregistered. + * + * Possible errors: PendingCall::InvalidArguments, PendingCall::NotSupported + * + * @param endpoint endpoint to be registered + * @return void pending call + */ + PendingCall *registerEndpoint(MediaEndpoint *endpoint); + + /** + * Unregisters endpoint. + * + * @param endpoint endpoint to be unregistered + * @return void pending call + */ + PendingCall *unregisterEndpoint(MediaEndpoint *endpoint); + +private: + class MediaPrivate *const d; + + friend class MediaPrivate; +}; + +} // namespace BluezQt + +#endif // BLUEZQT_MEDIA_H diff --git a/src/media.cpp b/src/media.cpp new file mode 100644 --- /dev/null +++ b/src/media.cpp @@ -0,0 +1,77 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "media.h" +#include "media_p.h" +#include "mediaendpoint.h" +#include "mediaendpointadaptor.h" +#include "pendingcall.h" +#include "utils.h" +#include "debug.h" + +namespace BluezQt +{ + +Media::Media(QObject *parent) + : QObject(parent) + , d(new MediaPrivate(this)) +{ +} + +Media::~Media() +{ + delete d; +} + +PendingCall *Media::registerEndpoint(MediaEndpoint *endpoint) +{ + Q_ASSERT(endpoint); + + if (!d->m_bluezMedia) { + return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!")); + } + + new MediaEndpointAdaptor(endpoint); + + if (!DBusConnection::orgBluez().registerObject(endpoint->objectPath().path(), endpoint)) { + qCDebug(BLUEZQT) << "Cannot register object" << endpoint->objectPath().path(); + } + + return new PendingCall(d->m_bluezMedia->RegisterEndpoint(endpoint->objectPath(), endpoint->properties()), + PendingCall::ReturnVoid, this); +} + +PendingCall *Media::unregisterEndpoint(MediaEndpoint *endpoint) +{ + Q_ASSERT(endpoint); + + if (!d->m_bluezMedia) { + return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!")); + } + + DBusConnection::orgBluez().unregisterObject(endpoint->objectPath().path()); + + return new PendingCall(d->m_bluezMedia->UnregisterEndpoint(endpoint->objectPath()), + PendingCall::ReturnVoid, this); +} + +} // namespace BluezQt diff --git a/src/media_p.h b/src/media_p.h new file mode 100644 --- /dev/null +++ b/src/media_p.h @@ -0,0 +1,48 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIA_P_H +#define BLUEZQT_MEDIA_P_H + +#include "bluezmedia1.h" + +namespace BluezQt +{ + +typedef org::bluez::Media1 BluezMedia; + +class Media; + +class MediaPrivate : public QObject +{ + Q_OBJECT + +public: + explicit MediaPrivate(Media *q); + + Media *q; + BluezMedia *m_bluezMedia; +}; + +} // namespace BluezQt + +#endif // BLUEZQT_MEDIA_P_H diff --git a/src/media_p.cpp b/src/media_p.cpp new file mode 100644 --- /dev/null +++ b/src/media_p.cpp @@ -0,0 +1,35 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "media_p.h" +#include "media.h" + +namespace BluezQt +{ + +MediaPrivate::MediaPrivate(Media *q) + : QObject(q) + , q(q) +{ +} + +} // namespace BluezQt diff --git a/src/mediaendpoint.h b/src/mediaendpoint.h new file mode 100644 --- /dev/null +++ b/src/mediaendpoint.h @@ -0,0 +1,119 @@ +/* + * BluezQt - Asynchronous BlueZ wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIAENDPOINT_H +#define BLUEZQT_MEDIAENDPOINT_H + +#include + +#include "bluezqt_export.h" + +class QDBusObjectPath; + +namespace BluezQt +{ + +class TransportPtr; + +/** + * @class BluezQt::MediaEndpoint MediaEndpoint.h + * + * Bluetooth MediaEndpoint. + * + * This class represents a Bluetooth MediaEndpoint. + * + * @note The return value of requests will be sent asynchronously with Request class. + * It is also possible to cancel/reject all requests. + */ +class BLUEZQT_EXPORT MediaEndpoint : public QObject +{ + Q_OBJECT + +public: + /** + * Creates a new MediaEndpoint object. + * + * @param parent + */ + explicit MediaEndpoint(QObject *parent = nullptr); + + /** + * D-Bus object path of the MediaEndpoint. + * + * The path where the MediaEndpoint will be registered. + * + * @note You must provide valid object path! + * + * @return object path of MediaEndpoint + */ + virtual QDBusObjectPath objectPath() const = 0; + + /** + * Properties of the endpoint. + * + * @return Properties of the endpoint + */ + virtual QVariantMap properties() const = 0; + + /** + * Set configuration for the transport. + * + * @param transport transport to be configured + * @param properties properties to be set for transport + */ + virtual void setConfiguration(const QString& transportObjectPath, const QVariantMap& properties); + + /** + * Select preferable configuration from the supported capabilities. + * + * @note There is no need to cache the selected configuration since on success + * the configuration is send back as parameter of SetConfiguration. + * + * @param capabilities supported capabilities + * @return configuration which can be used to setup a transport + */ + virtual QByteArray selectConfiguration(const QByteArray& capabilities) const = 0; + + /** + * Clear transport configuration. + */ + virtual void clearConfiguration(const QString& transportObjectPath); + + /** + * Indicates that the MediaEndpoint was unregistered. + * + * This method gets called when the Bluetooth daemon + * unregisters the MediaEndpoint. + * + * An MediaEndpoint can use it to do cleanup tasks. There is no need + * to unregister the MediaEndpoint, because when this method gets called + * it has already been unregistered. + */ + virtual void release(); + +private: + friend class Media; +}; + +} // namespace BluezQt + +#endif // BLUEZQT_MEDIAENDPOINT_H diff --git a/src/mediaendpoint.cpp b/src/mediaendpoint.cpp new file mode 100644 --- /dev/null +++ b/src/mediaendpoint.cpp @@ -0,0 +1,47 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "mediaendpoint.h" + +#include + +namespace BluezQt +{ + +MediaEndpoint::MediaEndpoint(QObject *parent) + : QObject(parent) +{ +} + +void MediaEndpoint::setConfiguration(const QString& /*transportObjectPath*/, const QVariantMap& /*properties*/) +{ +} + +void MediaEndpoint::clearConfiguration(const QString& /*transportObjectPath*/) +{ +} + +void MediaEndpoint::release() +{ +} + +} // namespace BluezQt diff --git a/src/mediaendpoint_p.h b/src/mediaendpoint_p.h new file mode 100644 --- /dev/null +++ b/src/mediaendpoint_p.h @@ -0,0 +1,39 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIAENDPOINT_P_H +#define BLUEZQT_MEDIAENDPOINT_P_H + +#include + +namespace BluezQt +{ + +class MediaEndpointPrivate +{ +public: + QVariantMap properties; +}; + +} // namepsace BluezQt + +#endif // BLUEZQT_MEDIAENDPOINT_P_H diff --git a/src/mediaendpointadaptor.h b/src/mediaendpointadaptor.h new file mode 100644 --- /dev/null +++ b/src/mediaendpointadaptor.h @@ -0,0 +1,55 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIAENDPOINTADAPTOR_H +#define BLUEZQT_MEDIAENDPOINTADAPTOR_H + +#include + +class QDBusObjectPath; + +namespace BluezQt +{ + +class MediaEndpoint; + +class MediaEndpointAdaptor : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.bluez.MediaEndpoint1") + +public: + explicit MediaEndpointAdaptor(MediaEndpoint *parent); + +public Q_SLOTS: + void SetConfiguration(const QDBusObjectPath &transport, const QVariantMap &properties); + QByteArray SelectConfiguration(const QByteArray &capabilities); + void ClearConfiguration(const QDBusObjectPath &transport); + Q_NOREPLY void Release(); + +private: + MediaEndpoint *m_endpoint; +}; + +} // namespace BluezQt + +#endif // BLUEZQT_MEDIAENDPOINTADAPTOR_H diff --git a/src/mediaendpointadaptor.cpp b/src/mediaendpointadaptor.cpp new file mode 100644 --- /dev/null +++ b/src/mediaendpointadaptor.cpp @@ -0,0 +1,57 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "mediaendpointadaptor.h" +#include "mediaendpoint.h" + +#include + +namespace BluezQt +{ + +MediaEndpointAdaptor::MediaEndpointAdaptor(MediaEndpoint *parent) + : QDBusAbstractAdaptor(parent) + , m_endpoint(parent) +{ +} + +void MediaEndpointAdaptor::SetConfiguration(const QDBusObjectPath &transport, const QVariantMap &properties) +{ + m_endpoint->setConfiguration(transport.path(), properties); +} + +QByteArray MediaEndpointAdaptor::SelectConfiguration(const QByteArray &capabilities) +{ + return m_endpoint->selectConfiguration(capabilities); +} + +void MediaEndpointAdaptor::ClearConfiguration(const QDBusObjectPath &transport) +{ + m_endpoint->clearConfiguration(transport.path()); +} + +void MediaEndpointAdaptor::Release() +{ + m_endpoint->release(); +} + +} // namespace BluezQt diff --git a/src/pendingcall.h b/src/pendingcall.h --- a/src/pendingcall.h +++ b/src/pendingcall.h @@ -192,6 +192,7 @@ friend class Manager; friend class Adapter; friend class Device; + friend class Media; friend class MediaPlayer; friend class ObexManager; friend class ObexTransfer;