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
9#include <qsensorplugin.h>
10#include <qsensorbackend.h>
11#include <qsensormanager.h>
12
13#include <QtDBus/QDBusConnection>
14#include <QtDBus/QDBusConnectionInterface>
15
16#include <QtCore/QFile>
17#include <QtCore/QDebug>
18
19class IIOSensorProxySensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
20{
21 Q_OBJECT
22 Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
23 Q_INTERFACES(QSensorPluginInterface)
24public:
25 void registerSensors() override
26 {
27 if (QDBusConnection::systemBus().interface()->isServiceRegistered(serviceName: "net.hadess.SensorProxy")) {
28 if (!QSensorManager::isBackendRegistered(type: QOrientationSensor::sensorType, identifier: IIOSensorProxyOrientationSensor::id))
29 QSensorManager::registerBackend(type: QOrientationSensor::sensorType, identifier: IIOSensorProxyOrientationSensor::id, factory: this);
30 if (!QSensorManager::isBackendRegistered(type: QLightSensor::sensorType, identifier: IIOSensorProxyLightSensor::id))
31 QSensorManager::registerBackend(type: QLightSensor::sensorType, identifier: IIOSensorProxyLightSensor::id, factory: this);
32 if (!QSensorManager::isBackendRegistered(type: QCompass::sensorType, identifier: IIOSensorProxyCompass::id))
33 QSensorManager::registerBackend(type: QCompass::sensorType, identifier: IIOSensorProxyCompass::id, factory: this);
34 }
35 }
36
37 QSensorBackend *createBackend(QSensor *sensor) override
38 {
39 if (sensor->identifier() == IIOSensorProxyOrientationSensor::id)
40 return new IIOSensorProxyOrientationSensor(sensor);
41 else if (sensor->identifier() == IIOSensorProxyLightSensor::id)
42 return new IIOSensorProxyLightSensor(sensor);
43 else if (sensor->identifier() == IIOSensorProxyCompass::id)
44 return new IIOSensorProxyCompass(sensor);
45
46 return 0;
47 }
48};
49
50#include "main.moc"
51

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