Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 1 | /* |
| 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 Xu | ab7884f | 2017-03-02 13:36:45 -0800 | [diff] [blame] | 23 | #include <mutex> |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace sensors { |
| 28 | namespace V1_0 { |
| 29 | namespace implementation { |
| 30 | |
Peng Xu | cefa91b | 2017-01-16 03:10:40 -0800 | [diff] [blame] | 31 | |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 32 | struct Sensors : public ::android::hardware::sensors::V1_0::ISensors { |
| 33 | Sensors(); |
| 34 | |
| 35 | status_t initCheck() const; |
| 36 | |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 37 | Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 38 | |
| 39 | Return<Result> setOperationMode(OperationMode mode) override; |
| 40 | |
| 41 | Return<Result> activate( |
| 42 | int32_t sensor_handle, bool enabled) override; |
| 43 | |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 44 | Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override; |
| 45 | |
| 46 | Return<Result> batch( |
| 47 | int32_t sensor_handle, |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 48 | 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 Xu | 0f0df7e | 2017-01-05 23:39:08 -0800 | [diff] [blame] | 55 | Return<void> registerDirectChannel( |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 56 | const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override; |
Peng Xu | 0f0df7e | 2017-01-05 23:39:08 -0800 | [diff] [blame] | 57 | |
| 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 Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 64 | private: |
Peng Xu | cefa91b | 2017-01-16 03:10:40 -0800 | [diff] [blame] | 65 | static constexpr int32_t kPollMaxBufferSize = 128; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 66 | status_t mInitCheck; |
| 67 | sensors_module_t *mSensorModule; |
| 68 | sensors_poll_device_1_t *mSensorDevice; |
Peng Xu | ab7884f | 2017-03-02 13:36:45 -0800 | [diff] [blame] | 69 | std::mutex mPollLock; |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 70 | |
| 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 | |
| 79 | extern "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_ |