winrt: Register callbacks in Xaml thread
Change-Id: Ib32af0803e95229a1671055da4d5608f3fd3e0f6 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
parent
69c8d41f90
commit
f07c94c003
|
@ -43,6 +43,7 @@
|
||||||
#include "qbluetoothsocket_p.h"
|
#include "qbluetoothsocket_p.h"
|
||||||
|
|
||||||
#include <QtCore/QLoggingCategory>
|
#include <QtCore/QLoggingCategory>
|
||||||
|
#include <QtCore/private/qeventdispatcher_winrt_p.h>
|
||||||
#include <qfunctions_winrt.h>
|
#include <qfunctions_winrt.h>
|
||||||
|
|
||||||
#include <windows.networking.h>
|
#include <windows.networking.h>
|
||||||
|
@ -156,12 +157,17 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Networking_Sockets_StreamSocketListener).Get(),
|
hr = QEventDispatcherWinRT::runOnXamlThread([d, this] ()
|
||||||
|
{
|
||||||
|
HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Networking_Sockets_StreamSocketListener).Get(),
|
||||||
&d->socketListener);
|
&d->socketListener);
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
hr = d->socketListener->add_ConnectionReceived(Callback<ClientConnectedHandler>(d, &QBluetoothServerPrivate::handleClientConnection).Get(),
|
hr = d->socketListener->add_ConnectionReceived(Callback<ClientConnectedHandler>(d, &QBluetoothServerPrivate::handleClientConnection).Get(),
|
||||||
&d->connectionToken);
|
&d->connectionToken);
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
return S_OK;
|
||||||
|
});
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
|
||||||
//We can not register an actual Rfcomm port, because the platform does not allow it
|
//We can not register an actual Rfcomm port, because the platform does not allow it
|
||||||
//but we need a way to associate a server with a service
|
//but we need a way to associate a server with a service
|
||||||
|
|
|
@ -166,6 +166,9 @@ public slots:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void startReading()
|
void startReading()
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
hr = QEventDispatcherWinRT::runOnXamlThread([this]()
|
||||||
{
|
{
|
||||||
ComPtr<IBuffer> buffer;
|
ComPtr<IBuffer> buffer;
|
||||||
HRESULT hr = g->bufferFactory->Create(READ_BUFFER_SIZE, &buffer);
|
HRESULT hr = g->bufferFactory->Create(READ_BUFFER_SIZE, &buffer);
|
||||||
|
@ -177,6 +180,9 @@ public:
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
hr = m_initialReadOp->put_Completed(Callback<SocketReadCompletedHandler>(this, &SocketWorker::onReadyRead).Get());
|
hr = m_initialReadOp->put_Completed(Callback<SocketReadCompletedHandler>(this, &SocketWorker::onReadyRead).Get());
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
return S_OK;
|
||||||
|
});
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT onReadyRead(IAsyncBufferOperation *asyncInfo, AsyncStatus status)
|
HRESULT onReadyRead(IAsyncBufferOperation *asyncInfo, AsyncStatus status)
|
||||||
|
|
Loading…
Reference in New Issue