1/*
2 * BluezQt - Asynchronous Bluez wrapper library
3 *
4 * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "obexagentadaptor.h"
10#include "dbusproperties.h"
11#include "obexagent.h"
12#include "obexmanager.h"
13#include "obextransfer.h"
14#include "obextransfer_p.h"
15#include "utils.h"
16
17#include <QDBusObjectPath>
18
19namespace BluezQt
20{
21typedef org::freedesktop::DBus::Properties DBusProperties;
22
23ObexAgentAdaptor::ObexAgentAdaptor(ObexAgent *parent, ObexManager *manager)
24 : QDBusAbstractAdaptor(parent)
25 , m_agent(parent)
26 , m_manager(manager)
27{
28}
29
30QString ObexAgentAdaptor::AuthorizePush(const QDBusObjectPath &transfer, const QDBusMessage &msg)
31{
32 msg.setDelayedReply(true);
33 m_transferRequest = Request<QString>(OrgBluezObexAgent, msg);
34 m_transferPath = transfer.path();
35
36 DBusProperties dbusProperties(Strings::orgBluezObex(), m_transferPath, DBusConnection::orgBluezObex(), this);
37
38 const QDBusPendingReply<QVariantMap> &call = dbusProperties.GetAll(interface_name: Strings::orgBluezObexTransfer1());
39 QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
40 connect(sender: watcher, signal: &QDBusPendingCallWatcher::finished, context: this, slot: &ObexAgentAdaptor::getPropertiesFinished);
41
42 return QString();
43}
44
45void ObexAgentAdaptor::Cancel()
46{
47 m_agent->cancel();
48}
49
50void ObexAgentAdaptor::Release()
51{
52 m_agent->release();
53}
54
55void ObexAgentAdaptor::getPropertiesFinished(QDBusPendingCallWatcher *watcher)
56{
57 const QDBusPendingReply<QVariantMap> &reply = *watcher;
58 watcher->deleteLater();
59
60 if (reply.isError()) {
61 m_transferRequest.cancel();
62 return;
63 }
64
65 ObexTransferPtr transfer = ObexTransferPtr(new ObexTransfer(m_transferPath, reply.value()));
66 transfer->d->q = transfer.toWeakRef();
67
68 ObexSessionPtr session = m_manager->sessionForPath(path: transfer->objectPath());
69 Q_ASSERT(session);
70
71 if (!session) {
72 m_transferRequest.cancel();
73 return;
74 }
75
76 m_agent->authorizePush(transfer, session, request: m_transferRequest);
77}
78
79} // namespace BluezQt
80
81#include "moc_obexagentadaptor.cpp"
82

source code of bluez-qt/src/obexagentadaptor.cpp