File indexing completed on 2025-01-19 06:44:39
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_PROFILE_H 0010 #define BLUEZQT_PROFILE_H 0011 0012 #include <QObject> 0013 0014 #include "bluezqt_export.h" 0015 #include "request.h" 0016 #include "types.h" 0017 0018 #include <memory> 0019 0020 class QLocalSocket; 0021 class QDBusObjectPath; 0022 class QDBusUnixFileDescriptor; 0023 0024 namespace BluezQt 0025 { 0026 class Device; 0027 0028 /** 0029 * @class BluezQt::Profile profile.h <BluezQt/Profile> 0030 * 0031 * Bluetooth profile. 0032 * 0033 * This class represents a Bluetooth profile. 0034 * 0035 * It is only needed to reimplement pure virtual functions. 0036 * You don't need to set any additional properties. 0037 * 0038 * But you may need to specify at least channel number or PSM in case it couldn't be 0039 * determined from UUID. It is also a good idea to provide name for the profile. 0040 * 0041 * Setting the channel number with setChannel() will make the profile use RFCOMM, while 0042 * setting the PSM with setPsm() will make the profile use L2CAP. 0043 * 0044 * @note The return value of requests will be sent asynchronously with Request class. 0045 * It is also possible to cancel/reject all requests. 0046 * 0047 */ 0048 class BLUEZQT_EXPORT Profile : public QObject 0049 { 0050 Q_OBJECT 0051 0052 Q_PROPERTY(QString uuid READ uuid) 0053 0054 public: 0055 /** Local role to identify sides in asymmetric profiles. */ 0056 enum LocalRole { 0057 /** Indicates that this is a client. */ 0058 ClientRole, 0059 /** Indicates that this is a server. */ 0060 ServerRole, 0061 }; 0062 0063 /** 0064 * Creates a new Profile object. 0065 * 0066 * @param parent 0067 */ 0068 explicit Profile(QObject *parent = nullptr); 0069 0070 /** 0071 * Destroys a Profile object. 0072 */ 0073 ~Profile() override; 0074 0075 /** 0076 * D-Bus object path of the profile. 0077 * 0078 * The path where the profile will be registered. 0079 * 0080 * @note You must provide valid object path! 0081 * 0082 * @return object path of agent 0083 */ 0084 virtual QDBusObjectPath objectPath() const = 0; 0085 0086 /** 0087 * UUID of the profile. 0088 * 0089 * @return UUID of the profile 0090 */ 0091 virtual QString uuid() const = 0; 0092 0093 /** 0094 * Sets the human readable name of the profile. 0095 * 0096 * @param name name of the profile 0097 */ 0098 void setName(const QString &name); 0099 0100 /** 0101 * Sets the primary service class UUID (if different from profile UUID). 0102 * 0103 * @param service service UUID 0104 */ 0105 void setService(const QString &service); 0106 0107 /** 0108 * Sets the local role to identify side. 0109 * 0110 * For asymmetric profiles that do not have UUIDs available 0111 * to uniquely identify each side this parameter allows 0112 * specifying the precise local role. 0113 * 0114 * @param role local role 0115 */ 0116 void setLocalRole(LocalRole role); 0117 0118 /** 0119 * Sets the RFCOMM channel number. 0120 * 0121 * Available channel number range is 0-31. 0122 * Setting channel number to 0 will automatically choose 0123 * correct channel number for profile UUID. 0124 * 0125 * @param channel channel number 0126 */ 0127 void setChannel(quint16 channel); 0128 0129 /** 0130 * Sets the L2CAP port number. 0131 * 0132 * PSM (Protocol Service Multiplexer) is a port number 0133 * in L2CAP. 0134 * 0135 * Setting PSM to 0 will automatically choose correct 0136 * PSM for profile UUID. 0137 * 0138 * @param psm PSM 0139 */ 0140 void setPsm(quint16 psm); 0141 0142 /** 0143 * Sets whether the pairing is required to connect. 0144 * 0145 * @param require require to pair 0146 */ 0147 void setRequireAuthentication(bool require); 0148 0149 /** 0150 * Sets whether the authorization is required to connect. 0151 * 0152 * @param require require to authorize 0153 */ 0154 void setRequireAuthorization(bool require); 0155 0156 /** 0157 * Sets whether the profile is automatically connected. 0158 * 0159 * In case of a client UUID this will force connection 0160 * of the RFCOMM or L2CAP channels when a remote device 0161 * is connected. 0162 * 0163 * @param autoConnect autoconnect the profile 0164 */ 0165 void setAutoConnect(bool autoConnect); 0166 0167 /** 0168 * Sets a SDP record. 0169 * 0170 * This allows to provide a manual SDP record, otherwise it will 0171 * be generated automatically. 0172 * 0173 * @param serviceRecord SDP record 0174 */ 0175 void setServiceRecord(const QString &serviceRecord); 0176 0177 /** 0178 * Sets the profile version. 0179 * 0180 * @param version version of the profile 0181 */ 0182 void setVersion(quint16 version); 0183 0184 /** 0185 * Sets the profile features. 0186 * 0187 * @param features features of the profile 0188 */ 0189 void setFeatures(quint16 features); 0190 0191 /** 0192 * Creates a socket from file descriptor. 0193 * 0194 * @param fd socket file descriptor 0195 * @return socket 0196 * 0197 * @see newConnection() 0198 */ 0199 QSharedPointer<QLocalSocket> createSocket(const QDBusUnixFileDescriptor &fd); 0200 0201 /** 0202 * Requests the new connection. 0203 * 0204 * Common properties: 0205 * <ul> 0206 * <li>quint16 Version - Profile version</li> 0207 * <li>quint16 Features - Profile features</li> 0208 * </ul> 0209 * 0210 * To create socket from fd, you can use: 0211 * @code 0212 * QSharedPointer<QLocalSocket> socket = createSocket(fd); 0213 * if (!socket->isValid()) { 0214 * delete socket; 0215 * request.cancel(); 0216 * return; 0217 * } 0218 * @endcode 0219 * 0220 * @param device device that requested connection 0221 * @param fd socket file descriptor 0222 * @param properties additional properties 0223 * @param request request to be used for sending reply 0224 */ 0225 virtual void newConnection(DevicePtr device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const Request<> &request); 0226 0227 /** 0228 * Requests the disconnection of the profile. 0229 * 0230 * This method gets called when a profile gets disconnected. 0231 * 0232 * @param device device to be disconnected 0233 * @param request request to be used for sending reply 0234 */ 0235 virtual void requestDisconnection(DevicePtr device, const Request<> &request); 0236 0237 /** 0238 * Indicates that the profile was unregistered. 0239 * 0240 * This method gets called when the Bluetooth daemon 0241 * unregisters the profile. 0242 * 0243 * A profile can use it to do cleanup tasks. There is no need 0244 * to unregister the profile, because when this method gets called 0245 * it has already been unregistered. 0246 * 0247 */ 0248 virtual void release(); 0249 0250 private: 0251 std::unique_ptr<class ProfilePrivate> const d; 0252 0253 friend class Manager; 0254 }; 0255 0256 } // namespace BluezQt 0257 0258 #endif // BLUEZQT_PROFILE_H