BluezQt

obexagentadaptor.cpp
1 /*
2  * BluezQt - Asynchronous Bluez wrapper library
3  *
4  * SPDX-FileCopyrightText: 2014-2015 David Rosca <[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 "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 
19 namespace BluezQt
20 {
21 typedef org::freedesktop::DBus::Properties DBusProperties;
22 
23 ObexAgentAdaptor::ObexAgentAdaptor(ObexAgent *parent, ObexManager *manager)
24  : QDBusAbstractAdaptor(parent)
25  , m_agent(parent)
26  , m_manager(manager)
27 {
28 }
29 
30 QString 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(Strings::orgBluezObexTransfer1());
39  QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
40  connect(watcher, &QDBusPendingCallWatcher::finished, this, &ObexAgentAdaptor::getPropertiesFinished);
41 
42  return QString();
43 }
44 
45 void ObexAgentAdaptor::Cancel()
46 {
47  m_agent->cancel();
48 }
49 
50 void ObexAgentAdaptor::Release()
51 {
52  m_agent->release();
53 }
54 
55 void 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(transfer->objectPath());
69  Q_ASSERT(session);
70 
71  if (!session) {
72  m_transferRequest.cancel();
73  return;
74  }
75 
76  m_agent->authorizePush(transfer, session, m_transferRequest);
77 }
78 
79 } // namespace BluezQt
void finished(QDBusPendingCallWatcher *self)
void setDelayedReply(bool enable) const const
bool isError() const const
void deleteLater()
T1 value() const const
QString path() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Sep 25 2022 04:19:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.