blob: 3a219cffbe3b2f65a93626d8e1ca3a1e3aabb375 [file] [log] [blame]
Tyler Trephan17857cc2021-11-16 21:23:12 +00001/*
2 * Copyright (C) 2021 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#pragma once
18
19#include "convertV2_1.h"
20
21#include <android/hardware/sensors/2.1/types.h>
22#include <fmq/MessageQueue.h>
23#include <hidl/MQDescriptor.h>
24#include <hidl/Status.h>
25#include <log/log.h>
26
27#include <atomic>
28
29namespace android {
30namespace hardware {
31namespace sensors {
32namespace V2_1 {
33namespace implementation {
34
35class WakeLockMessageQueueWrapperBase {
36 public:
37 virtual ~WakeLockMessageQueueWrapperBase() {}
38
39 virtual std::atomic<uint32_t>* getEventFlagWord() = 0;
40 virtual bool readBlocking(uint32_t* events, size_t numToRead, uint32_t readNotification,
41 uint32_t writeNotification, int64_t timeOutNanos,
42 ::android::hardware::EventFlag* evFlag = nullptr) = 0;
43 virtual bool write(const uint32_t* wakeLock) = 0;
44};
45
46class WakeLockMessageQueueWrapperHidl : public WakeLockMessageQueueWrapperBase {
47 public:
48 WakeLockMessageQueueWrapperHidl(
49 std::unique_ptr<::android::hardware::MessageQueue<uint32_t, kSynchronizedReadWrite>>&
50 queue)
51 : mQueue(std::move(queue)) {}
52
53 std::atomic<uint32_t>* getEventFlagWord() override { return mQueue->getEventFlagWord(); }
54
55 bool readBlocking(uint32_t* wakeLocks, size_t numToRead, uint32_t readNotification,
56 uint32_t writeNotification, int64_t timeOutNanos,
57 ::android::hardware::EventFlag* evFlag) override {
58 return mQueue->readBlocking(wakeLocks, numToRead, readNotification, writeNotification,
59 timeOutNanos, evFlag);
60 }
61
62 bool write(const uint32_t* wakeLock) override { return mQueue->write(wakeLock); }
63
64 private:
65 std::unique_ptr<::android::hardware::MessageQueue<uint32_t, kSynchronizedReadWrite>> mQueue;
66};
67
68} // namespace implementation
69} // namespace V2_1
70} // namespace sensors
71} // namespace hardware
72} // namespace android