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_2_RUNNINGLOCK_TIMERHANDKER_H
17 #define OHOS_HDI_POWER_V1_2_RUNNINGLOCK_TIMERHANDKER_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <timer.h>
22 
23 #include "v1_2/running_lock_types.h"
24 
25 namespace OHOS {
26 namespace HDI {
27 namespace Power {
28 namespace V1_2 {
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     void Clean();
37 
38 private:
39     uint32_t GetRunningLockTimerId(RunningLockType type, std::string name);
40     void AddRunningLockTimerMap(RunningLockType type, std::string name, uint32_t timerId);
41     void RemoveRunningLockTimerMap(RunningLockType type, std::string name);
42     void UnregisterTimer(uint32_t timerId);
43     std::unique_ptr<OHOS::Utils::Timer> handlerTimer_;
44     std::map<RunningLockType, std::map<std::string, uint32_t>> runninglockTimerMap_;
45 };
46 } // namespace V1_2
47 } // namespace Power
48 } // namespace HDI
49 } // namespace OHOS
50 
51 #endif // OHOS_HDI_POWER_V1_2_RUNNINGLOCK_TIMERHANDKER_H
52