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
qbluetoothutils_winrt_p.h
Go to the documentation of this file.
1
// Copyright (C) 2021 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
#
ifndef
QBLUETOOTHUTILS_WINRT_P_H
5
#
define
QBLUETOOTHUTILS_WINRT_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
// Workaround for Windows SDK bug.
19
// See https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/47
20
#
include
<
winrt
/
base
.
h
>
21
#
include
<
QtCore
/
private
/
qfactorycacheregistration_p
.
h
>
22
namespace
winrt
::
impl
23
{
24
template
<
typename
Async>
25
auto
wait_for
(Async
const
& async, Windows::Foundation::TimeSpan
const
& timeout);
26
}
27
28
#
include
<
QtCore
/
QtGlobal
>
29
#
include
<
QtCore
/
private
/
qglobal_p
.
h
>
30
31
#
include
<
wrl
/
client
.
h
>
32
33
#
include
<
functional
>
34
#
include
<
type_traits
>
35
36
// Macros for guarding C++/WinRT projection calls. Each accessor on a winrt
37
// projection runs check_hresult() on the underlying ABI HRESULT and throws
38
// winrt::hresult_error on failure. After the Bluetooth stack tears down state
39
// (suspend/resume, radio toggle, service restart), those calls routinely fail
40
// and the exception propagates out of completion lambdas, crashing the process.
41
//
42
// SAFE(expr): returns expr's value on success, a logged-and-defaulted value on
43
// a caught hresult_error. Default-constructible types (primitives, enums,
44
// winrt::hstring, generic interfaces like IAsyncOperation<T>) take T{};
45
// runtimeclass projections that only declare an explicit Class(nullptr_t)
46
// constructor fall back to T(nullptr).
47
// HR(stmt): runs stmt and returns the resulting winrt::hresult (S_OK on
48
// success, e.code() on failure).
49
// TRY(stmt): runs stmt and returns true on success, false on failure.
50
// LOG_HRESULT(hr): warning-log helper used by the wrappers.
51
//
52
// Callsites must have the QT_BT_WINDOWS logging category in scope.
53
54
#
define
LOG_HRESULT
(
hr
)
qCWarning
(
QT_BT_WINDOWS
)
<<
"HRESULT:"
<<
quint32
(
hr
)
55
56
#
define
HR
(
x
)
57
std
::
invoke
(
[
&
]
(
)
{
58
try
{
59
x
;
60
}
catch
(
winrt
::
hresult_error
const
&
e
)
{
61
LOG_HRESULT
(
e
.
code
(
)
)
<<
"/*"
<<
#
x
<<
"*/"
;
62
return
e
.
code
(
)
;
63
}
64
return
winrt
::
hresult
{
S_OK
}
;
65
}
)
66
67
#
define
TRY
(
x
)
68
std
::
invoke
(
[
&
]
(
)
{
69
try
{
70
x
;
71
}
catch
(
winrt
::
hresult_error
const
&
e
)
{
72
LOG_HRESULT
(
e
.
code
(
)
)
<<
"/*"
<<
#
x
<<
"*/"
;
73
return
false
;
74
}
75
return
true
;
76
}
)
77
78
#
define
SAFE
(
x
)
79
std
::
invoke
(
[
&
]
(
)
->
decltype
(
x
)
{
80
try
{
return
(
x
)
;
}
81
catch
(
winrt
::
hresult_error
const
&
e
)
{
82
LOG_HRESULT
(
e
.
code
(
)
)
<<
"/*"
<<
#
x
<<
"*/"
;
83
if
constexpr
(
std
::
is_default_constructible_v
<
decltype
(
x
)
>
)
84
return
decltype
(
x
)
{
}
;
85
else
86
return
decltype
(
x
)
(
nullptr
)
;
87
}
88
}
)
89
90
namespace
ABI
{
91
namespace
Windows
{
92
namespace
Storage
{
93
namespace
Streams
{
94
struct
IBuffer;
95
}
96
}
97
}
98
}
99
100
QT_BEGIN_NAMESPACE
101
102
using
NativeBuffer = ABI::Windows::Storage::Streams::IBuffer;
103
QByteArray
byteArrayFromBuffer
(
const
Microsoft::WRL::ComPtr<NativeBuffer> &buffer,
104
bool
isWCharString =
false
);
105
106
// The calls to Co(Un)init must be balanced
107
void
threadCoInit
(
void
* caller);
108
void
threadCoUninit
(
void
* caller);
109
110
QT_END_NAMESPACE
111
112
#
endif
// QBLUETOOTHSOCKET_WINRT_P_H
AdapterManager
Definition
qbluetoothlocaldevice_winrt.cpp:125
AdapterManager::deviceAdded
void deviceAdded(const QBluetoothAddress &address)
AdapterManager::deviceRemoved
void deviceRemoved(const QBluetoothAddress &address)
AdapterManager::updateMode
void updateMode(winrt::hstring adapterId, QBluetoothLocalDevice::HostMode mode)
Definition
qbluetoothlocaldevice_winrt.cpp:261
AdapterManager::modeChanged
void modeChanged(winrt::hstring id, QBluetoothLocalDevice::HostMode mode)
AdapterManager::connectedDevices
QList< QBluetoothAddress > connectedDevices()
Definition
qbluetoothlocaldevice_winrt.cpp:198
AdapterManager::adapterRemoved
void adapterRemoved(winrt::hstring id)
AdapterManager::~AdapterManager
~AdapterManager()
Definition
qbluetoothlocaldevice_winrt.cpp:194
AdapterManager::removeClient
void removeClient(winrt::hstring adapterId)
Definition
qbluetoothlocaldevice_winrt.cpp:246
QBluetoothLocalDevicePrivate
Definition
qbluetoothlocaldevice_p.h:199
QBluetoothLocalDevicePrivate::isValid
bool isValid() const
Definition
qbluetoothlocaldevice_p.h:206
QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate
QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *=nullptr, QBluetoothAddress=QBluetoothAddress())
Definition
qbluetoothlocaldevice_p.h:201
WatcherWrapper
Definition
qbluetoothlocaldevice_winrt.cpp:78
WatcherWrapper::init
void init(AdapterManager *manager, AddedSlot onAdded, RemovedSlot onRemoved)
Definition
qbluetoothlocaldevice_winrt.cpp:87
WatcherWrapper::WatcherWrapper
WatcherWrapper(winrt::hstring selector)
Definition
qbluetoothlocaldevice_winrt.cpp:81
ABI::Windows::Storage::Streams
Definition
qbluetoothutils_winrt_p.h:93
ABI::Windows::Storage
Definition
qbluetoothutils_winrt_p.h:92
ABI::Windows
Definition
qwin10helpers.cpp:43
ABI
Definition
qwin10helpers.cpp:42
winrt::impl::wait_for
auto wait_for(Async const &async, Windows::Foundation::TimeSpan const &timeout)
winrt
Definition
qbluetoothutils_winrt_p.h:23
winrt::AsyncStatus
Windows::Foundation::AsyncStatus AsyncStatus
Definition
qlowenergycontroller_winrt_p.h:36
getAvailableAdapters
static DeviceInformationCollection getAvailableAdapters()
Definition
qbluetoothlocaldevice_winrt.cpp:457
pairingInfoFromAddress
DeviceInformationPairing pairingInfoFromAddress(const QBluetoothAddress &address)
Definition
qbluetoothlocaldevice_winrt.cpp:465
kMaximumAttempts
static const int kMaximumAttempts
Definition
qbluetoothlocaldevice_winrt.cpp:310
getBluetoothInfo
static BluetoothInfo getBluetoothInfo(winrt::hstring id)
Definition
qbluetoothlocaldevice_winrt.cpp:361
threadCoUninit
void threadCoUninit(void *caller)
Definition
qbluetoothutils_winrt.cpp:76
byteArrayFromBuffer
QByteArray byteArrayFromBuffer(const Microsoft::WRL::ComPtr< NativeBuffer > &buffer, bool isWCharString=false)
Definition
qbluetoothutils_winrt.cpp:25
LOG_HRESULT
#define LOG_HRESULT(hr)
Definition
qbluetoothutils_winrt_p.h:54
threadCoInit
void threadCoInit(void *caller)
Definition
qbluetoothutils_winrt.cpp:50
BluetoothInfo
Definition
qbluetoothlocaldevice_winrt.cpp:356
BluetoothInfo::address
QBluetoothAddress address
Definition
qbluetoothlocaldevice_winrt.cpp:357
BluetoothInfo::isConnected
bool isConnected
Definition
qbluetoothlocaldevice_winrt.cpp:358
PairingWorker
Definition
qbluetoothlocaldevice_winrt.cpp:483
PairingWorker::~PairingWorker
~PairingWorker()=default
PairingWorker::PairingWorker
PairingWorker(QBluetoothLocalDevice *device)
Definition
qbluetoothlocaldevice_winrt.cpp:484
PairingWorker::pairAsync
void pairAsync(const QBluetoothAddress &addr, QBluetoothLocalDevice::Pairing pairing)
Definition
qbluetoothlocaldevice_winrt.cpp:495
qtconnectivity
src
bluetooth
qbluetoothutils_winrt_p.h
Generated on
for Qt by
1.18.0