| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2014-2015 David Rosca <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "agentmanager.h" |
| 8 |
|
| 9 |
#include <QDBusConnection> |
| 10 |
#include <QDBusMessage> |
| 11 |
#include <QDBusPendingCall> |
| 12 |
#include <QDebug> |
| 13 |
|
| 14 |
AgentManager::AgentManager(QObject *parent) |
| 15 |
: QDBusAbstractAdaptor(parent) |
| 16 |
{ |
| 17 |
setName(QStringLiteral("org.bluez.AgentManager1")); |
| 18 |
setPath(QDBusObjectPath(QStringLiteral("/org/bluez"))); |
| 19 |
} |
| 20 |
|
| 21 |
void AgentManager::runAction(const QString &actionName, const QVariantMap &properties) |
| 22 |
{ |
| 23 |
if (actionName == QLatin1String("request-pincode")) { |
| 24 |
runRequestPinCodeAction(properties); |
| 25 |
} else if (actionName == QLatin1String("display-pincode")) { |
| 26 |
runDisplayPinCodeAction(properties); |
| 27 |
} else if (actionName == QLatin1String("request-passkey")) { |
| 28 |
runRequestPasskeyAction(properties); |
| 29 |
} else if (actionName == QLatin1String("display-passkey")) { |
| 30 |
runDisplayPasskeyAction(properties); |
| 31 |
} else if (actionName == QLatin1String("request-confirmation")) { |
| 32 |
runRequestConfirmationAction(properties); |
| 33 |
} else if (actionName == QLatin1String("request-authorization")) { |
| 34 |
runRequestAuthorizationAction(properties); |
| 35 |
} else if (actionName == QLatin1String("authorize-service")) { |
| 36 |
runAuthorizeServiceAction(properties); |
| 37 |
} else if (actionName == QLatin1String("cancel")) { |
| 38 |
runCancelAction(); |
| 39 |
} else if (actionName == QLatin1String("release")) { |
| 40 |
runReleaseAction(); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
void AgentManager::RegisterAgent(const QDBusObjectPath &path, const QString &capability, const QDBusMessage &msg) |
| 45 |
{ |
| 46 |
m_agent = path; |
| 47 |
m_service = msg.service(); |
| 48 |
m_capability = capability; |
| 49 |
} |
| 50 |
|
| 51 |
void AgentManager::UnregisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg) |
| 52 |
{ |
| 53 |
if (m_agent == path && m_service == msg.service()) { |
| 54 |
m_agent = QDBusObjectPath(); |
| 55 |
m_service.clear(); |
| 56 |
m_capability.clear(); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
void AgentManager::RequestDefaultAgent(const QDBusObjectPath &path) |
| 61 |
{ |
| 62 |
qDebug() << "RequestDefaultAgent" << path.path(); |
| 63 |
} |
| 64 |
|
| 65 |
void AgentManager::runRequestPinCodeAction(const QVariantMap &properties) |
| 66 |
{ |
| 67 |
QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("RequestPinCode")); |
| 68 |
|
| 69 |
call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value<QDBusObjectPath>()); |
| 70 |
QDBusConnection::sessionBus().asyncCall(call); |
| 71 |
} |
| 72 |
|
| 73 |
void AgentManager::runDisplayPinCodeAction(const QVariantMap &properties) |
| 74 |
{ |
| 75 |
QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("DisplayPinCode")); |
| 76 |
|
| 77 |
call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value<QDBusObjectPath>()); |
| 78 |
call << properties.value(QStringLiteral("PinCode")); |
| 79 |
QDBusConnection::sessionBus().asyncCall(call); |
| 80 |
} |
| 81 |
|
| 82 |
void AgentManager::runRequestPasskeyAction(const QVariantMap &properties) |
| 83 |
{ |
| 84 |
QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("RequestPasskey")); |
| 85 |
|
| 86 |
call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value<QDBusObjectPath>()); |
| 87 |
QDBusConnection::sessionBus().asyncCall(call); |
| 88 |
} |
| 89 |
|
| 90 |
void AgentManager::runDisplayPasskeyAction(const QVariantMap &properties) |
| 91 |
{ |
| 92 |
QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("DisplayPasskey")); |
| 93 |
|
| 94 |
call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value<QDBusObjectPath>()); |
| 95 |
call << properties.value(QStringLiteral("Passkey")); |
| 96 |
call << properties.value(QStringLiteral("EnteredPasskey")); |
| 97 |
QDBusConnection::sessionBus().asyncCall(call); |
| 98 |
} |
| 99 |
|
| 100 |
void AgentManager::runRequestConfirmationAction(const QVariantMap &properties) |
| 101 |
{ |
| 102 |
QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("RequestConfirmation")); |
| 103 |
|
| 104 |
call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value<QDBusObjectPath>()); |
| 105 |
call << properties.value(QStringLiteral("Passkey")); |
| 106 |
QDBusConnection::sessionBus().asyncCall(call); |
| 107 |
} |
| 108 |
|
| 109 |
void AgentManager::runRequestAuthorizationAction(const QVariantMap &properties) |
| 110 |
{ |
| 111 |
QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("RequestAuthorization")); |
| 112 |
|
| 113 |
call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value<QDBusObjectPath>()); |
| 114 |
QDBusConnection::sessionBus().asyncCall(call); |
| 115 |
} |
| 116 |
|
| 117 |
void AgentManager::runAuthorizeServiceAction(const QVariantMap &properties) |
| 118 |
{ |
| 119 |
QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("AuthorizeService")); |
| 120 |
|
| 121 |
call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value<QDBusObjectPath>()); |
| 122 |
call << properties.value(QStringLiteral("UUID")); |
| 123 |
QDBusConnection::sessionBus().asyncCall(call); |
| 124 |
} |
| 125 |
|
| 126 |
void AgentManager::runCancelAction() |
| 127 |
{ |
| 128 |
QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("Cancel")); |
| 129 |
QDBusConnection::sessionBus().asyncCall(call); |
| 130 |
} |
| 131 |
|
| 132 |
void AgentManager::runReleaseAction() |
| 133 |
{ |
| 134 |
QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("Release")); |
| 135 |
QDBusConnection::sessionBus().asyncCall(call); |
| 136 |
} |
| 137 |
|
| 138 |
#include "moc_agentmanager.cpp" |