1/*
2 * BluezQt - Asynchronous BlueZ wrapper library
3 *
4 * SPDX-FileCopyrightText: 2014-2015 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#ifndef BLUEZQT_PROFILE_H
10#define BLUEZQT_PROFILE_H
11
12#include <QObject>
13
14#include "bluezqt_export.h"
15#include "request.h"
16#include "types.h"
17
18#include <memory>
19
20class QLocalSocket;
21class QDBusObjectPath;
22class QDBusUnixFileDescriptor;
23
24namespace BluezQt
25{
26class Device;
27
28/**
29 * @class BluezQt::Profile profile.h <BluezQt/Profile>
30 *
31 * Bluetooth profile.
32 *
33 * This class represents a Bluetooth profile.
34 *
35 * It is only needed to reimplement pure virtual functions.
36 * You don't need to set any additional properties.
37 *
38 * But you may need to specify at least channel number or PSM in case it couldn't be
39 * determined from UUID. It is also a good idea to provide name for the profile.
40 *
41 * Setting the channel number with setChannel() will make the profile use RFCOMM, while
42 * setting the PSM with setPsm() will make the profile use L2CAP.
43 *
44 * @note The return value of requests will be sent asynchronously with Request class.
45 * It is also possible to cancel/reject all requests.
46 *
47 */
48class BLUEZQT_EXPORT Profile : public QObject
49{
50 Q_OBJECT
51
52 Q_PROPERTY(QString uuid READ uuid)
53
54public:
55 /** Local role to identify sides in asymmetric profiles. */
56 enum LocalRole {
57 /** Indicates that this is a client. */
58 ClientRole,
59 /** Indicates that this is a server. */
60 ServerRole,
61 };
62
63 /**
64 * Creates a new Profile object.
65 *
66 * @param parent
67 */
68 explicit Profile(QObject *parent = nullptr);
69
70 /**
71 * Destroys a Profile object.
72 */
73 ~Profile() override;
74
75 /**
76 * D-Bus object path of the profile.
77 *
78 * The path where the profile will be registered.
79 *
80 * @note You must provide valid object path!
81 *
82 * @return object path of agent
83 */
84 virtual QDBusObjectPath objectPath() const = 0;
85
86 /**
87 * UUID of the profile.
88 *
89 * @return UUID of the profile
90 */
91 virtual QString uuid() const = 0;
92
93 /**
94 * Sets the human readable name of the profile.
95 *
96 * @param name name of the profile
97 */
98 void setName(const QString &name);
99
100 /**
101 * Sets the primary service class UUID (if different from profile UUID).
102 *
103 * @param service service UUID
104 */
105 void setService(const QString &service);
106
107 /**
108 * Sets the local role to identify side.
109 *
110 * For asymmetric profiles that do not have UUIDs available
111 * to uniquely identify each side this parameter allows
112 * specifying the precise local role.
113 *
114 * @param role local role
115 */
116 void setLocalRole(LocalRole role);
117
118 /**
119 * Sets the RFCOMM channel number.
120 *
121 * Available channel number range is 0-31.
122 * Setting channel number to 0 will automatically choose
123 * correct channel number for profile UUID.
124 *
125 * @param channel channel number
126 */
127 void setChannel(quint16 channel);
128
129 /**
130 * Sets the L2CAP port number.
131 *
132 * PSM (Protocol Service Multiplexer) is a port number
133 * in L2CAP.
134 *
135 * Setting PSM to 0 will automatically choose correct
136 * PSM for profile UUID.
137 *
138 * @param psm PSM
139 */
140 void setPsm(quint16 psm);
141
142 /**
143 * Sets whether the pairing is required to connect.
144 *
145 * @param require require to pair
146 */
147 void setRequireAuthentication(bool require);
148
149 /**
150 * Sets whether the authorization is required to connect.
151 *
152 * @param require require to authorize
153 */
154 void setRequireAuthorization(bool require);
155
156 /**
157 * Sets whether the profile is automatically connected.
158 *
159 * In case of a client UUID this will force connection
160 * of the RFCOMM or L2CAP channels when a remote device
161 * is connected.
162 *
163 * @param autoConnect autoconnect the profile
164 */
165 void setAutoConnect(bool autoConnect);
166
167 /**
168 * Sets a SDP record.
169 *
170 * This allows to provide a manual SDP record, otherwise it will
171 * be generated automatically.
172 *
173 * @param serviceRecord SDP record
174 */
175 void setServiceRecord(const QString &serviceRecord);
176
177 /**
178 * Sets the profile version.
179 *
180 * @param version version of the profile
181 */
182 void setVersion(quint16 version);
183
184 /**
185 * Sets the profile features.
186 *
187 * @param features features of the profile
188 */
189 void setFeatures(quint16 features);
190
191 /**
192 * Creates a socket from file descriptor.
193 *
194 * @param fd socket file descriptor
195 * @return socket
196 *
197 * @see newConnection()
198 */
199 QSharedPointer<QLocalSocket> createSocket(const QDBusUnixFileDescriptor &fd);
200
201 /**
202 * Requests the new connection.
203 *
204 * Common properties:
205 * <ul>
206 * <li>quint16 Version - Profile version</li>
207 * <li>quint16 Features - Profile features</li>
208 * </ul>
209 *
210 * To create socket from fd, you can use:
211 * @code
212 * QSharedPointer<QLocalSocket> socket = createSocket(fd);
213 * if (!socket->isValid()) {
214 * delete socket;
215 * request.cancel();
216 * return;
217 * }
218 * @endcode
219 *
220 * @param device device that requested connection
221 * @param fd socket file descriptor
222 * @param properties additional properties
223 * @param request request to be used for sending reply
224 */
225 virtual void newConnection(DevicePtr device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const Request<> &request);
226
227 /**
228 * Requests the disconnection of the profile.
229 *
230 * This method gets called when a profile gets disconnected.
231 *
232 * @param device device to be disconnected
233 * @param request request to be used for sending reply
234 */
235 virtual void requestDisconnection(DevicePtr device, const Request<> &request);
236
237 /**
238 * Indicates that the profile was unregistered.
239 *
240 * This method gets called when the Bluetooth daemon
241 * unregisters the profile.
242 *
243 * A profile can use it to do cleanup tasks. There is no need
244 * to unregister the profile, because when this method gets called
245 * it has already been unregistered.
246 *
247 */
248 virtual void release();
249
250private:
251 std::unique_ptr<class ProfilePrivate> const d;
252
253 friend class Manager;
254};
255
256} // namespace BluezQt
257
258#endif // BLUEZQT_PROFILE_H
259

source code of bluez-qt/src/profile.h