blob: 7d715e0f6fe216069b276b59a7add5b44e7c42e7 [file] [log] [blame]
Andreas Huberdb49a412016-10-10 13:23:59 -07001/*
2 * Copyright (C) 2016 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 HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_
18
19#define HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_
20
21#include <android/hardware/sensors/1.0/ISensors.h>
22#include <hardware/sensors.h>
Peng Xuab7884f2017-03-02 13:36:45 -080023#include <mutex>
Andreas Huberdb49a412016-10-10 13:23:59 -070024
25namespace android {
26namespace hardware {
27namespace sensors {
28namespace V1_0 {
29namespace implementation {
30
Peng Xucefa91b2017-01-16 03:10:40 -080031
Andreas Huberdb49a412016-10-10 13:23:59 -070032struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
33 Sensors();
34
35 status_t initCheck() const;
36
Peng Xu0873e642017-01-08 13:28:10 -080037 Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override;
Andreas Huberdb49a412016-10-10 13:23:59 -070038
39 Return<Result> setOperationMode(OperationMode mode) override;
40
41 Return<Result> activate(
42 int32_t sensor_handle, bool enabled) override;
43
Andreas Huberdb49a412016-10-10 13:23:59 -070044 Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override;
45
46 Return<Result> batch(
47 int32_t sensor_handle,
Andreas Huberdb49a412016-10-10 13:23:59 -070048 int64_t sampling_period_ns,
49 int64_t max_report_latency_ns) override;
50
51 Return<Result> flush(int32_t sensor_handle) override;
52
53 Return<Result> injectSensorData(const Event& event) override;
54
Peng Xu0f0df7e2017-01-05 23:39:08 -080055 Return<void> registerDirectChannel(
Peng Xu0873e642017-01-08 13:28:10 -080056 const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override;
Peng Xu0f0df7e2017-01-05 23:39:08 -080057
58 Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
59
60 Return<void> configDirectReport(
61 int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
62 configDirectReport_cb _hidl_cb) override;
63
Andreas Huberdb49a412016-10-10 13:23:59 -070064private:
Peng Xucefa91b2017-01-16 03:10:40 -080065 static constexpr int32_t kPollMaxBufferSize = 128;
Andreas Huberdb49a412016-10-10 13:23:59 -070066 status_t mInitCheck;
67 sensors_module_t *mSensorModule;
68 sensors_poll_device_1_t *mSensorDevice;
Peng Xuab7884f2017-03-02 13:36:45 -080069 std::mutex mPollLock;
Andreas Huberdb49a412016-10-10 13:23:59 -070070
71 int getHalDeviceVersion() const;
72
73 static void convertFromSensorEvents(
74 size_t count, const sensors_event_t *src, hidl_vec<Event> *dst);
75
76 DISALLOW_COPY_AND_ASSIGN(Sensors);
77};
78
79extern "C" ISensors *HIDL_FETCH_ISensors(const char *name);
80
81} // namespace implementation
82} // namespace V1_0
83} // namespace sensors
84} // namespace hardware
85} // namespace android
86
87#endif // HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_