Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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_HARDWARE_SENSORS_V2_0_SENSORS_H |
| 18 | #define ANDROID_HARDWARE_SENSORS_V2_0_SENSORS_H |
| 19 | |
| 20 | #include <android/hardware/sensors/2.0/ISensors.h> |
Brian Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame^] | 21 | #include <fmq/MessageQueue.h> |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 22 | #include <hidl/MQDescriptor.h> |
| 23 | #include <hidl/Status.h> |
| 24 | |
Brian Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame^] | 25 | #include <memory> |
| 26 | |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | namespace sensors { |
| 30 | namespace V2_0 { |
| 31 | namespace implementation { |
| 32 | |
| 33 | using ::android::sp; |
Brian Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame^] | 34 | using ::android::hardware::EventFlag; |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 35 | using ::android::hardware::hidl_array; |
| 36 | using ::android::hardware::hidl_memory; |
| 37 | using ::android::hardware::hidl_string; |
| 38 | using ::android::hardware::hidl_vec; |
Brian Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame^] | 39 | using ::android::hardware::MessageQueue; |
| 40 | using ::android::hardware::MQDescriptor; |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 41 | using ::android::hardware::Return; |
| 42 | using ::android::hardware::Void; |
| 43 | |
| 44 | struct Sensors : public ISensors { |
| 45 | using Event = ::android::hardware::sensors::V1_0::Event; |
| 46 | using OperationMode = ::android::hardware::sensors::V1_0::OperationMode; |
| 47 | using RateLevel = ::android::hardware::sensors::V1_0::RateLevel; |
| 48 | using Result = ::android::hardware::sensors::V1_0::Result; |
| 49 | using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo; |
| 50 | |
Brian Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame^] | 51 | Sensors(); |
| 52 | virtual ~Sensors(); |
| 53 | |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 54 | // Methods from ::android::hardware::sensors::V2_0::ISensors follow. |
| 55 | Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override; |
| 56 | |
| 57 | Return<Result> setOperationMode(OperationMode mode) override; |
| 58 | |
| 59 | Return<Result> activate(int32_t sensorHandle, bool enabled) override; |
| 60 | |
| 61 | Return<Result> initialize( |
| 62 | const ::android::hardware::MQDescriptorSync<Event>& eventQueueDescriptor, |
| 63 | const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor, |
| 64 | const sp<ISensorsCallback>& sensorsCallback) override; |
| 65 | |
| 66 | Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs, |
| 67 | int64_t maxReportLatencyNs) override; |
| 68 | |
| 69 | Return<Result> flush(int32_t sensorHandle) override; |
| 70 | |
| 71 | Return<Result> injectSensorData(const Event& event) override; |
| 72 | |
| 73 | Return<void> registerDirectChannel(const SharedMemInfo& mem, |
| 74 | registerDirectChannel_cb _hidl_cb) override; |
| 75 | |
| 76 | Return<Result> unregisterDirectChannel(int32_t channelHandle) override; |
| 77 | |
| 78 | Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate, |
| 79 | configDirectReport_cb _hidl_cb) override; |
Brian Stack | 475d4d4 | 2018-10-19 15:58:09 -0700 | [diff] [blame^] | 80 | |
| 81 | private: |
| 82 | /** |
| 83 | * Utility function to delete the Event Flag |
| 84 | */ |
| 85 | void deleteEventFlag(); |
| 86 | |
| 87 | using EventMessageQueue = MessageQueue<Event, kSynchronizedReadWrite>; |
| 88 | using WakeLockMessageQueue = MessageQueue<uint32_t, kSynchronizedReadWrite>; |
| 89 | |
| 90 | /** |
| 91 | * The Event FMQ where sensor events are written |
| 92 | */ |
| 93 | std::unique_ptr<EventMessageQueue> mEventQueue; |
| 94 | |
| 95 | /** |
| 96 | * The Wake Lock FMQ that is read to determine when the framework has handled WAKE_UP events |
| 97 | */ |
| 98 | std::unique_ptr<WakeLockMessageQueue> mWakeLockQueue; |
| 99 | |
| 100 | /** |
| 101 | * Event Flag to signal to the framework when sensor events are available to be read |
| 102 | */ |
| 103 | EventFlag* mEventQueueFlag; |
| 104 | |
| 105 | /** |
| 106 | * Callback for asynchronous events, such as dynamic sensor connections. |
| 107 | */ |
| 108 | sp<ISensorsCallback> mCallback; |
Brian Stack | 60fcdcf | 2018-10-16 14:51:34 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | } // namespace implementation |
| 112 | } // namespace V2_0 |
| 113 | } // namespace sensors |
| 114 | } // namespace hardware |
| 115 | } // namespace android |
| 116 | |
| 117 | #endif // ANDROID_HARDWARE_SENSORS_V2_0_SENSORS_H |