File indexing completed on 2024-12-01 12:29:50

0001 /*
0002  * BluezQt - Asynchronous Bluez wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "obexagentadaptor.h"
0010 #include "dbusproperties.h"
0011 #include "obexagent.h"
0012 #include "obexmanager.h"
0013 #include "obextransfer.h"
0014 #include "obextransfer_p.h"
0015 #include "utils.h"
0016 
0017 #include <QDBusObjectPath>
0018 
0019 namespace BluezQt
0020 {
0021 typedef org::freedesktop::DBus::Properties DBusProperties;
0022 
0023 ObexAgentAdaptor::ObexAgentAdaptor(ObexAgent *parent, ObexManager *manager)
0024     : QDBusAbstractAdaptor(parent)
0025     , m_agent(parent)
0026     , m_manager(manager)
0027 {
0028 }
0029 
0030 QString ObexAgentAdaptor::AuthorizePush(const QDBusObjectPath &transfer, const QDBusMessage &msg)
0031 {
0032     msg.setDelayedReply(true);
0033     m_transferRequest = Request<QString>(OrgBluezObexAgent, msg);
0034     m_transferPath = transfer.path();
0035 
0036     DBusProperties dbusProperties(Strings::orgBluezObex(), m_transferPath, DBusConnection::orgBluezObex(), this);
0037 
0038     const QDBusPendingReply<QVariantMap> &call = dbusProperties.GetAll(Strings::orgBluezObexTransfer1());
0039     QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
0040     connect(watcher, &QDBusPendingCallWatcher::finished, this, &ObexAgentAdaptor::getPropertiesFinished);
0041 
0042     return QString();
0043 }
0044 
0045 void ObexAgentAdaptor::Cancel()
0046 {
0047     m_agent->cancel();
0048 }
0049 
0050 void ObexAgentAdaptor::Release()
0051 {
0052     m_agent->release();
0053 }
0054 
0055 void ObexAgentAdaptor::getPropertiesFinished(QDBusPendingCallWatcher *watcher)
0056 {
0057     const QDBusPendingReply<QVariantMap> &reply = *watcher;
0058     watcher->deleteLater();
0059 
0060     if (reply.isError()) {
0061         m_transferRequest.cancel();
0062         return;
0063     }
0064 
0065     ObexTransferPtr transfer = ObexTransferPtr(new ObexTransfer(m_transferPath, reply.value()));
0066     transfer->d->q = transfer.toWeakRef();
0067 
0068     ObexSessionPtr session = m_manager->sessionForPath(transfer->objectPath());
0069     Q_ASSERT(session);
0070 
0071     if (!session) {
0072         m_transferRequest.cancel();
0073         return;
0074     }
0075 
0076     m_agent->authorizePush(transfer, session, m_transferRequest);
0077 }
0078 
0079 } // namespace BluezQt
0080 
0081 #include "moc_obexagentadaptor.cpp"