1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QSENSORBACKEND_H |
5 | #define QSENSORBACKEND_H |
6 | |
7 | #include <QtSensors/qsensor.h> |
8 | #include <QtSensors/qsensormanager.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | class QSensorBackendPrivate; |
13 | |
14 | class Q_SENSORS_EXPORT QSensorBackend : public QObject |
15 | { |
16 | Q_OBJECT |
17 | public: |
18 | explicit QSensorBackend(QSensor *sensor, QObject *parent = nullptr); |
19 | virtual ~QSensorBackend(); |
20 | |
21 | virtual void start() = 0; |
22 | virtual void stop() = 0; |
23 | |
24 | virtual bool isFeatureSupported(QSensor::Feature feature) const; |
25 | |
26 | // used by the backend to set metadata properties |
27 | void addDataRate(qreal min, qreal max); |
28 | void setDataRates(const QSensor *otherSensor); |
29 | void addOutputRange(qreal min, qreal max, qreal accuracy); |
30 | void setDescription(const QString &description); |
31 | |
32 | template <typename T> |
33 | T *setReading(T *readingClass) |
34 | { |
35 | if (!readingClass) |
36 | readingClass = new T(this); |
37 | setReadings(device: readingClass, filter: new T(this), cache: new T(this)); |
38 | return readingClass; |
39 | } |
40 | |
41 | QSensorReading *reading() const; |
42 | QSensor *sensor() const; |
43 | |
44 | // used by the backend to inform us of events |
45 | void newReadingAvailable(); |
46 | void sensorStopped(); |
47 | void sensorBusy(bool busy = true); |
48 | void sensorError(int error); |
49 | |
50 | private: |
51 | void setReadings(QSensorReading *device, QSensorReading *filter, QSensorReading *cache); |
52 | |
53 | Q_DECLARE_PRIVATE(QSensorBackend) |
54 | Q_DISABLE_COPY(QSensorBackend) |
55 | }; |
56 | |
57 | QT_END_NAMESPACE |
58 | |
59 | #endif |
60 | |
61 | |