summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensors/winrt/winrtgyroscope.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/sensors/winrt/winrtgyroscope.cpp')
-rw-r--r--src/plugins/sensors/winrt/winrtgyroscope.cpp42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/plugins/sensors/winrt/winrtgyroscope.cpp b/src/plugins/sensors/winrt/winrtgyroscope.cpp
index e7910ab2..70d7980f 100644
--- a/src/plugins/sensors/winrt/winrtgyroscope.cpp
+++ b/src/plugins/sensors/winrt/winrtgyroscope.cpp
@@ -38,7 +38,9 @@
#include "winrtcommon.h"
#include <QtSensors/QGyroscope>
+#include <private/qeventdispatcher_winrt_p.h>
+#include <functional>
#include <wrl.h>
#include <windows.devices.sensors.h>
using namespace Microsoft::WRL;
@@ -111,20 +113,24 @@ WinRtGyroscope::WinRtGyroscope(QSensor *sensor)
: QSensorBackend(sensor), d_ptr(new WinRtGyroscopePrivate(this))
{
Q_D(WinRtGyroscope);
- HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Gyrometer);
- ComPtr<IGyrometerStatics> factory;
- HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory));
- if (FAILED(hr)) {
- qCWarning(lcWinRtSensors) << "Unable to initialize gyroscope sensor factory."
- << qt_error_string(hr);
- sensorError(hr);
- return;
- }
+ HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() {
+ HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Gyrometer);
+ ComPtr<IGyrometerStatics> factory;
+ HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory));
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to initialize gyroscope sensor factory."
+ << qt_error_string(hr);
+ return hr;
+ }
- hr = factory->GetDefault(&d->sensor);
+ hr = factory->GetDefault(&d->sensor);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get default gyroscope sensor."
+ << qt_error_string(hr);
+ }
+ return hr;
+ });
if (FAILED(hr) || !d->sensor) {
- qCWarning(lcWinRtSensors) << "Unable to get default gyroscope sensor."
- << qt_error_string(hr);
sensorError(hr);
return;
}
@@ -155,9 +161,11 @@ void WinRtGyroscope::start()
if (d->token.value)
return;
- ComPtr<InclinometerReadingHandler> callback =
+ HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() {
+ ComPtr<InclinometerReadingHandler> callback =
Callback<InclinometerReadingHandler>(d, &WinRtGyroscopePrivate::readingChanged);
- HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token);
+ return d->sensor->add_ReadingChanged(callback.Get(), &d->token);
+ });
if (FAILED(hr)) {
qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event."
<< qt_error_string(hr);
@@ -186,14 +194,16 @@ void WinRtGyroscope::stop()
if (!d->token.value)
return;
- HRESULT hr = d->sensor->remove_ReadingChanged(d->token);
+ HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() {
+ return d->sensor->remove_ReadingChanged(d->token);
+ });
if (FAILED(hr)) {
qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event."
<< qt_error_string(hr);
sensorError(hr);
return;
}
- d->sensor->put_ReportInterval(0);
+ hr = d->sensor->put_ReportInterval(0);
if (FAILED(hr)) {
qCWarning(lcWinRtSensors) << "Unable to reset report interval."
<< qt_error_string(hr);