| 1 |
/* |
| 2 |
* BluezQt - Asynchronous Bluez wrapper library |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer <[email protected]> |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "media.h" |
| 10 |
#include "debug.h" |
| 11 |
#include "media_p.h" |
| 12 |
#include "mediaendpoint.h" |
| 13 |
#include "mediaendpointadaptor.h" |
| 14 |
#include "pendingcall.h" |
| 15 |
#include "utils.h" |
| 16 |
|
| 17 |
namespace BluezQt |
| 18 |
{ |
| 19 |
Media::Media(const QString &path, QObject *parent) |
| 20 |
: QObject(parent) |
| 21 |
, d(new MediaPrivate()) |
| 22 |
{ |
| 23 |
d->m_path = path; |
| 24 |
d->m_bluezMedia = new BluezMedia(Strings::orgBluez(), path, DBusConnection::orgBluez(), this); |
| 25 |
} |
| 26 |
|
| 27 |
Media::~Media() = default; |
| 28 |
|
| 29 |
PendingCall *Media::registerEndpoint(MediaEndpoint *endpoint) |
| 30 |
{ |
| 31 |
Q_ASSERT(endpoint); |
| 32 |
|
| 33 |
if (!d->m_bluezMedia) { |
| 34 |
return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!")); |
| 35 |
} |
| 36 |
|
| 37 |
new MediaEndpointAdaptor(endpoint); |
| 38 |
|
| 39 |
if (!DBusConnection::orgBluez().registerObject(endpoint->objectPath().path(), endpoint)) { |
| 40 |
qCDebug(BLUEZQT) << "Cannot register object" << endpoint->objectPath().path(); |
| 41 |
} |
| 42 |
|
| 43 |
return new PendingCall(d->m_bluezMedia->RegisterEndpoint(endpoint->objectPath(), endpoint->properties()), PendingCall::ReturnVoid, this); |
| 44 |
} |
| 45 |
|
| 46 |
PendingCall *Media::unregisterEndpoint(MediaEndpoint *endpoint) |
| 47 |
{ |
| 48 |
Q_ASSERT(endpoint); |
| 49 |
|
| 50 |
if (!d->m_bluezMedia) { |
| 51 |
return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!")); |
| 52 |
} |
| 53 |
|
| 54 |
DBusConnection::orgBluez().unregisterObject(endpoint->objectPath().path()); |
| 55 |
|
| 56 |
return new PendingCall(d->m_bluezMedia->UnregisterEndpoint(endpoint->objectPath()), PendingCall::ReturnVoid, this); |
| 57 |
} |
| 58 |
|
| 59 |
} // namespace BluezQt |
| 60 |
|
| 61 |
#include "moc_media.cpp" |