1 /*
2  * Copyright (C) 2015 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 SENSORS_H_
18 
19 #define SENSORS_H_
20 
21 #include <hardware/hardware.h>
22 #include <hardware/sensors.h>
23 #include <media/stagefright/foundation/ABase.h>
24 
25 #include "hubconnection.h"
26 
27 struct SensorContext {
28     struct sensors_poll_device_1 device;
29 
30     explicit SensorContext(const struct hw_module_t *module);
31 
32     bool getHubAlive();
33 
34 private:
35     android::sp<android::HubConnection> mHubConnection;
36     bool mHubAlive;
37 
38     int close();
39     int activate(int handle, int enabled);
40     int setDelay(int handle, int64_t delayNs);
41     int poll(sensors_event_t *data, int count);
42 
43     int batch(
44             int handle,
45             int flags,
46             int64_t sampling_period_ns,
47             int64_t max_report_latency_ns);
48 
49     int flush(int handle);
50 
51     static int CloseWrapper(struct hw_device_t *dev);
52 
53     static int ActivateWrapper(
54             struct sensors_poll_device_t *dev, int handle, int enabled);
55 
56     static int SetDelayWrapper(
57             struct sensors_poll_device_t *dev, int handle, int64_t delayNs);
58 
59     static int PollWrapper(
60             struct sensors_poll_device_t *dev, sensors_event_t *data, int count);
61 
62     static int BatchWrapper(
63             struct sensors_poll_device_1 *dev,
64             int handle,
65             int flags,
66             int64_t sampling_period_ns,
67             int64_t max_report_latency_ns);
68 
69     static int FlushWrapper(struct sensors_poll_device_1 *dev, int handle);
70 
71     DISALLOW_EVIL_CONSTRUCTORS(SensorContext);
72 };
73 
74 #endif  // SENSORS_H_
75