BluezQt

agentadaptor.cpp
1/*
2 * BluezQt - Asynchronous Bluez wrapper library
3 *
4 * SPDX-FileCopyrightText: 2014 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 "agentadaptor.h"
10#include "adapter.h"
11#include "agent.h"
12#include "device.h"
13#include "manager.h"
14#include "request.h"
15
16#include <QDBusMessage>
17#include <QDBusObjectPath>
18
19namespace BluezQt
20{
21AgentAdaptor::AgentAdaptor(Agent *parent, Manager *manager)
22 : QDBusAbstractAdaptor(parent)
23 , m_agent(parent)
24 , m_manager(manager)
25{
26}
27
28QString AgentAdaptor::RequestPinCode(const QDBusObjectPath &device, const QDBusMessage &msg)
29{
30 msg.setDelayedReply(true);
31 Request<QString> req(OrgBluezAgent, msg);
32
33 DevicePtr dev = m_manager->deviceForUbi(device.path());
34 if (!dev) {
35 req.cancel();
36 return QString();
37 }
38
39 m_agent->requestPinCode(dev, req);
40 return QString();
41}
42
43void AgentAdaptor::DisplayPinCode(const QDBusObjectPath &device, const QString &pincode)
44{
45 DevicePtr dev = m_manager->deviceForUbi(device.path());
46 if (!dev) {
47 return;
48 }
49
50 m_agent->displayPinCode(dev, pincode);
51}
52
53quint32 AgentAdaptor::RequestPasskey(const QDBusObjectPath &device, const QDBusMessage &msg)
54{
55 msg.setDelayedReply(true);
56 Request<quint32> req(OrgBluezAgent, msg);
57
58 DevicePtr dev = m_manager->deviceForUbi(device.path());
59 if (!dev) {
60 req.cancel();
61 return 0;
62 }
63
64 m_agent->requestPasskey(dev, req);
65 return 0;
66}
67
68void AgentAdaptor::DisplayPasskey(const QDBusObjectPath &device, quint32 passkey, quint16 entered)
69{
70 DevicePtr dev = m_manager->deviceForUbi(device.path());
71 if (!dev) {
72 return;
73 }
74
75 m_agent->displayPasskey(dev, passkeyToString(passkey), QString::number(entered));
76}
77
78void AgentAdaptor::RequestConfirmation(const QDBusObjectPath &device, quint32 passkey, const QDBusMessage &msg)
79{
80 msg.setDelayedReply(true);
81 Request<> req(OrgBluezAgent, msg);
82
83 DevicePtr dev = m_manager->deviceForUbi(device.path());
84 if (!dev) {
85 req.cancel();
86 return;
87 }
88
89 m_agent->requestConfirmation(dev, passkeyToString(passkey), req);
90}
91
92void AgentAdaptor::RequestAuthorization(const QDBusObjectPath &device, const QDBusMessage &msg)
93{
94 msg.setDelayedReply(true);
95 Request<> req(OrgBluezAgent, msg);
96
97 DevicePtr dev = m_manager->deviceForUbi(device.path());
98 if (!dev) {
99 req.cancel();
100 return;
101 }
102
103 m_agent->requestAuthorization(dev, req);
104}
105
106void AgentAdaptor::AuthorizeService(const QDBusObjectPath &device, const QString &uuid, const QDBusMessage &msg)
107{
108 msg.setDelayedReply(true);
109 Request<> req(OrgBluezAgent, msg);
110
111 DevicePtr dev = m_manager->deviceForUbi(device.path());
112 if (!dev) {
113 req.cancel();
114 return;
115 }
116
117 m_agent->authorizeService(dev, uuid.toUpper(), req);
118}
119
120void AgentAdaptor::Cancel()
121{
122 m_agent->cancel();
123}
124
125void AgentAdaptor::Release()
126{
127 m_agent->release();
128}
129
130QString AgentAdaptor::passkeyToString(quint32 passkey) const
131{
132 // Passkey will always be a 6-digit number, zero-pad it at the start
133 return QStringLiteral("%1").arg(passkey, 6, 10, QLatin1Char('0'));
134}
135
136} // namespace BluezQt
137
138#include "moc_agentadaptor.cpp"
void setDelayedReply(bool enable) const const
QString path() const const
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)
QString toUpper() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:46:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.