From a58b60600aa3f280c01f2f741fd7b43d8adc0994 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Thu, 2 Jul 2015 16:59:13 +0300 Subject: Add iio-sensor-proxy backend iio-sensor-proxy is a daemon that listens to sensors on IIO subsystem on Linux and provides access to the sensor readings over D-Bus. Currently it provides only orientation and ambient- light level. https://github.com/hadess/iio-sensor-proxy Change-Id: I035bda0b43a16552a9f2bd88a064e53d5f105451 Reviewed-by: Lorn Potter --- .../sensors/iio-sensor-proxy/iio-sensor-proxy.pro | 26 +++++ .../iio-sensor-proxy/iiosensorproxylightsensor.cpp | 94 ++++++++++++++++++ .../iio-sensor-proxy/iiosensorproxylightsensor.h | 66 +++++++++++++ .../iiosensorproxyorientationsensor.cpp | 104 ++++++++++++++++++++ .../iiosensorproxyorientationsensor.h | 66 +++++++++++++ .../iio-sensor-proxy/iiosensorproxysensorbase.cpp | 107 +++++++++++++++++++++ .../iio-sensor-proxy/iiosensorproxysensorbase.h | 70 ++++++++++++++ src/plugins/sensors/iio-sensor-proxy/main.cpp | 70 ++++++++++++++ .../iio-sensor-proxy/net.hadess.SensorProxy.xml | 24 +++++ .../org.freedesktop.DBus.Properties.xml | 27 ++++++ src/plugins/sensors/iio-sensor-proxy/plugin.json | 1 + 11 files changed, 655 insertions(+) create mode 100644 src/plugins/sensors/iio-sensor-proxy/iio-sensor-proxy.pro create mode 100644 src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.cpp create mode 100644 src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.h create mode 100644 src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.cpp create mode 100644 src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.h create mode 100644 src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.cpp create mode 100644 src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.h create mode 100644 src/plugins/sensors/iio-sensor-proxy/main.cpp create mode 100644 src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.xml create mode 100644 src/plugins/sensors/iio-sensor-proxy/org.freedesktop.DBus.Properties.xml create mode 100644 src/plugins/sensors/iio-sensor-proxy/plugin.json (limited to 'src/plugins/sensors/iio-sensor-proxy') diff --git a/src/plugins/sensors/iio-sensor-proxy/iio-sensor-proxy.pro b/src/plugins/sensors/iio-sensor-proxy/iio-sensor-proxy.pro new file mode 100644 index 00000000..355097a1 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iio-sensor-proxy.pro @@ -0,0 +1,26 @@ +TARGET = qtsensors_iio-sensor-proxy +QT = core dbus sensors + +PLUGIN_TYPE = sensors +PLUGIN_CLASS_NAME = IIOSensorProxySensorPlugin +load(qt_plugin) + +!android:LIBS += -lrt +HEADERS += iiosensorproxysensorbase.h \ + iiosensorproxylightsensor.h \ + iiosensorproxyorientationsensor.h + +SOURCES += iiosensorproxysensorbase.cpp \ + iiosensorproxylightsensor.cpp \ + iiosensorproxyorientationsensor.cpp \ + main.cpp + +DBUS_INTERFACES += sensor_proxy dbus_properties + +sensor_proxy.files = net.hadess.SensorProxy.xml +sensor_proxy.header_flags = -N + +dbus_properties.files = org.freedesktop.DBus.Properties.xml +dbus_properties.header_flags = -N + +OTHER_FILES = plugin.json $$DBUS_INTERFACES diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.cpp b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.cpp new file mode 100644 index 00000000..38bce633 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxylightsensor.h" +#include "sensorproxy_interface.h" + +#include + +char const * const IIOSensorProxyLightSensor::id("iio-sensor-proxy.lightsensor"); + +static inline QString dbusPath() { return QStringLiteral("/net/hadess/SensorProxy"); } + +IIOSensorProxyLightSensor::IIOSensorProxyLightSensor(QSensor *sensor) + : IIOSensorProxySensorBase(dbusPath(), NetHadessSensorProxyInterface::staticInterfaceName(), sensor) +{ + setReading(&m_reading); + m_sensorProxyInterface = new NetHadessSensorProxyInterface(serviceName(), dbusPath(), + QDBusConnection::systemBus(), this); +} + +IIOSensorProxyLightSensor::~IIOSensorProxyLightSensor() +{ +} + +void IIOSensorProxyLightSensor::start() +{ + if (isServiceRunning()) { + if (m_sensorProxyInterface->hasAmbientLight() + && m_sensorProxyInterface->lightLevelUnit() == QLatin1String("lux")) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ClaimLight(); + reply.waitForFinished(); + if (!reply.isError()) { + updateLightLevel(m_sensorProxyInterface->lightLevel()); + return; + } + } + } + sensorStopped(); +} + +void IIOSensorProxyLightSensor::stop() +{ + if (isServiceRunning()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ReleaseLight(); + reply.waitForFinished(); + } + sensorStopped(); +} + +void IIOSensorProxyLightSensor::updateProperties(const QVariantMap &changedProperties) +{ + if (changedProperties.contains("LightLevel")) { + double lux = changedProperties.value("LightLevel").toDouble(); + updateLightLevel(lux); + } +} + +void IIOSensorProxyLightSensor::updateLightLevel(double lux) +{ + m_reading.setLux(lux); + m_reading.setTimestamp(produceTimestamp()); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.h b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.h new file mode 100644 index 00000000..96cedc7f --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_LIGHTSENSOR_H +#define IIOSENSORPROXY_LIGHTSENSOR_H + +#include "iiosensorproxysensorbase.h" + +#include + +class NetHadessSensorProxyInterface; + +class IIOSensorProxyLightSensor : public IIOSensorProxySensorBase +{ + Q_OBJECT +public: + static char const * const id; + + IIOSensorProxyLightSensor(QSensor *sensor); + ~IIOSensorProxyLightSensor(); + + void start() Q_DECL_OVERRIDE; + void stop() Q_DECL_OVERRIDE; + +protected: + void updateProperties(const QVariantMap &changedProperties) Q_DECL_OVERRIDE; + +private: + void updateLightLevel(double lux); + + QLightReading m_reading; + NetHadessSensorProxyInterface *m_sensorProxyInterface; +}; + +#endif // IIOSENSORPROXY_LIGHTSENSOR_H diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.cpp b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.cpp new file mode 100644 index 00000000..b9042178 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxyorientationsensor.h" +#include "sensorproxy_interface.h" + +#include + +char const * const IIOSensorProxyOrientationSensor::id("iio-sensor-proxy.orientationsensor"); + +static inline QString dbusPath() { return QStringLiteral("/net/hadess/SensorProxy"); } + +IIOSensorProxyOrientationSensor::IIOSensorProxyOrientationSensor(QSensor *sensor) + : IIOSensorProxySensorBase(dbusPath(), NetHadessSensorProxyInterface::staticInterfaceName(), sensor) +{ + setReading(&m_reading); + m_sensorProxyInterface = new NetHadessSensorProxyInterface(serviceName(), dbusPath(), + QDBusConnection::systemBus(), this); +} + +IIOSensorProxyOrientationSensor::~IIOSensorProxyOrientationSensor() +{ +} + +void IIOSensorProxyOrientationSensor::start() +{ + if (isServiceRunning()) { + if (m_sensorProxyInterface->hasAccelerometer()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ClaimAccelerometer(); + reply.waitForFinished(); + if (!reply.isError()) { + QString orientation = m_sensorProxyInterface->accelerometerOrientation(); + updateOrientation(orientation); + return; + } + } + } + sensorStopped(); +} + +void IIOSensorProxyOrientationSensor::stop() +{ + if (isServiceRunning()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ReleaseAccelerometer(); + reply.waitForFinished(); + } + sensorStopped(); +} + +void IIOSensorProxyOrientationSensor::updateProperties(const QVariantMap &changedProperties) +{ + if (changedProperties.contains("AccelerometerOrientation")) { + QString orientation = changedProperties.value("AccelerometerOrientation").toString(); + updateOrientation(orientation); + } +} + +void IIOSensorProxyOrientationSensor::updateOrientation(const QString &orientation) +{ + QOrientationReading::Orientation o = QOrientationReading::Undefined; + if (orientation == QLatin1String("normal")) + o = QOrientationReading::TopUp; + else if (orientation == QLatin1String("bottom-up")) + o = QOrientationReading::TopDown; + else if (orientation == QLatin1String("left-up")) + o = QOrientationReading::LeftUp; + else if (orientation == QLatin1String("right-up")) + o = QOrientationReading::RightUp; + + m_reading.setOrientation(o); + m_reading.setTimestamp(produceTimestamp()); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.h b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.h new file mode 100644 index 00000000..39bc4ee9 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_ORIENTATIONSENSOR_H +#define IIOSENSORPROXY_ORIENTATIONSENSOR_H + +#include "iiosensorproxysensorbase.h" + +#include + +class NetHadessSensorProxyInterface; + +class IIOSensorProxyOrientationSensor : public IIOSensorProxySensorBase +{ + Q_OBJECT +public: + static char const * const id; + + IIOSensorProxyOrientationSensor(QSensor *sensor); + ~IIOSensorProxyOrientationSensor(); + + void start() Q_DECL_OVERRIDE; + void stop() Q_DECL_OVERRIDE; + +protected: + void updateProperties(const QVariantMap &changedProperties) Q_DECL_OVERRIDE; + +private: + void updateOrientation(const QString &orientation); + + QOrientationReading m_reading; + NetHadessSensorProxyInterface *m_sensorProxyInterface; +}; + +#endif // IIOSENSORPROXY_ORIENTATIONSENSOR_H diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.cpp b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.cpp new file mode 100644 index 00000000..09cb2a36 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxysensorbase.h" +#include "sensorproxy_interface.h" +#include "properties_interface.h" + +#include +#include +#include + +#include + +quint64 IIOSensorProxySensorBase::produceTimestamp() +{ + struct timespec tv; + int ok; + +#ifdef CLOCK_MONOTONIC_RAW + ok = clock_gettime(CLOCK_MONOTONIC_RAW, &tv); + if (ok != 0) +#endif + ok = clock_gettime(CLOCK_MONOTONIC, &tv); + Q_ASSERT(ok == 0); + + quint64 result = (tv.tv_sec * 1000000ULL) + (tv.tv_nsec * 0.001); // scale to microseconds + return result; +} + +IIOSensorProxySensorBase::IIOSensorProxySensorBase(const QString& dbusPath, const QString dbusIface, QSensor *sensor) + : QSensorBackend(sensor) + , m_dbusInterface(dbusIface) +{ + QDBusServiceWatcher *watcher = new QDBusServiceWatcher(serviceName(), QDBusConnection::systemBus(), + QDBusServiceWatcher::WatchForRegistration | + QDBusServiceWatcher::WatchForUnregistration, this); + connect(watcher, SIGNAL(serviceRegistered(QString)), + this, SLOT(serviceRegistered())); + connect(watcher, SIGNAL(serviceUnregistered(QString)), + this, SLOT(serviceUnregistered())); + + m_serviceRunning = QDBusConnection::systemBus().interface()->isServiceRegistered(serviceName()); + + m_propertiesInterface = new OrgFreedesktopDBusPropertiesInterface(serviceName(), dbusPath, + QDBusConnection::systemBus(), this); + connect(m_propertiesInterface, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)), + this, SLOT(propertiesChanged(QString,QVariantMap,QStringList))); +} + +IIOSensorProxySensorBase::~IIOSensorProxySensorBase() +{ +} + +QString IIOSensorProxySensorBase::serviceName() const +{ + return QLatin1String("net.hadess.SensorProxy"); +} + +void IIOSensorProxySensorBase::serviceRegistered() +{ + m_serviceRunning = true; +} + +void IIOSensorProxySensorBase::serviceUnregistered() +{ + m_serviceRunning = false; + sensorStopped(); +} + +void IIOSensorProxySensorBase::propertiesChanged(const QString &interface, + const QVariantMap &changedProperties, + const QStringList &/*invalidatedProperties*/) +{ + if (interface == m_dbusInterface) + updateProperties(changedProperties); +} diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.h b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.h new file mode 100644 index 00000000..f114c3e6 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_SENSORBASE_H +#define IIOSENSORPROXY_SENSORBASE_H + +#include + +class OrgFreedesktopDBusPropertiesInterface; + +class IIOSensorProxySensorBase : public QSensorBackend +{ + Q_OBJECT +public: + static char const * const id; + + IIOSensorProxySensorBase(const QString &dbusPath, const QString dbusIface, QSensor *sensor); + ~IIOSensorProxySensorBase(); + + bool isServiceRunning() const { return m_serviceRunning; } + QString serviceName() const; + +protected: + static quint64 produceTimestamp(); + virtual void updateProperties(const QVariantMap &changedProperties) = 0; + +private slots: + void serviceRegistered(); + void serviceUnregistered(); + void propertiesChanged(const QString &interface, const QVariantMap &changedProperties, + const QStringList &invalidatedProperties); + +private: + bool m_serviceRunning; + OrgFreedesktopDBusPropertiesInterface *m_propertiesInterface; + QString m_dbusInterface; +}; + +#endif // IIOSENSORPROXY_SENSORBASE_H diff --git a/src/plugins/sensors/iio-sensor-proxy/main.cpp b/src/plugins/sensors/iio-sensor-proxy/main.cpp new file mode 100644 index 00000000..85737b3b --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/main.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxyorientationsensor.h" +#include "iiosensorproxylightsensor.h" + +#include +#include +#include + +#include +#include + +class IIOSensorProxySensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") + Q_INTERFACES(QSensorPluginInterface) +public: + void registerSensors() + { + if (!QSensorManager::isBackendRegistered(QOrientationSensor::type, IIOSensorProxyOrientationSensor::id)) + QSensorManager::registerBackend(QOrientationSensor::type, IIOSensorProxyOrientationSensor::id, this); + if (!QSensorManager::isBackendRegistered(QLightSensor::type, IIOSensorProxyLightSensor::id)) + QSensorManager::registerBackend(QLightSensor::type, IIOSensorProxyLightSensor::id, this); + } + + QSensorBackend *createBackend(QSensor *sensor) + { + if (sensor->identifier() == IIOSensorProxyOrientationSensor::id) + return new IIOSensorProxyOrientationSensor(sensor); + else if (sensor->identifier() == IIOSensorProxyLightSensor::id) + return new IIOSensorProxyLightSensor(sensor); + + return 0; + } +}; + +#include "main.moc" diff --git a/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.xml b/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.xml new file mode 100644 index 00000000..94d9869b --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/plugins/sensors/iio-sensor-proxy/org.freedesktop.DBus.Properties.xml b/src/plugins/sensors/iio-sensor-proxy/org.freedesktop.DBus.Properties.xml new file mode 100644 index 00000000..5dc94f5d --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/org.freedesktop.DBus.Properties.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/plugins/sensors/iio-sensor-proxy/plugin.json b/src/plugins/sensors/iio-sensor-proxy/plugin.json new file mode 100644 index 00000000..5397f760 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/plugin.json @@ -0,0 +1 @@ +{ "Keys": [ "iio-sensor-proxy" ] } -- cgit v1.2.3