File indexing completed on 2024-05-05 03:52:31

0001 /*
0002  * BluezQt - Asynchronous Bluez wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer <mincequi@web.de>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "media.h"
0010 #include "debug.h"
0011 #include "media_p.h"
0012 #include "mediaendpoint.h"
0013 #include "mediaendpointadaptor.h"
0014 #include "pendingcall.h"
0015 #include "utils.h"
0016 
0017 namespace BluezQt
0018 {
0019 Media::Media(const QString &path, QObject *parent)
0020     : QObject(parent)
0021     , d(new MediaPrivate())
0022 {
0023     d->m_path = path;
0024     d->m_bluezMedia = new BluezMedia(Strings::orgBluez(), path, DBusConnection::orgBluez(), this);
0025 }
0026 
0027 Media::~Media() = default;
0028 
0029 PendingCall *Media::registerEndpoint(MediaEndpoint *endpoint)
0030 {
0031     Q_ASSERT(endpoint);
0032 
0033     if (!d->m_bluezMedia) {
0034         return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!"));
0035     }
0036 
0037     new MediaEndpointAdaptor(endpoint);
0038 
0039     if (!DBusConnection::orgBluez().registerObject(endpoint->objectPath().path(), endpoint)) {
0040         qCDebug(BLUEZQT) << "Cannot register object" << endpoint->objectPath().path();
0041     }
0042 
0043     return new PendingCall(d->m_bluezMedia->RegisterEndpoint(endpoint->objectPath(), endpoint->properties()), PendingCall::ReturnVoid, this);
0044 }
0045 
0046 PendingCall *Media::unregisterEndpoint(MediaEndpoint *endpoint)
0047 {
0048     Q_ASSERT(endpoint);
0049 
0050     if (!d->m_bluezMedia) {
0051         return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!"));
0052     }
0053 
0054     DBusConnection::orgBluez().unregisterObject(endpoint->objectPath().path());
0055 
0056     return new PendingCall(d->m_bluezMedia->UnregisterEndpoint(endpoint->objectPath()), PendingCall::ReturnVoid, this);
0057 }
0058 
0059 } // namespace BluezQt
0060 
0061 #include "moc_media.cpp"