BluezQt

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

KDE's Doxygen guidelines are available online.