BluezQt

profile.cpp
1 /*
2  * BluezQt - Asynchronous Bluez wrapper library
3  *
4  * SPDX-FileCopyrightText: 2014 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 #include "profile.h"
10 #include "debug.h"
11 #include "profile_p.h"
12 
13 #include <unistd.h>
14 
15 #include <QDBusUnixFileDescriptor>
16 #include <QLocalSocket>
17 
18 namespace BluezQt
19 {
21  : QObject(parent)
22  , d(new ProfilePrivate)
23 {
24 }
25 
27 {
28  delete d;
29 }
30 
31 void Profile::setName(const QString &name)
32 {
33  d->options[QStringLiteral("Name")] = name;
34 }
35 
36 void Profile::setService(const QString &service)
37 {
38  d->options[QStringLiteral("Service")] = service;
39 }
40 
42 {
43  QString str;
44  switch (role) {
45  case ClientRole:
46  str = QStringLiteral("client");
47  break;
48 
49  case ServerRole:
50  str = QStringLiteral("server");
51  break;
52 
53  default:
54  break;
55  }
56 
57  if (str.isEmpty()) {
58  qCWarning(BLUEZQT) << "Invalid local role!";
59  return;
60  }
61 
62  d->options[QStringLiteral("Role")] = str;
63 }
64 
65 void Profile::setChannel(quint16 channel)
66 {
67  if (channel > 31) {
68  qCWarning(BLUEZQT) << "Invalid channel number. Must be 0-31!";
69  return;
70  }
71 
72  d->options[QStringLiteral("Channel")] = QVariant::fromValue(channel);
73 }
74 
75 void Profile::setPsm(quint16 psm)
76 {
77  d->options[QStringLiteral("PSM")] = QVariant::fromValue(psm);
78 }
79 
81 {
82  d->options[QStringLiteral("RequireAuthentication")] = require;
83 }
84 
86 {
87  d->options[QStringLiteral("RequireAuthorization")] = require;
88 }
89 
90 void Profile::setAutoConnect(bool autoConnect)
91 {
92  d->options[QStringLiteral("AutoConnect")] = autoConnect;
93 }
94 
95 void Profile::setServiceRecord(const QString &serviceRecord)
96 {
97  d->options[QStringLiteral("ServiceRecord")] = serviceRecord;
98 }
99 
100 void Profile::setVersion(quint16 version)
101 {
102  d->options[QStringLiteral("Version")] = QVariant::fromValue(version);
103 }
104 
105 void Profile::setFeatures(quint16 features)
106 {
107  d->options[QStringLiteral("Features")] = QVariant::fromValue(features);
108 }
109 
111 {
112  int newfd = ::dup(fd.fileDescriptor());
114  socket->setSocketDescriptor(newfd);
115  return socket;
116 }
117 
118 void Profile::newConnection(DevicePtr device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const Request<> &request)
119 {
120  Q_UNUSED(device)
121  Q_UNUSED(fd)
122  Q_UNUSED(properties)
123 
124  request.cancel();
125 }
126 
128 {
129  Q_UNUSED(device)
130 
131  request.cancel();
132 }
133 
135 {
136 }
137 
138 } // namespace BluezQt
QVariant fromValue(const T &value)
void setRequireAuthorization(bool require)
Sets whether the authorization is required to connect.
Definition: profile.cpp:85
LocalRole
Local role to identify sides in asymmetric profiles.
Definition: profile.h:54
void setChannel(quint16 channel)
Sets the RFCOMM channel number.
Definition: profile.cpp:65
virtual void newConnection(DevicePtr device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const Request<> &request)
Requests the new connection.
Definition: profile.cpp:118
void setAutoConnect(bool autoConnect)
Sets whether the profile is automatically connected.
Definition: profile.cpp:90
void setService(const QString &service)
Sets the primary service class UUID (if different from profile UUID).
Definition: profile.cpp:36
~Profile() override
Destroys a Profile object.
Definition: profile.cpp:26
bool isEmpty() const const
void setName(const QString &name)
Sets the human readable name of the profile.
Definition: profile.cpp:31
int fileDescriptor() const const
@ ClientRole
Indicates that this is a client.
Definition: profile.h:56
void setLocalRole(LocalRole role)
Sets the local role to identify side.
Definition: profile.cpp:41
virtual void release()
Indicates that the profile was unregistered.
Definition: profile.cpp:134
void setRequireAuthentication(bool require)
Sets whether the pairing is required to connect.
Definition: profile.cpp:80
@ ServerRole
Indicates that this is a server.
Definition: profile.h:58
void setPsm(quint16 psm)
Sets the L2CAP port number.
Definition: profile.cpp:75
void cancel() const
Cancels the request.
Definition: request.cpp:138
QSharedPointer< QLocalSocket > createSocket(const QDBusUnixFileDescriptor &fd)
Creates a socket from file descriptor.
Definition: profile.cpp:110
virtual void requestDisconnection(DevicePtr device, const Request<> &request)
Requests the disconnection of the profile.
Definition: profile.cpp:127
void setFeatures(quint16 features)
Sets the profile features.
Definition: profile.cpp:105
void setServiceRecord(const QString &serviceRecord)
Sets a SDP record.
Definition: profile.cpp:95
Profile(QObject *parent=nullptr)
Creates a new Profile object.
Definition: profile.cpp:20
void setVersion(quint16 version)
Sets the profile version.
Definition: profile.cpp:100
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.