1// Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru>
2// Copyright (C) 2016 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "iiosensorproxyorientationsensor.h"
6#include "iiosensorproxylightsensor.h"
7#include "iiosensorproxycompass.h"
8#include "iiosensorproxyproximitysensor.h"
9
10#include <qsensorplugin.h>
11#include <qsensorbackend.h>
12#include <qsensormanager.h>
13
14#include <QtDBus/QDBusConnection>
15#include <QtDBus/QDBusConnectionInterface>
16
17#include <QtCore/QFile>
18#include <QtCore/QDebug>
19
20class IIOSensorProxySensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
21{
22 Q_OBJECT
23 Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
24 Q_INTERFACES(QSensorPluginInterface)
25public:
26 void registerSensors() override
27 {
28 if (QDBusConnection::systemBus().interface()->isServiceRegistered(serviceName: "net.hadess.SensorProxy")) {
29 if (!QSensorManager::isBackendRegistered(type: QOrientationSensor::sensorType, identifier: IIOSensorProxyOrientationSensor::id))
30 QSensorManager::registerBackend(type: QOrientationSensor::sensorType, identifier: IIOSensorProxyOrientationSensor::id, factory: this);
31 if (!QSensorManager::isBackendRegistered(type: QLightSensor::sensorType, identifier: IIOSensorProxyLightSensor::id))
32 QSensorManager::registerBackend(type: QLightSensor::sensorType, identifier: IIOSensorProxyLightSensor::id, factory: this);
33 if (!QSensorManager::isBackendRegistered(type: QCompass::sensorType, identifier: IIOSensorProxyCompass::id))
34 QSensorManager::registerBackend(type: QCompass::sensorType, identifier: IIOSensorProxyCompass::id, factory: this);
35 if (!QSensorManager::isBackendRegistered(type: QProximitySensor::sensorType, identifier: IIOSensorProxyProximitySensor::id))
36 QSensorManager::registerBackend(type: QProximitySensor::sensorType, identifier: IIOSensorProxyProximitySensor::id, factory: this);
37 }
38 }
39
40 QSensorBackend *createBackend(QSensor *sensor) override
41 {
42 if (sensor->identifier() == IIOSensorProxyOrientationSensor::id)
43 return new IIOSensorProxyOrientationSensor(sensor);
44 else if (sensor->identifier() == IIOSensorProxyLightSensor::id)
45 return new IIOSensorProxyLightSensor(sensor);
46 else if (sensor->identifier() == IIOSensorProxyCompass::id)
47 return new IIOSensorProxyCompass(sensor);
48 else if (sensor->identifier() == IIOSensorProxyProximitySensor::id)
49 return new IIOSensorProxyProximitySensor(sensor);
50
51 return 0;
52 }
53};
54
55#include "main.moc"
56

source code of qtsensors/src/plugins/sensors/iio-sensor-proxy/main.cpp