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 #pragma once 18 19 #include <condition_variable> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 #include <thread> 24 25 namespace aidl { 26 namespace google { 27 namespace hardware { 28 namespace power { 29 namespace impl { 30 namespace pixel { 31 32 enum InteractionState { 33 INTERACTION_STATE_UNINITIALIZED, 34 INTERACTION_STATE_IDLE, 35 INTERACTION_STATE_INTERACTION, 36 INTERACTION_STATE_WAITING, 37 }; 38 39 class InteractionHandler { 40 public: 41 InteractionHandler(); 42 ~InteractionHandler(); 43 bool Init(); 44 void Exit(); 45 void Acquire(int32_t duration); 46 47 private: 48 void Release(); 49 void WaitForIdle(int32_t wait_ms, int32_t timeout_ms); 50 void AbortWaitLocked(); 51 void Routine(); 52 53 void PerfLock(); 54 void PerfRel(); 55 56 enum InteractionState mState; 57 int mIdleFd; 58 int mEventFd; 59 int32_t mDurationMs; 60 struct timespec mLastTimespec; 61 std::unique_ptr<std::thread> mThread; 62 std::mutex mLock; 63 std::condition_variable mCond; 64 }; 65 66 } // namespace pixel 67 } // namespace impl 68 } // namespace power 69 } // namespace hardware 70 } // namespace google 71 } // namespace aidl 72