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_RUNNINGLOCKCOUNTER_H 17 #define OHOS_HDI_POWER_V1_2_RUNNINGLOCKCOUNTER_H 18 19 #include <cstdint> 20 #include <map> 21 22 #include "v1_2/running_lock_types.h" 23 24 namespace OHOS { 25 namespace HDI { 26 namespace Power { 27 namespace V1_2 { 28 class RunningLockCounter { 29 public: RunningLockCounter(RunningLockType type,const std::string & tag)30 RunningLockCounter(RunningLockType type, const std::string &tag) 31 : type_(type), tag_(tag), counter_(0) {} 32 ~RunningLockCounter() = default; 33 int32_t Increase(const RunningLockInfo &info); 34 int32_t Decrease(const RunningLockInfo &info); 35 void Clean(); GetCount()36 uint32_t GetCount() const 37 { 38 return counter_; 39 } GetType()40 RunningLockType GetType() const 41 { 42 return type_; 43 } 44 private: 45 enum ChangedType { 46 NOTIFY_RUNNINGLOCK_ADD, 47 NOTIFY_RUNNINGLOCK_REMOVE, 48 NOTIFY_RUNNINGLOCK_OVERTIME, 49 RUNNINGLOCK_CHANGED_BUTT 50 }; 51 enum class RunningLockState : uint32_t { 52 RUNNINGLOCK_STATE_DISABLE = 0, 53 RUNNINGLOCK_STATE_ENABLE = 1, 54 }; 55 void NotifyHiView(const RunningLockInfo &info, ChangedType changeType, RunningLockState state); 56 const std::array<std::string, RUNNINGLOCK_CHANGED_BUTT> runninglockNotifyStr_ { 57 "DUBAI_TAG_RUNNINGLOCK_ADD", "DUBAI_TAG_RUNNINGLOCK_REMOVE", "DUBAI_TAG_RUNNINGLOCK_OVERTIME" 58 }; 59 const RunningLockType type_; 60 const std::string tag_; 61 uint32_t counter_; 62 std::map<std::string, RunningLockInfo> runninglockInfos_ {}; 63 }; 64 } // namespace V1_2 65 } // namespace Power 66 } // namespace HDI 67 } // namespace OHOS 68 69 #endif // OHOS_HDI_POWER_V1_2_RUNNINGLOCKCOUNTER_H 70