• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "suspend_sources.h"
17 #include "power_log.h"
18 #include <string>
19 namespace OHOS {
20 namespace PowerMgr {
21 std::mutex SuspendSources::sourceKeysMutex_;
22 
mapSuspendDeviceType(const std::string & key)23 SuspendDeviceType SuspendSources::mapSuspendDeviceType(const std::string& key)
24 {
25     if (key == SuspendSources::POWERKEY_KEY) {
26         return SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY;
27     }
28 
29     if (key == SuspendSources::TIMEOUT_KEY) {
30         return SuspendDeviceType::SUSPEND_DEVICE_REASON_TIMEOUT;
31     }
32 
33     if (key == SuspendSources::LID_KEY) {
34         return SuspendDeviceType::SUSPEND_DEVICE_REASON_LID;
35     }
36 
37     if (key == SuspendSources::SWITCH_KEY) {
38         return SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH;
39     }
40 
41     return SuspendDeviceType::SUSPEND_DEVICE_REASON_MIN;
42 }
43 
getSourceKeys()44 std::vector<std::string> SuspendSources::getSourceKeys()
45 {
46     std::lock_guard<std::mutex> lock(sourceKeysMutex_);
47     std::vector<std::string> sourceKeys;
48     sourceKeys.push_back(SuspendSources::POWERKEY_KEY);
49     sourceKeys.push_back(SuspendSources::TIMEOUT_KEY);
50     sourceKeys.push_back(SuspendSources::LID_KEY);
51     sourceKeys.push_back(SuspendSources::SWITCH_KEY);
52     return sourceKeys;
53 }
54 
PutSource(SuspendSource & source)55 void SuspendSources::PutSource(SuspendSource& source)
56 {
57     std::lock_guard<std::mutex> lock(sourceListMutex_);
58     sourceList_.push_back(source);
59 }
60 
GetSourceList()61 std::vector<SuspendSource> SuspendSources::GetSourceList()
62 {
63     std::lock_guard<std::mutex> lock(sourceListMutex_);
64     return sourceList_;
65 }
66 
67 } // namespace PowerMgr
68 } // namespace OHOS