File indexing completed on 2024-12-01 12:29:46
0001 /* 0002 * BluezQt - Asynchronous BlueZ wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2014-2015 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 #ifndef BLUEZQT_AGENT_H 0010 #define BLUEZQT_AGENT_H 0011 0012 #include <QObject> 0013 0014 #include "bluezqt_export.h" 0015 #include "request.h" 0016 #include "types.h" 0017 0018 class QDBusObjectPath; 0019 0020 namespace BluezQt 0021 { 0022 class Device; 0023 0024 /** 0025 * @class BluezQt::Agent agent.h <BluezQt/Agent> 0026 * 0027 * Bluetooth agent. 0028 * 0029 * This class represents a Bluetooth agent. 0030 * 0031 * The agent is used in pairing process to do various actions. 0032 * 0033 * @note The return value of requests will be sent asynchronously with Request class. 0034 * It is also possible to cancel/reject all requests. 0035 */ 0036 class BLUEZQT_EXPORT Agent : public QObject 0037 { 0038 Q_OBJECT 0039 0040 Q_PROPERTY(Capability capability READ capability) 0041 0042 public: 0043 /** 0044 * The input/output capabilities of Agent. 0045 */ 0046 enum Capability { 0047 DisplayOnly = 0, 0048 DisplayYesNo = 1, 0049 KeyboardOnly = 2, 0050 NoInputNoOutput = 3, 0051 }; 0052 Q_ENUM(Capability) 0053 0054 /** 0055 * Creates a new Agent object. 0056 * 0057 * @param parent 0058 */ 0059 explicit Agent(QObject *parent = nullptr); 0060 0061 /** 0062 * D-Bus object path of the agent. 0063 * 0064 * The path where the agent will be registered. 0065 * 0066 * @note You must provide valid object path! 0067 * 0068 * @return object path of agent 0069 */ 0070 virtual QDBusObjectPath objectPath() const = 0; 0071 0072 /** 0073 * Input/output capability of the agent. 0074 * 0075 * By default, this method returns DisplayYesNo. 0076 * 0077 * @return capability of agent 0078 */ 0079 virtual Capability capability() const; 0080 0081 /** 0082 * Requests a PIN code from the agent. 0083 * 0084 * This method gets called when the Bluetooth daemon 0085 * needs to get the PIN code for an authentication. 0086 * 0087 * The return value should be a string of 1-16 characters 0088 * length. The string can be alphanumeric. 0089 * 0090 * @param device device that invoked the action 0091 * @param request request to be used for sending reply 0092 */ 0093 virtual void requestPinCode(DevicePtr device, const Request<QString> &request); 0094 0095 /** 0096 * Requests the agent to display a PIN code. 0097 * 0098 * This method gets called when the Bluetooth daemon 0099 * needs to display a pincode for an authentication. 0100 * 0101 * When the PIN code needs no longer to be displayed, 0102 * the cancel() method will be called. 0103 * 0104 * @param device device that invoked the action 0105 * @param pinCode PIN code to be displayed 0106 */ 0107 virtual void displayPinCode(DevicePtr device, const QString &pinCode); 0108 0109 /** 0110 * Requests a passkey from the agent. 0111 * 0112 * This method gets called when the Bluetooth daemon 0113 * needs to get the passkey for an authentication. 0114 * 0115 * The return value should be a numeric value between 0-999999. 0116 * 0117 * @param device device that invoked the action 0118 * @param request request to be used for sending reply 0119 */ 0120 virtual void requestPasskey(DevicePtr device, const Request<quint32> &request); 0121 0122 /** 0123 * Requests the agent to display a passkey. 0124 * 0125 * This method gets called when the Bluetooth daemon 0126 * needs to display a passkey for an authentication. 0127 * 0128 * When the passkey needs no longer to be displayed, 0129 * the cancel() method will be called. 0130 * 0131 * @param device device that invoked the action 0132 * @param passkey passkey to be displayed 0133 * @param entered number of already typed keys on the remote side 0134 */ 0135 virtual void displayPasskey(DevicePtr device, const QString &passkey, const QString &entered); 0136 0137 /** 0138 * Requests the agent to confirm a passkey. 0139 * 0140 * This method gets called when the Bluetooth daemon 0141 * needs to confirm a passkey for an authentication. 0142 * 0143 * @param device device that invoked the action 0144 * @param passkey passkey to be confirmed 0145 * @param request request to be used for sending reply 0146 */ 0147 virtual void requestConfirmation(DevicePtr device, const QString &passkey, const Request<> &request); 0148 0149 /** 0150 * Requests the agent to authorize an incoming pairing attempt. 0151 * 0152 * This method gets called to request the user to authorize 0153 * an incoming pairing attempt which would in other circumstances 0154 * trigger the just-works model. 0155 * 0156 * @param device device that invoked the action 0157 * @param request request to be used for sending reply 0158 */ 0159 virtual void requestAuthorization(DevicePtr device, const Request<> &request); 0160 0161 /** 0162 * Requests the agent to authorize a connection/service request. 0163 * 0164 * This method gets called when the Bluetooth daemon 0165 * needs to authorize a connection/service request. 0166 * 0167 * @param device device that invoked the action 0168 * @param uuid UUID of service 0169 * @param request request to be used for sending reply 0170 */ 0171 virtual void authorizeService(DevicePtr device, const QString &uuid, const Request<> &request); 0172 0173 /** 0174 * Indicate that the agent request failed before receiving reply. 0175 * 0176 * This method gets called to indicate that the agent 0177 * request failed before a reply was returned. 0178 * 0179 * It cancels the previous request. 0180 */ 0181 virtual void cancel(); 0182 0183 /** 0184 * Indicates that the agent was unregistered. 0185 * 0186 * This method gets called when the Bluetooth daemon 0187 * unregisters the agent. 0188 * 0189 * An agent can use it to do cleanup tasks. There is no need 0190 * to unregister the agent, because when this method gets called 0191 * it has already been unregistered. 0192 */ 0193 virtual void release(); 0194 }; 0195 0196 } // namespace BluezQt 0197 0198 #endif // BLUEZQT_AGENT_H