diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2016-08-24 14:19:40 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2016-08-25 07:57:22 +0000 |
commit | 46d9a630a88fc5388dec7fd99289d0e9e0e1f680 (patch) | |
tree | 282f24c50f249090994791e7224af2b82e31db62 /src/plugins/sensors/ios/iosgyroscope.mm | |
parent | f2f289b5048eab47901fe75dd41770ffd630dead (diff) | |
download | qtsensors-46d9a630a88fc5388dec7fd99289d0e9e0e1f680.tar.gz |
iOS: protect OS sensors from being stopped when shared by several Qt sensors
When a Qt sensor is told to stop, it automatically stops the underlying
OS sensor as well. This caused a problem when several Qt sensors were
running, since stopping one would stop them all.
This patch will add a ref count for each affected sensor, so that we
keep track of when it's safe to start and stop the underlying OS sensor.
Task-number: QTBUG-54977
Change-Id: If06c4daac22916feef2f4c7bd521363d74f342a6
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@canonical.com>
Diffstat (limited to 'src/plugins/sensors/ios/iosgyroscope.mm')
-rw-r--r-- | src/plugins/sensors/ios/iosgyroscope.mm | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/plugins/sensors/ios/iosgyroscope.mm b/src/plugins/sensors/ios/iosgyroscope.mm index fa051da..0a4699c 100644 --- a/src/plugins/sensors/ios/iosgyroscope.mm +++ b/src/plugins/sensors/ios/iosgyroscope.mm @@ -38,6 +38,8 @@ char const * const IOSGyroscope::id("ios.gyroscope"); QT_BEGIN_NAMESPACE +int IOSGyroscope::s_startCount = 0; + IOSGyroscope::IOSGyroscope(QSensor *sensor) : QSensorBackend(sensor) , m_motionManager([QIOSMotionManager sharedManager]) @@ -50,16 +52,24 @@ IOSGyroscope::IOSGyroscope(QSensor *sensor) void IOSGyroscope::start() { + if (m_timer != 0) + return; + int hz = sensor()->dataRate(); m_timer = startTimer(1000 / (hz == 0 ? 60 : hz)); - [m_motionManager startGyroUpdates]; + if (++s_startCount == 1) + [m_motionManager startGyroUpdates]; } void IOSGyroscope::stop() { - [m_motionManager stopGyroUpdates]; + if (m_timer == 0) + return; + killTimer(m_timer); m_timer = 0; + if (--s_startCount == 0) + [m_motionManager stopGyroUpdates]; } void IOSGyroscope::timerEvent(QTimerEvent *) |