blob: 15a713a7524c2d088f8115206a118cfb641e1935 [file] [log] [blame]
Brian Stack60fcdcf2018-10-16 14:51:34 -07001/*
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 Stack475d4d42018-10-19 15:58:09 -070021#include <fmq/MessageQueue.h>
Brian Stack60fcdcf2018-10-16 14:51:34 -070022#include <hidl/MQDescriptor.h>
23#include <hidl/Status.h>
24
Brian Stack475d4d42018-10-19 15:58:09 -070025#include <memory>
26
Brian Stack60fcdcf2018-10-16 14:51:34 -070027namespace android {
28namespace hardware {
29namespace sensors {
30namespace V2_0 {
31namespace implementation {
32
33using ::android::sp;
Brian Stack475d4d42018-10-19 15:58:09 -070034using ::android::hardware::EventFlag;
Brian Stack60fcdcf2018-10-16 14:51:34 -070035using ::android::hardware::hidl_array;
36using ::android::hardware::hidl_memory;
37using ::android::hardware::hidl_string;
38using ::android::hardware::hidl_vec;
Brian Stack475d4d42018-10-19 15:58:09 -070039using ::android::hardware::MessageQueue;
40using ::android::hardware::MQDescriptor;
Brian Stack60fcdcf2018-10-16 14:51:34 -070041using ::android::hardware::Return;
42using ::android::hardware::Void;
43
44struct 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 Stack475d4d42018-10-19 15:58:09 -070051 Sensors();
52 virtual ~Sensors();
53
Brian Stack60fcdcf2018-10-16 14:51:34 -070054 // 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 Stack475d4d42018-10-19 15:58:09 -070080
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 Stack60fcdcf2018-10-16 14:51:34 -0700109};
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