| 1 | // Copyright (C) 2016 The Qt Company Ltd. | 
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | 
| 3 |  | 
| 4 | #ifdef QTSENSORS_GENERICORIENTATIONSENSOR | 
| 5 | #include "genericorientationsensor.h" | 
| 6 | #endif | 
| 7 | #ifdef QTSENSORS_GENERICROTATIONSENSOR | 
| 8 | #include "genericrotationsensor.h" | 
| 9 | #endif | 
| 10 | #ifdef QTSENSORS_GENERICALSSENSOR | 
| 11 | #include "genericalssensor.h" | 
| 12 | #endif | 
| 13 | #ifdef QTSENSORS_GENERICTILTSENSOR | 
| 14 | #include "generictiltsensor.h" | 
| 15 | #endif | 
| 16 | #include <QtSensors/qsensorplugin.h> | 
| 17 | #include <QtSensors/qsensorbackend.h> | 
| 18 | #include <QtSensors/qsensormanager.h> | 
| 19 | #include <QFile> | 
| 20 | #include <QDebug> | 
| 21 |  | 
| 22 | class genericSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorChangesInterface, public QSensorBackendFactory | 
| 23 | { | 
| 24 |     Q_OBJECT | 
| 25 |     Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0"  FILE "plugin.json" ) | 
| 26 |     Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface) | 
| 27 | public: | 
| 28 |     void registerSensors() override | 
| 29 |     { | 
| 30 |         // Nothing to register here | 
| 31 |     } | 
| 32 |  | 
| 33 |     void sensorsChanged() override | 
| 34 |     { | 
| 35 |         if (!QSensor::defaultSensorForType(type: QAccelerometer::sensorType).isEmpty()) { | 
| 36 |             // There is an accelerometer available. Register the backends | 
| 37 | #ifdef QTSENSORS_GENERICORIENTATIONSENSOR | 
| 38 |             if (!QSensorManager::isBackendRegistered(type: QOrientationSensor::sensorType, identifier: genericorientationsensor::id)) | 
| 39 |                 QSensorManager::registerBackend(type: QOrientationSensor::sensorType, identifier: genericorientationsensor::id, factory: this); | 
| 40 | #endif | 
| 41 | #ifdef QTSENSORS_GENERICROTATIONSENSOR | 
| 42 |             if (!QSensorManager::isBackendRegistered(type: QRotationSensor::sensorType, identifier: genericrotationsensor::id)) | 
| 43 |                 QSensorManager::registerBackend(type: QRotationSensor::sensorType, identifier: genericrotationsensor::id, factory: this); | 
| 44 | #endif | 
| 45 | #ifdef QTSENSORS_GENERICTILTSENSOR | 
| 46 |             if (!QSensorManager::isBackendRegistered(type: QTiltSensor::sensorType, identifier: GenericTiltSensor::id)) | 
| 47 |                 QSensorManager::registerBackend(type: QTiltSensor::sensorType, identifier: GenericTiltSensor::id, factory: this); | 
| 48 | #endif | 
| 49 |         } else { | 
| 50 | #ifdef QTSENSORS_GENERICORIENTATIONSENSOR | 
| 51 |             if (QSensorManager::isBackendRegistered(type: QOrientationSensor::sensorType, identifier: genericorientationsensor::id)) | 
| 52 |                 QSensorManager::unregisterBackend(type: QOrientationSensor::sensorType, identifier: genericorientationsensor::id); | 
| 53 | #endif | 
| 54 | #ifdef QTSENSORS_GENERICROTATIONSENSOR | 
| 55 |             if (QSensorManager::isBackendRegistered(type: QRotationSensor::sensorType, identifier: genericrotationsensor::id)) | 
| 56 |                 QSensorManager::unregisterBackend(type: QRotationSensor::sensorType, identifier: genericrotationsensor::id); | 
| 57 | #endif | 
| 58 | #ifdef QTSENSORS_GENERICTILTSENSOR | 
| 59 |             if (QSensorManager::isBackendRegistered(type: QTiltSensor::sensorType, identifier: GenericTiltSensor::id)) | 
| 60 |                 QSensorManager::unregisterBackend(type: QTiltSensor::sensorType, identifier: GenericTiltSensor::id); | 
| 61 | #endif | 
| 62 |         } | 
| 63 |  | 
| 64 |         if (!QSensor::defaultSensorForType(type: QLightSensor::sensorType).isEmpty()) { | 
| 65 | #ifdef QTSENSORS_GENERICALSSENSOR | 
| 66 |             if (!QSensorManager::isBackendRegistered(type: QAmbientLightSensor::sensorType, identifier: genericalssensor::id)) | 
| 67 |                 QSensorManager::registerBackend(type: QAmbientLightSensor::sensorType, identifier: genericalssensor::id, factory: this); | 
| 68 | #endif | 
| 69 |         } else { | 
| 70 | #ifdef QTSENSORS_GENERICALSSENSOR | 
| 71 |             if (QSensorManager::isBackendRegistered(type: QAmbientLightSensor::sensorType, identifier: genericalssensor::id)) | 
| 72 |                 QSensorManager::unregisterBackend(type: QAmbientLightSensor::sensorType, identifier: genericalssensor::id); | 
| 73 | #endif | 
| 74 |         } | 
| 75 |     } | 
| 76 |  | 
| 77 |     QSensorBackend *createBackend(QSensor *sensor) override | 
| 78 |     { | 
| 79 | #ifdef QTSENSORS_GENERICORIENTATIONSENSOR | 
| 80 |         if (sensor->identifier() == genericorientationsensor::id) | 
| 81 |             return new genericorientationsensor(sensor); | 
| 82 | #endif | 
| 83 | #ifdef QTSENSORS_GENERICROTATIONSENSOR | 
| 84 |         if (sensor->identifier() == genericrotationsensor::id) | 
| 85 |             return new genericrotationsensor(sensor); | 
| 86 | #endif | 
| 87 | #ifdef QTSENSORS_GENERICALSSENSOR | 
| 88 |         if (sensor->identifier() == genericalssensor::id) | 
| 89 |             return new genericalssensor(sensor); | 
| 90 | #endif | 
| 91 | #ifdef QTSENSORS_GENERICTILTSENSOR | 
| 92 |         if (sensor->identifier() == GenericTiltSensor::id) | 
| 93 |             return new GenericTiltSensor(sensor); | 
| 94 | #endif | 
| 95 |  | 
| 96 |         return 0; | 
| 97 |     } | 
| 98 | }; | 
| 99 |  | 
| 100 | #include "main.moc" | 
| 101 |  |