Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qbluetoothserviceinfo_android.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
5
#
include
"android/androidutils_p.h"
6
#
include
"qbluetoothhostinfo.h"
7
#
include
"qbluetoothlocaldevice.h"
8
#
include
"qbluetoothserviceinfo.h"
9
#
include
"qbluetoothserviceinfo_p.h"
10
#
include
"qbluetoothserver_p.h"
11
#
include
"qbluetoothserver.h"
12
13
#
include
<
QtCore
/
QLoggingCategory
>
14
15
QT_BEGIN_NAMESPACE
16
17
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
18
19
extern
QHash
<
QBluetoothServerPrivate
*,
int
>
__fakeServerPorts
;
20
21
QBluetoothServiceInfoPrivate
::QBluetoothServiceInfoPrivate()
22
: registered(
false
)
23
{
24
}
25
26
QBluetoothServiceInfoPrivate
::~
QBluetoothServiceInfoPrivate
()
27
{
28
}
29
30
bool
QBluetoothServiceInfoPrivate
::
isRegistered
()
const
31
{
32
return
registered;
33
}
34
35
bool
QBluetoothServiceInfoPrivate
::
unregisterService
()
36
{
37
if
(!registered)
38
return
false
;
39
40
QBluetoothServerPrivate
*sPriv = __fakeServerPorts.key(
serverChannel
(
)
);
41
if
(!sPriv) {
42
//QBluetoothServer::close() was called without prior call to unregisterService().
43
//Now it is unregistered anyway.
44
registered =
false
;
45
return
true
;
46
}
47
48
bool
result = sPriv->deactivateActiveListening();
49
if
(!result)
50
return
false
;
51
52
registered =
false
;
53
return
true
;
54
}
55
56
bool
QBluetoothServiceInfoPrivate
::
registerService
(
const
QBluetoothAddress& localAdapter)
57
{
58
if
(!ensureAndroidPermission(QBluetoothPermission::Access)) {
59
qCWarning(QT_BT_ANDROID) <<
"Serviceinfo registerService() failed due to"
60
"missing permissions"
;
61
return
false
;
62
}
63
64
const
QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
65
if
(localDevices.isEmpty())
66
return
false
;
//no Bluetooth device
67
68
if
(!localAdapter.isNull()) {
69
bool
found =
false
;
70
for
(
const
QBluetoothHostInfo &hostInfo : localDevices) {
71
if
(hostInfo.address() == localAdapter) {
72
found =
true
;
73
break
;
74
}
75
}
76
77
if
(!found) {
78
qCWarning(QT_BT_ANDROID) << localAdapter.toString() <<
"is not a valid local Bt adapter"
;
79
return
false
;
80
}
81
}
82
83
//already registered on local adapter => nothing to do
84
if
(registered)
85
return
false
;
86
87
if
(protocolDescriptor(QBluetoothUuid::ProtocolUuid::Rfcomm).isEmpty()) {
88
qCWarning(QT_BT_ANDROID) << Q_FUNC_INFO <<
"Only RFCOMM services can be registered on Android"
;
89
return
false
;
90
}
91
92
QBluetoothServerPrivate
*sPriv = __fakeServerPorts.key(
serverChannel
(
)
);
93
if
(!sPriv)
94
return
false
;
95
96
//tell the server what service name and uuid our listener should have
97
//and start the real listener
98
bool
result = sPriv->initiateActiveListening(
99
attributes.value(QBluetoothServiceInfo::ServiceId).value<QBluetoothUuid>(),
100
attributes.value(QBluetoothServiceInfo::ServiceName).toString());
101
if
(!result) {
102
return
false
;
103
}
104
105
106
registered =
true
;
107
return
true
;
108
}
109
110
QT_END_NAMESPACE
QBluetoothServerPrivate
Definition
qbluetoothserver_p.h:69
QBluetoothServiceInfoPrivate
Definition
qbluetoothserviceinfo_p.h:70
QBluetoothServiceInfoPrivate::registerService
bool registerService(const QBluetoothAddress &localAdapter=QBluetoothAddress())
Definition
qbluetoothserviceinfo_android.cpp:56
QBluetoothServiceInfoPrivate::unregisterService
bool unregisterService()
Definition
qbluetoothserviceinfo_android.cpp:35
QBluetoothServiceInfoPrivate::serverChannel
int serverChannel() const
Definition
qbluetoothserviceinfo.cpp:642
QBluetoothServiceInfoPrivate::isRegistered
bool isRegistered() const
Definition
qbluetoothserviceinfo_android.cpp:30
QBluetoothServiceInfoPrivate::~QBluetoothServiceInfoPrivate
~QBluetoothServiceInfoPrivate()
Definition
qbluetoothserviceinfo_android.cpp:26
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
__fakeServerPorts
QT_BEGIN_NAMESPACE QHash< QBluetoothServerPrivate *, int > __fakeServerPorts
Definition
qbluetoothserviceinfo_android.cpp:19
qtconnectivity
src
bluetooth
qbluetoothserviceinfo_android.cpp
Generated on
for Qt by
1.18.0