1 /* 2 * Copyright (c) 2021-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 POWERMGR_RUNNING_LOCK_INNER_H 17 #define POWERMGR_RUNNING_LOCK_INNER_H 18 19 #include <mutex> 20 21 #include "actions/running_lock_action_info.h" 22 #include "power_common.h" 23 #include "running_lock_info.h" 24 25 namespace OHOS { 26 namespace PowerMgr { 27 enum class RunningLockState : uint32_t { 28 RUNNINGLOCK_STATE_DISABLE = 0, 29 RUNNINGLOCK_STATE_ENABLE, 30 RUNNINGLOCK_STATE_PROXIED, 31 RUNNINGLOCK_STATE_UNPROXIED_RESTORE, 32 }; 33 34 class RunningLockInner { 35 public: 36 RunningLockInner(const RunningLockParam& runningLockParam); 37 ~RunningLockInner() = default; 38 39 static std::shared_ptr<RunningLockInner> CreateRunningLockInner(const RunningLockParam& runningLockParam); 40 void DumpInfo(const std::string& description); 41 GetName()42 const std::string& GetName() const 43 { 44 return runningLockParam_.name; 45 } GetType()46 RunningLockType GetType() const 47 { 48 return runningLockParam_.type; 49 } GetPid()50 int32_t GetPid() const 51 { 52 return runningLockParam_.pid; 53 } GetUid()54 int32_t GetUid() const 55 { 56 return runningLockParam_.uid; 57 } SetTimeOutMs(int32_t timeoutMs)58 void SetTimeOutMs(int32_t timeoutMs) 59 { 60 runningLockParam_.timeoutMs = timeoutMs; 61 } GetTimeOutMs()62 int32_t GetTimeOutMs() const 63 { 64 return runningLockParam_.timeoutMs; 65 } GetParam()66 const RunningLockParam& GetParam() const 67 { 68 return runningLockParam_; 69 } SetState(RunningLockState state)70 void SetState(RunningLockState state) 71 { 72 state_ = state; 73 } GetState()74 RunningLockState GetState() const 75 { 76 return state_; 77 } IsProxied()78 bool IsProxied() const 79 { 80 return state_ == RunningLockState::RUNNINGLOCK_STATE_PROXIED || 81 state_ == RunningLockState::RUNNINGLOCK_STATE_UNPROXIED_RESTORE; 82 } SetOverTimeFlag(bool overTimeFlag)83 void SetOverTimeFlag(bool overTimeFlag) 84 { 85 overTimeFlag_ = overTimeFlag; 86 } GetOverTimeFlag()87 bool GetOverTimeFlag() const 88 { 89 return overTimeFlag_; 90 } GetLockTimeMs()91 int64_t GetLockTimeMs() const 92 { 93 return lockTimeMs_; 94 } 95 96 private: 97 std::mutex mutex_; 98 RunningLockParam runningLockParam_; 99 RunningLockState state_ = RunningLockState::RUNNINGLOCK_STATE_DISABLE; 100 bool overTimeFlag_ = false; 101 int64_t lockTimeMs_ = 0; 102 }; 103 } // namespace PowerMgr 104 } // namespace OHOS 105 #endif // POWERMGR_RUNNING_LOCK_INNER_H 106