winrt: Register callbacks in Xaml thread

Change-Id: Ib32af0803e95229a1671055da4d5608f3fd3e0f6
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
Oliver Wolff 2017-02-02 15:14:11 +01:00
parent 69c8d41f90
commit f07c94c003
2 changed files with 26 additions and 14 deletions

View File

@ -43,6 +43,7 @@
#include "qbluetoothsocket_p.h"
#include <QtCore/QLoggingCategory>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
#include <qfunctions_winrt.h>
#include <windows.networking.h>
@ -156,12 +157,17 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
return false;
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);
Q_ASSERT_SUCCEEDED(hr);
hr = d->socketListener->add_ConnectionReceived(Callback<ClientConnectedHandler>(d, &QBluetoothServerPrivate::handleClientConnection).Get(),
&d->connectionToken);
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
//but we need a way to associate a server with a service

View File

@ -166,6 +166,9 @@ public slots:
public:
void startReading()
{
HRESULT hr;
hr = QEventDispatcherWinRT::runOnXamlThread([this]()
{
ComPtr<IBuffer> buffer;
HRESULT hr = g->bufferFactory->Create(READ_BUFFER_SIZE, &buffer);
@ -177,6 +180,9 @@ public:
Q_ASSERT_SUCCEEDED(hr);
hr = m_initialReadOp->put_Completed(Callback<SocketReadCompletedHandler>(this, &SocketWorker::onReadyRead).Get());
Q_ASSERT_SUCCEEDED(hr);
return S_OK;
});
Q_ASSERT_SUCCEEDED(hr);
}
HRESULT onReadyRead(IAsyncBufferOperation *asyncInfo, AsyncStatus status)