1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtSensors module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef MOCKCOMMON_H |
30 | #define MOCKCOMMON_H |
31 | |
32 | #include <qsensorbackend.h> |
33 | |
34 | #include <QSensor> |
35 | #include <QTimer> |
36 | #include <QAccelerometer> |
37 | #include <QOrientationSensor> |
38 | #include <QIRProximitySensor> |
39 | #include <QProximitySensor> |
40 | #include <QTapSensor> |
41 | |
42 | #include <QFile> |
43 | #include <QTextStream> |
44 | |
45 | class mockcommonPrivate : public QObject |
46 | { |
47 | Q_OBJECT |
48 | public: |
49 | |
50 | mockcommonPrivate(); |
51 | |
52 | static mockcommonPrivate *instance(); |
53 | |
54 | bool setFile(const QString &); |
55 | bool parseData(const QString &line); |
56 | QTimer *readTimer; |
57 | |
58 | public slots: |
59 | void timerout(); |
60 | |
61 | Q_SIGNALS: |
62 | void accelData(const QString &data); |
63 | void irProxyData(const QString &data); |
64 | void orientData(const QString &data); |
65 | void tapData(const QString &data); |
66 | void proxyData(const QString &data); |
67 | |
68 | private: |
69 | QFile pFile; |
70 | qreal oldAccelTs; |
71 | qreal prevts; |
72 | bool firstRun; |
73 | }; |
74 | |
75 | class mockcommon : public QSensorBackend |
76 | { |
77 | Q_OBJECT |
78 | public: |
79 | mockcommon(QSensor *sensor); |
80 | |
81 | void start() override; |
82 | void stop() override; |
83 | static char const * const id; |
84 | |
85 | Q_SIGNALS: |
86 | void parseAccelData(const QString &data); |
87 | void parseIrProxyDatata(const QString &data); |
88 | void parseOrientData(const QString &data); |
89 | void parseTapData(const QString &data); |
90 | void parseProxyData(const QString &data); |
91 | |
92 | private: |
93 | int m_timerid; |
94 | friend class mockcommonPrivate; |
95 | QTimer *timer; |
96 | QSensor *parentSensor; |
97 | |
98 | }; |
99 | |
100 | class mockaccelerometer : public mockcommon |
101 | { |
102 | Q_OBJECT |
103 | |
104 | public: |
105 | static char const * const id; |
106 | |
107 | mockaccelerometer(QSensor *sensor); |
108 | |
109 | public slots: |
110 | void parseAccelData(const QString &data); |
111 | |
112 | private: |
113 | QAccelerometerReading m_reading; |
114 | qreal lastTimestamp; |
115 | }; |
116 | |
117 | class mockorientationsensor : public mockcommon |
118 | { |
119 | Q_OBJECT |
120 | |
121 | public: |
122 | static char const * const id; |
123 | |
124 | mockorientationsensor(QSensor *sensor); |
125 | public slots: |
126 | |
127 | void parseOrientData(const QString &data); |
128 | |
129 | private: |
130 | QOrientationReading m_reading; |
131 | }; |
132 | |
133 | class mockirproximitysensor : public mockcommon |
134 | { |
135 | Q_OBJECT |
136 | |
137 | public: |
138 | static char const * const id; |
139 | |
140 | mockirproximitysensor(QSensor *sensor); |
141 | public slots: |
142 | |
143 | void parseIrProxyData(const QString &data); |
144 | |
145 | private: |
146 | QIRProximityReading m_reading; |
147 | }; |
148 | |
149 | class mocktapsensor : public mockcommon |
150 | { |
151 | Q_OBJECT |
152 | |
153 | public: |
154 | static char const * const id; |
155 | |
156 | mocktapsensor(QSensor *sensor); |
157 | public slots: |
158 | |
159 | void parseTapData(const QString &data); |
160 | |
161 | private: |
162 | QTapReading m_reading; |
163 | }; |
164 | |
165 | |
166 | class mockproximitysensor : public mockcommon |
167 | { |
168 | Q_OBJECT |
169 | |
170 | public: |
171 | static char const * const id; |
172 | |
173 | mockproximitysensor(QSensor *sensor); |
174 | public slots: |
175 | |
176 | void parseProxyData(const QString &data); |
177 | |
178 | private: |
179 | QProximityReading m_reading; |
180 | }; |
181 | #endif // MOCKCOMMON_H |
182 | |