File indexing completed on 2024-04-28 15:17:54

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()
0028 {
0029     delete d;
0030 }
0031 
0032 PendingCall *Media::registerEndpoint(MediaEndpoint *endpoint)
0033 {
0034     Q_ASSERT(endpoint);
0035 
0036     if (!d->m_bluezMedia) {
0037         return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!"));
0038     }
0039 
0040     new MediaEndpointAdaptor(endpoint);
0041 
0042     if (!DBusConnection::orgBluez().registerObject(endpoint->objectPath().path(), endpoint)) {
0043         qCDebug(BLUEZQT) << "Cannot register object" << endpoint->objectPath().path();
0044     }
0045 
0046     return new PendingCall(d->m_bluezMedia->RegisterEndpoint(endpoint->objectPath(), endpoint->properties()), PendingCall::ReturnVoid, this);
0047 }
0048 
0049 PendingCall *Media::unregisterEndpoint(MediaEndpoint *endpoint)
0050 {
0051     Q_ASSERT(endpoint);
0052 
0053     if (!d->m_bluezMedia) {
0054         return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!"));
0055     }
0056 
0057     DBusConnection::orgBluez().unregisterObject(endpoint->objectPath().path());
0058 
0059     return new PendingCall(d->m_bluezMedia->UnregisterEndpoint(endpoint->objectPath()), PendingCall::ReturnVoid, this);
0060 }
0061 
0062 } // namespace BluezQt
0063 
0064 #include "moc_media.cpp"