/
hybrisadaptor.h
150 lines (120 loc) · 4.46 KB
/
hybrisadaptor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@jollamobile.com
**
**
** $QT_BEGIN_LICENSE:LGPL$
**
** 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 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef HybrisAdaptor_H
#define HybrisAdaptor_H
#include <QObject>
#include <QThread>
#include <QTimer>
#include <QFile>
#include <pthread.h>
#include "deviceadaptor.h"
#include <hardware/sensors.h>
#define SENSORFW_MCE_WATCHER
class HybrisAdaptor;
struct HybrisSensorState
{
HybrisSensorState();
~HybrisSensorState();
int m_minDelay;
int m_maxDelay;
int m_delay;
int m_active;
sensors_event_t m_fallbackEvent;
};
class HybrisManager : public QObject
{
Q_OBJECT
public:
static HybrisManager *instance();
explicit HybrisManager(QObject *parent = 0);
virtual ~HybrisManager();
/* - - - - - - - - - - - - - - - - - - - *
* android sensor hal functions
* - - - - - - - - - - - - - - - - - - - */
sensors_event_t *halEventForHandle(int handle) const;
int halIndexForHandle(int handle) const;
int halIndexForType (int sensorType) const;
int halHandleForType (int sensorType) const;
float halGetMaxRange (int handle) const;
float halGetResolution (int handle) const;
int halGetMinDelay (int handle) const;
int halGetMaxDelay (int handle) const;
int halGetDelay (int handle) const;
bool halSetDelay (int handle, int delay_ms);
bool halGetActive (int handle) const;
bool halSetActive (int handle, bool active);
/* - - - - - - - - - - - - - - - - - - - *
* HybrisManager <--> sensorfwd
* - - - - - - - - - - - - - - - - - - - */
void startReader (HybrisAdaptor *adaptor);
void stopReader (HybrisAdaptor *adaptor);
void registerAdaptor (HybrisAdaptor * adaptor);
void processSample (const sensors_event_t& data);
private:
// fields
bool m_initialized;
QMap <int, HybrisAdaptor *> m_registeredAdaptors; // type -> obj
struct sensors_module_t *m_halModule;
struct sensors_poll_device_t *m_halDevice;
int m_halSensorCount;
const struct sensor_t *m_halSensorArray; // [m_halSensorCount]
HybrisSensorState *m_halSensorState; // [m_halSensorCount]
QMap <int, int> m_halIndexOfType; // type -> index
QMap <int, int> m_halIndexOfHandle; // handle -> index
pthread_t m_halEventReaderTid;
friend class HybrisAdaptorReader;
private:
static void *halEventReaderThread(void *aptr);
};
class HybrisAdaptor : public DeviceAdaptor
{
public:
HybrisAdaptor(const QString& id, int type);
virtual ~HybrisAdaptor();
virtual void init();
virtual bool startAdaptor();
bool isRunning() const;
virtual void stopAdaptor();
void evaluateSensor();
virtual bool startSensor();
virtual void stopSensor();
virtual bool standby();
virtual bool resume();
virtual void sendInitialData();
friend class HybrisManager;
protected:
virtual void processSample(const sensors_event_t& data) = 0;
qreal minRange() const;
qreal maxRange() const;
qreal resolution() const;
unsigned int minInterval() const;
unsigned int maxInterval() const;
virtual unsigned int interval() const;
virtual bool setInterval(const unsigned int value, const int sessionId);
virtual unsigned int evaluateIntervalRequests(int& sessionId) const;
static bool writeToFile(const QByteArray& path, const QByteArray& content);
private:
bool m_inStandbyMode;
volatile bool m_isRunning;
bool m_shouldBeRunning;
int m_sensorHandle;
int m_sensorType;
};
#endif // HybrisAdaptor_H