diff options
Diffstat (limited to 'src/plugins/sensors/iio-sensor-proxy')
14 files changed, 893 insertions, 0 deletions
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..b68d9fbf --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iio-sensor-proxy.pro @@ -0,0 +1,31 @@ +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 \ + iiosensorproxycompass.h + +SOURCES += iiosensorproxysensorbase.cpp \ + iiosensorproxylightsensor.cpp \ + iiosensorproxyorientationsensor.cpp \ + iiosensorproxycompass.cpp \ + main.cpp + +DBUS_INTERFACES += sensor_proxy sensor_proxy_compass dbus_properties + +sensor_proxy.files = net.hadess.SensorProxy.xml +sensor_proxy.header_flags = -N + +sensor_proxy_compass.files = net.hadess.SensorProxy.Compass.xml +sensor_proxy_compass.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/iiosensorproxycompass.cpp b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.cpp new file mode 100644 index 00000000..fd0b0f1f --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxycompass.h" +#include "compass_interface.h" + +#include <QtDBus/QDBusPendingReply> + +char const * const IIOSensorProxyCompass::id("iio-sensor-proxy.compass"); + +static inline QString dbusPath() { return QStringLiteral("/net/hadess/SensorProxy/Compass"); } + +IIOSensorProxyCompass::IIOSensorProxyCompass(QSensor *sensor) + : IIOSensorProxySensorBase(dbusPath(), NetHadessSensorProxyCompassInterface::staticInterfaceName(), sensor) +{ + setReading<QCompassReading>(&m_reading); + m_sensorProxyInterface = new NetHadessSensorProxyCompassInterface(serviceName(), dbusPath(), + QDBusConnection::systemBus(), this); +} + +IIOSensorProxyCompass::~IIOSensorProxyCompass() +{ +} + +void IIOSensorProxyCompass::start() +{ + if (isServiceRunning()) { + if (m_sensorProxyInterface->hasCompass()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ClaimCompass(); + reply.waitForFinished(); + if (!reply.isError()) { + double azimuth = m_sensorProxyInterface->compassHeading(); + updateAzimuth(azimuth); + return; + } + } + } + sensorStopped(); +} + +void IIOSensorProxyCompass::stop() +{ + if (isServiceRunning()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ReleaseCompass(); + reply.waitForFinished(); + } + sensorStopped(); +} + +void IIOSensorProxyCompass::updateProperties(const QVariantMap &changedProperties) +{ + if (changedProperties.contains("CompassHeading")) { + double azimuth = changedProperties.value("CompassHeading").toDouble(); + updateAzimuth(azimuth); + } +} + +void IIOSensorProxyCompass::updateAzimuth(double azimuth) +{ + m_reading.setAzimuth(azimuth); + m_reading.setTimestamp(produceTimestamp()); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.h b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.h new file mode 100644 index 00000000..60b201ee --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_COMPASS_H +#define IIOSENSORPROXY_COMPASS_H + +#include "iiosensorproxysensorbase.h" + +#include <qcompass.h> + +class NetHadessSensorProxyCompassInterface; + +class IIOSensorProxyCompass : public IIOSensorProxySensorBase +{ + Q_OBJECT +public: + static char const * const id; + + IIOSensorProxyCompass(QSensor *sensor); + ~IIOSensorProxyCompass(); + + void start() Q_DECL_OVERRIDE; + void stop() Q_DECL_OVERRIDE; + +protected: + void updateProperties(const QVariantMap &changedProperties) Q_DECL_OVERRIDE; + +private: + void updateAzimuth(double azimuth); + + QCompassReading m_reading; + NetHadessSensorProxyCompassInterface *m_sensorProxyInterface; +}; + +#endif // IIOSENSORPROXY_COMPASS_H 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..acd48147 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxylightsensor.h" +#include "sensorproxy_interface.h" + +#include <QtDBus/QDBusPendingReply> + +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<QLightReading>(&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..e1acd239 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_LIGHTSENSOR_H +#define IIOSENSORPROXY_LIGHTSENSOR_H + +#include "iiosensorproxysensorbase.h" + +#include <qlightsensor.h> + +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..86ebb358 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxyorientationsensor.h" +#include "sensorproxy_interface.h" + +#include <QtDBus/QDBusPendingReply> + +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<QOrientationReading>(&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..b62aad9e --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_ORIENTATIONSENSOR_H +#define IIOSENSORPROXY_ORIENTATIONSENSOR_H + +#include "iiosensorproxysensorbase.h" + +#include <qorientationsensor.h> + +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..0a9f318c --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxysensorbase.h" +#include "sensorproxy_interface.h" +#include "properties_interface.h" + +#include <QtDBus/QDBusConnection> +#include <QtDBus/QDBusServiceWatcher> +#include <QtDBus/QDBusConnectionInterface> + +#include <time.h> + +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..96e036ad --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_SENSORBASE_H +#define IIOSENSORPROXY_SENSORBASE_H + +#include <qsensorbackend.h> + +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..5d38833f --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/main.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxyorientationsensor.h" +#include "iiosensorproxylightsensor.h" +#include "iiosensorproxycompass.h" + +#include <qsensorplugin.h> +#include <qsensorbackend.h> +#include <qsensormanager.h> + +#include <QtCore/QFile> +#include <QtCore/QDebug> + +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); + if (!QSensorManager::isBackendRegistered(QCompass::type, IIOSensorProxyCompass::id)) + QSensorManager::registerBackend(QCompass::type, IIOSensorProxyCompass::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); + else if (sensor->identifier() == IIOSensorProxyCompass::id) + return new IIOSensorProxyCompass(sensor); + + return 0; + } +}; + +#include "main.moc" diff --git a/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.Compass.xml b/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.Compass.xml new file mode 100644 index 00000000..bcadffde --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.Compass.xml @@ -0,0 +1,14 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="net.hadess.SensorProxy.Compass"> + <method name="ClaimCompass"> + </method> + <method name="ReleaseCompass"> + </method> + <property type="b" name="HasCompass" access="read"> + </property> + <property type="d" name="CompassHeading" access="read"> + </property> + </interface> +</node> 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 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="net.hadess.SensorProxy"> + <method name="ClaimAccelerometer"> + </method> + <method name="ReleaseAccelerometer"> + </method> + <method name="ClaimLight"> + </method> + <method name="ReleaseLight"> + </method> + <property type="b" name="HasAccelerometer" access="read"> + </property> + <property type="s" name="AccelerometerOrientation" access="read"> + </property> + <property type="b" name="HasAmbientLight" access="read"> + </property> + <property type="s" name="LightLevelUnit" access="read"> + </property> + <property type="d" name="LightLevel" access="read"> + </property> + </interface> +</node> 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 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="org.freedesktop.DBus.Properties"> + <method name="Get"> + <arg name="interface" type="s" direction="in"/> + <arg name="name" type="s" direction="in"/> + <arg name="value" type="v" direction="out"/> + </method> + <method name="Set"> + <arg name="interface" type="s" direction="in"/> + <arg name="name" type="s" direction="in"/> + <arg name="value" type="v" direction="in"/> + </method> + <method name="GetAll"> + <arg name="interface" type="s" direction="in"/> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + <signal name="PropertiesChanged"> + <arg name="interface" type="s"/> + <arg name="changed_properties" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> + <arg name="invalidated_properties" type="as"/> + </signal> + </interface> +</node> 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" ] } |