File indexing completed on 2024-12-01 12:29:46
0001 /* 0002 * BluezQt - Asynchronous Bluez wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2014 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 "agentadaptor.h" 0010 #include "adapter.h" 0011 #include "agent.h" 0012 #include "device.h" 0013 #include "manager.h" 0014 #include "request.h" 0015 0016 #include <QDBusMessage> 0017 #include <QDBusObjectPath> 0018 0019 namespace BluezQt 0020 { 0021 AgentAdaptor::AgentAdaptor(Agent *parent, Manager *manager) 0022 : QDBusAbstractAdaptor(parent) 0023 , m_agent(parent) 0024 , m_manager(manager) 0025 { 0026 } 0027 0028 QString AgentAdaptor::RequestPinCode(const QDBusObjectPath &device, const QDBusMessage &msg) 0029 { 0030 msg.setDelayedReply(true); 0031 Request<QString> req(OrgBluezAgent, msg); 0032 0033 DevicePtr dev = m_manager->deviceForUbi(device.path()); 0034 if (!dev) { 0035 req.cancel(); 0036 return QString(); 0037 } 0038 0039 m_agent->requestPinCode(dev, req); 0040 return QString(); 0041 } 0042 0043 void AgentAdaptor::DisplayPinCode(const QDBusObjectPath &device, const QString &pincode) 0044 { 0045 DevicePtr dev = m_manager->deviceForUbi(device.path()); 0046 if (!dev) { 0047 return; 0048 } 0049 0050 m_agent->displayPinCode(dev, pincode); 0051 } 0052 0053 quint32 AgentAdaptor::RequestPasskey(const QDBusObjectPath &device, const QDBusMessage &msg) 0054 { 0055 msg.setDelayedReply(true); 0056 Request<quint32> req(OrgBluezAgent, msg); 0057 0058 DevicePtr dev = m_manager->deviceForUbi(device.path()); 0059 if (!dev) { 0060 req.cancel(); 0061 return 0; 0062 } 0063 0064 m_agent->requestPasskey(dev, req); 0065 return 0; 0066 } 0067 0068 void AgentAdaptor::DisplayPasskey(const QDBusObjectPath &device, quint32 passkey, quint16 entered) 0069 { 0070 DevicePtr dev = m_manager->deviceForUbi(device.path()); 0071 if (!dev) { 0072 return; 0073 } 0074 0075 m_agent->displayPasskey(dev, passkeyToString(passkey), QString::number(entered)); 0076 } 0077 0078 void AgentAdaptor::RequestConfirmation(const QDBusObjectPath &device, quint32 passkey, const QDBusMessage &msg) 0079 { 0080 msg.setDelayedReply(true); 0081 Request<> req(OrgBluezAgent, msg); 0082 0083 DevicePtr dev = m_manager->deviceForUbi(device.path()); 0084 if (!dev) { 0085 req.cancel(); 0086 return; 0087 } 0088 0089 m_agent->requestConfirmation(dev, passkeyToString(passkey), req); 0090 } 0091 0092 void AgentAdaptor::RequestAuthorization(const QDBusObjectPath &device, const QDBusMessage &msg) 0093 { 0094 msg.setDelayedReply(true); 0095 Request<> req(OrgBluezAgent, msg); 0096 0097 DevicePtr dev = m_manager->deviceForUbi(device.path()); 0098 if (!dev) { 0099 req.cancel(); 0100 return; 0101 } 0102 0103 m_agent->requestAuthorization(dev, req); 0104 } 0105 0106 void AgentAdaptor::AuthorizeService(const QDBusObjectPath &device, const QString &uuid, const QDBusMessage &msg) 0107 { 0108 msg.setDelayedReply(true); 0109 Request<> req(OrgBluezAgent, msg); 0110 0111 DevicePtr dev = m_manager->deviceForUbi(device.path()); 0112 if (!dev) { 0113 req.cancel(); 0114 return; 0115 } 0116 0117 m_agent->authorizeService(dev, uuid.toUpper(), req); 0118 } 0119 0120 void AgentAdaptor::Cancel() 0121 { 0122 m_agent->cancel(); 0123 } 0124 0125 void AgentAdaptor::Release() 0126 { 0127 m_agent->release(); 0128 } 0129 0130 QString AgentAdaptor::passkeyToString(quint32 passkey) const 0131 { 0132 // Passkey will always be a 6-digit number, zero-pad it at the start 0133 return QStringLiteral("%1").arg(passkey, 6, 10, QLatin1Char('0')); 0134 } 0135 0136 } // namespace BluezQt 0137 0138 #include "moc_agentadaptor.cpp"