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

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