1 /* 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 29 namespace android { 30 namespace hardware { 31 namespace sensors { 32 namespace V2_1 { 33 namespace implementation { 34 35 class WakeLockMessageQueueWrapperBase { 36 public: ~WakeLockMessageQueueWrapperBase()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 46 class WakeLockMessageQueueWrapperHidl : public WakeLockMessageQueueWrapperBase { 47 public: WakeLockMessageQueueWrapperHidl(std::unique_ptr<::android::hardware::MessageQueue<uint32_t,kSynchronizedReadWrite>> & queue)48 WakeLockMessageQueueWrapperHidl( 49 std::unique_ptr<::android::hardware::MessageQueue<uint32_t, kSynchronizedReadWrite>>& 50 queue) 51 : mQueue(std::move(queue)) {} 52 getEventFlagWord()53 std::atomic<uint32_t>* getEventFlagWord() override { return mQueue->getEventFlagWord(); } 54 readBlocking(uint32_t * wakeLocks,size_t numToRead,uint32_t readNotification,uint32_t writeNotification,int64_t timeOutNanos,::android::hardware::EventFlag * evFlag)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 write(const uint32_t * wakeLock)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 73