• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "running_lock_inner.h"
17 
18 #include <datetime_ex.h>
19 
20 #include "power_common.h"
21 
22 namespace OHOS {
23 namespace PowerMgr {
RunningLockInner(const RunningLockInfo & runningLockInfo,const UserIPCInfo & userIPCinfo)24 RunningLockInner::RunningLockInner(const RunningLockInfo& runningLockInfo, const UserIPCInfo &userIPCinfo)
25 {
26     runningLockInfo_.name = runningLockInfo.name;
27     runningLockInfo_.type = runningLockInfo.type;
28     SetWorkTriggerList(runningLockInfo.workTriggerlist);
29     userIPCinfo_ = userIPCinfo;
30     lockTimeMs_ = GetTickCount();
31 }
32 
CreateRunningLockInner(const RunningLockInfo & runningLockInfo,const UserIPCInfo & userIPCinfo)33 std::shared_ptr<RunningLockInner> RunningLockInner::CreateRunningLockInner(const RunningLockInfo& runningLockInfo,
34     const UserIPCInfo &userIPCinfo)
35 {
36     std::shared_ptr<RunningLockInner> runningLockInner = std::make_shared<RunningLockInner>(runningLockInfo,
37         userIPCinfo);
38     if (runningLockInner == nullptr) {
39         POWER_HILOGE(MODULE_SERVICE, "failed to create new RunningLockInner record");
40         return nullptr;
41     }
42     POWER_HILOGI(MODULE_SERVICE, "RunningLockInner::%{public}s : name = %s, type = %d", __func__,
43         runningLockInfo.name.c_str(), runningLockInfo.type);
44     return runningLockInner;
45 }
46 
SetWorkTriggerList(const WorkTriggerList & workTriggerList)47 void RunningLockInner::SetWorkTriggerList(const WorkTriggerList& workTriggerList)
48 {
49     DumpInfo("before");
50     runningLockInfo_.workTriggerlist = workTriggerList;
51     DumpInfo("after");
52 }
53 
DumpInfo(const std::string & description)54 void RunningLockInner::DumpInfo(const std::string& description)
55 {
56     // this statement used to debug, can't find isDebugEnabled() interface. will be replaced later.
57     POWER_HILOGD(MODULE_SERVICE, "RunningLockInner::%{public}s :description = %s, name = %s, type = %d,", __func__,
58         description.c_str(), runningLockInfo_.name.c_str(), runningLockInfo_.type);
59 
60     auto& list = runningLockInfo_.workTriggerlist;
61     for (auto& worker : list) {
62         POWER_HILOGD(MODULE_SERVICE, "usecount = %ld, name = %s, uid = %d,"
63             " pid = %d, abilityid = %d", worker.use_count(), worker->GetName().c_str(),
64             worker->GetUid(), worker->GetPid(), worker->GetAbilityId());
65     }
66 }
67 } // namespace PowerMgr
68 } // namespace OHOS
69