diff options
author | Lincoln Ramsay <lincoln.ramsay@nokia.com> | 2012-05-28 14:10:29 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-13 20:33:16 +0100 |
commit | ce33c04b01fcd368c506335c2f105efbe9f4f702 (patch) | |
tree | 8eabdd3b11019acff5dd611950734d8f981205d0 /src/plugins/sensors/simulator/main.cpp | |
parent | c7ea35f8ca25da17c78174b4e98f3c613f742cb2 (diff) |
Register only the sensors the emulator knows about
Unfortunately, this involves a (long) round-trip so we start by
registering all the types we know about then unregister and
re-register the ones we're notified about.
Change-Id: I8ae8b4a9037eeb21a65454519945c3c307979a14
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/plugins/sensors/simulator/main.cpp')
-rw-r--r-- | src/plugins/sensors/simulator/main.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/plugins/sensors/simulator/main.cpp b/src/plugins/sensors/simulator/main.cpp index dda7269c..1e404086 100644 --- a/src/plugins/sensors/simulator/main.cpp +++ b/src/plugins/sensors/simulator/main.cpp @@ -56,6 +56,13 @@ class SimulatorSensorPlugin : public QObject, public QSensorPluginInterface, pub Q_PLUGIN_METADATA(IID "com.nokia.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") Q_INTERFACES(QSensorPluginInterface) public: + SimulatorSensorPlugin() + { + SensorsConnection *connection = SensorsConnection::instance(); + if (!connection) return; // hardly likely but just in case... + connect(connection, SIGNAL(setAvailableFeatures(quint32)), this, SLOT(setAvailableFeatures(quint32))); + } + void registerSensors() { QSensorManager::registerBackend(QAccelerometer::type, SimulatorAccelerometer::id, this); @@ -99,6 +106,39 @@ public: return 0; } + + // Copied from the emulator codebase + enum Features { + Accelerometer = 0x01, + Magnetometer = 0x02, + Compass = 0x04, + Infraredsensor = 0x08, + Lightsensor = 0x10 + }; + +public slots: + void setAvailableFeatures(quint32 features) + { + check(features&Accelerometer, QAccelerometer::type, SimulatorAccelerometer::id); + check(features&Lightsensor, QLightSensor::type, SimulatorLightSensor::id); + check(features&Lightsensor, QAmbientLightSensor::type, SimulatorAmbientLightSensor::id); + check(features&Magnetometer, QMagnetometer::type, SimulatorMagnetometer::id); + check(features&Compass, QCompass::type, SimulatorCompass::id); + check(features&Infraredsensor, QIRProximitySensor::type, SimulatorIRProximitySensor::id); + check(features&Infraredsensor, QProximitySensor::type, SimulatorProximitySensor::id); + } + +private: + void check(bool test, const QByteArray &type, const QByteArray &id) + { + if (test) { + if (!QSensorManager::isBackendRegistered(type, id)) + QSensorManager::registerBackend(type, id, this); + } else { + if (QSensorManager::isBackendRegistered(type, id)) + QSensorManager::unregisterBackend(type, id); + } + } }; #include "main.moc" |