SensorInterface.h revision f001c92436b4a66eb7687286325ced7f10c9f917
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_SENSOR_INTERFACE_H
18#define ANDROID_SENSOR_INTERFACE_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/Singleton.h>
24
25#include <gui/Sensor.h>
26
27#include "SensorDevice.h"
28
29// ---------------------------------------------------------------------------
30
31namespace android {
32// ---------------------------------------------------------------------------
33
34class SensorInterface {
35public:
36    virtual ~SensorInterface();
37
38    virtual bool process(sensors_event_t* outEvent,
39            const sensors_event_t& event) = 0;
40
41    virtual bool isEnabled() const = 0;
42    virtual status_t activate(void* ident, bool enabled) = 0;
43    virtual status_t setDelay(void* ident, int handle, int64_t ns) = 0;
44    virtual Sensor getSensor() const = 0;
45    virtual bool isVirtual() const = 0;
46};
47
48// ---------------------------------------------------------------------------
49
50class HardwareSensor : public SensorInterface
51{
52    SensorDevice& mSensorDevice;
53    Sensor mSensor;
54    bool mEnabled;
55
56public:
57    HardwareSensor(const sensor_t& sensor);
58
59    virtual ~HardwareSensor();
60
61    virtual bool process(sensors_event_t* outEvent,
62            const sensors_event_t& event);
63
64    virtual bool isEnabled() const;
65    virtual status_t activate(void* ident, bool enabled);
66    virtual status_t setDelay(void* ident, int handle, int64_t ns);
67    virtual Sensor getSensor() const;
68    virtual bool isVirtual() const { return false; }
69};
70
71
72// ---------------------------------------------------------------------------
73}; // namespace android
74
75#endif // ANDROID_SENSOR_INTERFACE_H
76