8#include <QtCore/QLoggingCategory>
9#include <QtCore/private/qfunctions_winrt_p.h>
13#include <windows.devices.enumeration.h>
14#include <windows.devices.bluetooth.h>
15#include <windows.foundation.collections.h>
16#include <windows.networking.h>
17#include <windows.storage.streams.h>
21using namespace Microsoft::WRL::Wrappers;
23using namespace ABI::Windows::Foundation::Collections;
26using namespace ABI::Windows::Devices::Bluetooth::Rfcomm;
27using namespace ABI::Windows::Devices::Enumeration;
30typedef Collections::IKeyValuePair<UINT32, IBuffer *>
ValueItem;
41#define TYPE_SHORT_UUID 25
42#define TYPE_LONG_UUID 28
44#define TYPE_SEQUENCE 53
80 : m_targetAddress(targetAddress)
92 HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Bluetooth_BluetoothDevice).Get(), &deviceStatics);
93 Q_ASSERT_SUCCEEDED(hr);
95 hr = deviceStatics->FromBluetoothAddressAsync(m_targetAddress, &deviceFromAddressOperation);
96 Q_ASSERT_SUCCEEDED(hr);
97 hr = deviceFromAddressOperation->put_Completed(
Callback<IAsyncOperationCompletedHandler<BluetoothDevice *>>
98 (
this, &QWinRTBluetoothServiceDiscoveryWorker::onBluetoothDeviceFoundAsync).Get());
99 Q_ASSERT_SUCCEEDED(hr);
104 if (status != Completed) {
105 qCDebug(QT_BT_WINDOWS) <<
"Could not find device";
112 hr = op->GetResults(&
device);
113 Q_ASSERT_SUCCEEDED(hr);
119 Q_ASSERT_SUCCEEDED(hr);
122 ? BluetoothCacheMode_Cached : BluetoothCacheMode_Uncached;
123 hr = device3->GetRfcommServicesWithCacheModeAsync(cacheMode, &serviceOp);
124 Q_ASSERT_SUCCEEDED(hr);
125 hr = serviceOp->put_Completed(Callback<IAsyncOperationCompletedHandler<RfcommDeviceServicesResult *>>
128 if (status != Completed) {
129 qCDebug(QT_BT_WINDOWS) <<
"Could not obtain service list";
136 Q_ASSERT_SUCCEEDED(hr);
138 hr =
result->get_Services(&commServices);
139 Q_ASSERT_SUCCEEDED(hr);
140 processServiceSearchResult(
address, commServices);
143 Q_ASSERT_SUCCEEDED(hr);
148void QWinRTBluetoothServiceDiscoveryWorker::processServiceSearchResult(
quint64 address,
ComPtr<IVectorView<RfcommDeviceService*>>
services)
153 Q_ASSERT_SUCCEEDED(hr);
157 Q_ASSERT_SUCCEEDED(hr);
159 hr =
service->get_ConnectionServiceName(
name.GetAddressOf());
160 Q_ASSERT_SUCCEEDED(hr);
163 hr =
service->get_ConnectionHostName(host.GetAddressOf());
164 Q_ASSERT_SUCCEEDED(hr);
166 hr = host->get_RawName(hostName.GetAddressOf());
167 Q_ASSERT_SUCCEEDED(hr);
171 hr =
service->get_ServiceId(&
id);
172 Q_ASSERT_SUCCEEDED(hr);
174 hr =
id->get_Uuid(&guid);
176 Q_ASSERT_SUCCEEDED(hr);
181 info.setServiceName(serviceName);
182 info.setServiceUuid(uuid);
184 hr =
service->GetSdpRawAttributesAsync(op.GetAddressOf());
187 qCDebug(QT_BT_WINDOWS) <<
"Check manifest capabilities";
191 hr = QWinRTFunctions::await(op, mapView.GetAddressOf());
192 Q_ASSERT_SUCCEEDED(hr);
197 hr = mapView.As(&iterable);
201 boolean current =
false;
202 hr = iterable->First(&iterator);
205 hr =
iterator->get_HasCurrent(¤t);
209 while (SUCCEEDED(hr) && current) {
222 Q_ASSERT_SUCCEEDED(hr);
226 hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_DataReader).Get(), &dataReaderStatics);
227 Q_ASSERT_SUCCEEDED(hr);
228 hr = dataReaderStatics->FromBuffer(
buffer.Get(), dataReader.GetAddressOf());
229 Q_ASSERT_SUCCEEDED(hr);
231 hr = dataReader->ReadByte(&
type);
232 Q_ASSERT_SUCCEEDED(hr);
235 hr = dataReader->ReadByte(&
value);
236 Q_ASSERT_SUCCEEDED(hr);
241 hr = dataReader->ReadUInt16(&
value);
242 Q_ASSERT_SUCCEEDED(hr);
247 hr = dataReader->ReadUInt32(&
value);
248 Q_ASSERT_SUCCEEDED(hr);
253 hr = dataReader->ReadUInt16(&
value);
254 Q_ASSERT_SUCCEEDED(hr);
260 hr = dataReader->ReadGuid(&
value);
261 Q_ASSERT_SUCCEEDED(hr);
269 hr = dataReader->ReadByte(&
length);
270 Q_ASSERT_SUCCEEDED(hr);
272 hr = dataReader->ReadString(
length,
value.GetAddressOf());
273 Q_ASSERT_SUCCEEDED(hr);
281 info.setAttribute(
key, sequence);
319 HRESULT hr = dataReader->ReadByte(&remainingLength);
320 Q_ASSERT_SUCCEEDED(hr);
324 hr = dataReader->ReadByte(&
type);
325 remainingLength -= 1;
328 Q_ASSERT_SUCCEEDED(hr);
333 hr = dataReader->ReadByte(&
value);
334 Q_ASSERT_SUCCEEDED(hr);
336 remainingLength -= 1;
343 hr = dataReader->ReadUInt16(&
value);
344 Q_ASSERT_SUCCEEDED(hr);
346 remainingLength -= 2;
353 hr = dataReader->ReadUInt32(&
value);
354 Q_ASSERT_SUCCEEDED(hr);
356 remainingLength -= 4;
363 hr = dataReader->ReadUInt16(&
b);
364 Q_ASSERT_SUCCEEDED(hr);
368 remainingLength -= 2;
375 hr = dataReader->ReadGuid(&
b);
376 Q_ASSERT_SUCCEEDED(hr);
381 remainingLength -=
sizeof(GUID);
383 *bytesRead +=
sizeof(GUID);
388 hr = dataReader->ReadByte(&
length);
389 Q_ASSERT_SUCCEEDED(hr);
390 remainingLength -= 1;
394 hr = dataReader->ReadString(
length,
value.GetAddressOf());
395 Q_ASSERT_SUCCEEDED(hr);
399 remainingLength -=
length;
411 remainingLength -= bytesR;
413 *bytesRead += bytesR;
417 qCDebug(QT_BT_WINDOWS) <<
"SEQUENCE ERROR" <<
type;
421 if (remainingLength == 0)
424 hr = dataReader->ReadByte(&
type);
425 Q_ASSERT_SUCCEEDED(hr);
426 remainingLength -= 1;
471void QBluetoothServiceDiscoveryAgentPrivate::stop()
483 bool serviceNameMatched = uuidFilter.
contains(
info.serviceUuid());
484 bool serviceClassMatched =
false;
486 =
info.serviceClassUuids();
489 serviceClassMatched =
true;
494 if (!serviceNameMatched && !serviceClassMatched)
506 returnInfo.setDevice(deviceInfo);
512 if (!isDuplicatedService(returnInfo)) {
515 << returnInfo.serviceName() << returnInfo.serviceUuid()
516 <<
">>>" << returnInfo.serviceClassUuids();
518 emit q->serviceDiscovered(returnInfo);
522void QBluetoothServiceDiscoveryAgentPrivate::onScanFinished(
quint64 deviceAddress)
532void QBluetoothServiceDiscoveryAgentPrivate::onError()
541void QBluetoothServiceDiscoveryAgentPrivate::releaseWorker()
547 this, &QBluetoothServiceDiscoveryAgentPrivate::processFoundService);
549 this, &QBluetoothServiceDiscoveryAgentPrivate::onScanFinished);
551 this, &QBluetoothServiceDiscoveryAgentPrivate::onError);
558#include <qbluetoothservicediscoveryagent_winrt.moc>
IOBluetoothDevice * device
std::vector< ObjCStrongReference< CBMutableService > > services
QBluetoothAddress address() const
Returns the address of the device.
QBluetoothAddress deviceAddress
~QBluetoothServiceDiscoveryAgentPrivate()
QList< QBluetoothServiceInfo > discoveredServices
void _q_serviceDiscoveryFinished()
QBluetoothServiceDiscoveryAgentPrivate(QBluetoothServiceDiscoveryAgent *qp, const QBluetoothAddress &deviceAdapter)
QList< QBluetoothDeviceInfo > discoveredDevices
QBluetoothServiceDiscoveryAgent::Error error
DiscoveryMode
This enum describes the service discovery mode.
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
void append(parameter_type t)
void deleteLater()
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
QWinRTBluetoothServiceDiscoveryWorker(quint64 targetAddress, QBluetoothServiceDiscoveryAgent::DiscoveryMode mode)
~QWinRTBluetoothServiceDiscoveryWorker()
void scanFinished(quint64 deviceAddress)
void serviceFound(quint64 deviceAddress, const QBluetoothServiceInfo &info)
typename C::iterator iterator
Combined button and popup list for selecting options.
Q_CORE_EXPORT QtJniTypes::Service service()
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
QTextStream & dec(QTextStream &stream)
Calls QTextStream::setIntegerBase(10) on stream and returns stream.
Collections::IKeyValuePair< UINT32, IBuffer * > ValueItem
Collections::IIterable< ValueItem * > ValueIterable
Collections::IIterator< ValueItem * > ValueIterator
static void reverseArray(uchar data[], size_t length)
void mainThreadCoInit(void *caller)
void mainThreadCoUninit(void *caller)
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLboolean GLboolean GLboolean b
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
QT_BEGIN_NAMESPACE typedef void(* Callback)(QQmlNotifierEndpoint *, void **)
#define QStringLiteral(str)
unsigned long long quint64
QFileInfo info(fileName)
[8]
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
myObject disconnect()
[26]
bool contains(const AT &t) const noexcept