1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtSensors module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifdef QTSENSORS_GENERICORIENTATIONSENSOR
41#include "genericorientationsensor.h"
42#endif
43#ifdef QTSENSORS_GENERICROTATIONSENSOR
44#include "genericrotationsensor.h"
45#endif
46#ifdef QTSENSORS_GENERICALSSENSOR
47#include "genericalssensor.h"
48#endif
49#ifdef QTSENSORS_GENERICTILTSENSOR
50#include "generictiltsensor.h"
51#endif
52#include <QtSensors/qsensorplugin.h>
53#include <QtSensors/qsensorbackend.h>
54#include <QtSensors/qsensormanager.h>
55#include <QFile>
56#include <QDebug>
57
58class genericSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorChangesInterface, public QSensorBackendFactory
59{
60 Q_OBJECT
61 Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
62 Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface)
63public:
64 void registerSensors() override
65 {
66 // Nothing to register here
67 }
68
69 void sensorsChanged() override
70 {
71 if (!QSensor::defaultSensorForType(type: QAccelerometer::type).isEmpty()) {
72 // There is an accelerometer available. Register the backends
73#ifdef QTSENSORS_GENERICORIENTATIONSENSOR
74 if (!QSensorManager::isBackendRegistered(type: QOrientationSensor::type, identifier: genericorientationsensor::id))
75 QSensorManager::registerBackend(type: QOrientationSensor::type, identifier: genericorientationsensor::id, factory: this);
76#endif
77#ifdef QTSENSORS_GENERICROTATIONSENSOR
78 if (!QSensorManager::isBackendRegistered(type: QRotationSensor::type, identifier: genericrotationsensor::id))
79 QSensorManager::registerBackend(type: QRotationSensor::type, identifier: genericrotationsensor::id, factory: this);
80#endif
81#ifdef QTSENSORS_GENERICTILTSENSOR
82 if (!QSensorManager::isBackendRegistered(type: QTiltSensor::type, identifier: GenericTiltSensor::id))
83 QSensorManager::registerBackend(type: QTiltSensor::type, identifier: GenericTiltSensor::id, factory: this);
84#endif
85 } else {
86#ifdef QTSENSORS_GENERICORIENTATIONSENSOR
87 if (QSensorManager::isBackendRegistered(type: QOrientationSensor::type, identifier: genericorientationsensor::id))
88 QSensorManager::unregisterBackend(type: QOrientationSensor::type, identifier: genericorientationsensor::id);
89#endif
90#ifdef QTSENSORS_GENERICROTATIONSENSOR
91 if (QSensorManager::isBackendRegistered(type: QRotationSensor::type, identifier: genericrotationsensor::id))
92 QSensorManager::unregisterBackend(type: QRotationSensor::type, identifier: genericrotationsensor::id);
93#endif
94#ifdef QTSENSORS_GENERICTILTSENSOR
95 if (QSensorManager::isBackendRegistered(type: QTiltSensor::type, identifier: GenericTiltSensor::id))
96 QSensorManager::unregisterBackend(type: QTiltSensor::type, identifier: GenericTiltSensor::id);
97#endif
98 }
99
100 if (!QSensor::defaultSensorForType(type: QLightSensor::type).isEmpty()) {
101#ifdef QTSENSORS_GENERICALSSENSOR
102 if (!QSensorManager::isBackendRegistered(type: QAmbientLightSensor::type, identifier: genericalssensor::id))
103 QSensorManager::registerBackend(type: QAmbientLightSensor::type, identifier: genericalssensor::id, factory: this);
104#endif
105 } else {
106#ifdef QTSENSORS_GENERICALSSENSOR
107 if (QSensorManager::isBackendRegistered(type: QAmbientLightSensor::type, identifier: genericalssensor::id))
108 QSensorManager::unregisterBackend(type: QAmbientLightSensor::type, identifier: genericalssensor::id);
109#endif
110 }
111 }
112
113 QSensorBackend *createBackend(QSensor *sensor) override
114 {
115#ifdef QTSENSORS_GENERICORIENTATIONSENSOR
116 if (sensor->identifier() == genericorientationsensor::id)
117 return new genericorientationsensor(sensor);
118#endif
119#ifdef QTSENSORS_GENERICROTATIONSENSOR
120 if (sensor->identifier() == genericrotationsensor::id)
121 return new genericrotationsensor(sensor);
122#endif
123#ifdef QTSENSORS_GENERICALSSENSOR
124 if (sensor->identifier() == genericalssensor::id)
125 return new genericalssensor(sensor);
126#endif
127#ifdef QTSENSORS_GENERICTILTSENSOR
128 if (sensor->identifier() == GenericTiltSensor::id)
129 return new GenericTiltSensor(sensor);
130#endif
131
132 return 0;
133 }
134};
135
136#include "main.moc"
137
138

source code of qtsensors/src/plugins/sensors/generic/main.cpp