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_RUNNINGLOCK_TIMERHANDKER_H 17 #define OHOS_HDI_POWER_V1_1_RUNNINGLOCK_TIMERHANDKER_H 18 19 #include <cstdint> 20 #include <map> 21 #include <timer.h> 22 23 #include "v1_1/running_lock_types.h" 24 25 namespace OHOS { 26 namespace HDI { 27 namespace Power { 28 namespace V1_1 { 29 class RunningLockTimerHandler { 30 public: 31 RunningLockTimerHandler() = default; 32 ~RunningLockTimerHandler(); 33 34 bool RegisterRunningLockTimer(const RunningLockInfo &info, const std::function<void()> &callback, bool once = true); 35 bool UnregisterRunningLockTimer(const RunningLockInfo &info); 36 37 private: 38 uint32_t GetRunningLockTimerId(RunningLockType type, std::string name); 39 void AddRunningLockTimerMap(RunningLockType type, std::string name, uint32_t timerId); 40 void RemoveRunningLockTimerMap(RunningLockType type, std::string name); 41 void UnregisterTimer(uint32_t timerId); 42 std::unique_ptr<OHOS::Utils::Timer> handlerTimer_; 43 std::map<RunningLockType, std::map<std::string, uint32_t>> runninglockTimerMap_; 44 }; 45 } // namespace V1_1 46 } // namespace Power 47 } // namespace HDI 48 } // namespace OHOS 49 50 #endif // OHOS_HDI_POWER_V1_1_RUNNINGLOCK_TIMERHANDKER_H