1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_HDI_POWER_V1_1_RUNNINGLOCKIMPL_H 17 #define OHOS_HDI_POWER_V1_1_RUNNINGLOCKIMPL_H 18 19 #include <cstdint> 20 #include <map> 21 #include <mutex> 22 23 #include "running_lock_counter.h" 24 #include "running_lock_timer_handler.h" 25 #include "v1_1/power_types.h" 26 #include "v1_1/running_lock_types.h" 27 28 namespace OHOS { 29 namespace HDI { 30 namespace Power { 31 namespace V1_1 { 32 class RunningLockImpl { 33 public: 34 static int32_t Hold(const RunningLockInfo &info, PowerHdfState state); 35 static int32_t Unhold(const RunningLockInfo &info); 36 static uint32_t GetCount(RunningLockType type); 37 static std::string GetRunningLockTag(RunningLockType type); 38 static void SetDefaultTimeOutMs(int32_t timeOutMs); 39 40 private: 41 static bool IsValidType(RunningLockType type, PowerHdfState state = PowerHdfState::AWAKE); 42 static RunningLockInfo FillRunningLockInfo(const RunningLockInfo &info); 43 static std::mutex mutex_; 44 static int32_t defaultTimeOutMs_; 45 static std::unique_ptr<RunningLockTimerHandler> timerHandler_; 46 static std::map<RunningLockType, std::shared_ptr<RunningLockCounter>> lockCounters_; 47 }; 48 49 } // namespace V1_1 50 } // namespace Power 51 } // namespace HDI 52 } // namespace OHOS 53 54 #endif // OHOS_HDI_POWER_V1_1_RUNNINGLOCKIMPL_H 55