• 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 #ifndef POWERMGR_SUSPEND_SOURCES_H
17 #define POWERMGR_SUSPEND_SOURCES_H
18 
19 #include "power_state_machine_info.h"
20 #include <cstdint>
21 #include <vector>
22 #include <mutex>
23 
24 namespace OHOS {
25 namespace PowerMgr {
26 enum class SuspendAction : uint32_t {
27     ACTION_NONE = 0,      //  no action
28     ACTION_AUTO_SUSPEND,  //  automatically enter sleep
29     ACTION_FORCE_SUSPEND, //  force enter sleep
30     ACTION_HIBERNATE,     //  entry hibernate
31     ACTION_SHUTDOWN,      //  shutdown
32     ACTION_INVALID,
33     ACTION_MAC = ACTION_INVALID
34 };
35 
36 class SuspendSource {
37 public:
38     static const constexpr char* ACTION_KEY = "action";
39     static const constexpr char* DELAY_KEY = "delayMs";
40 
SuspendSource(SuspendDeviceType reason,uint32_t action,uint32_t delay)41     SuspendSource(SuspendDeviceType reason, uint32_t action, uint32_t delay)
42     {
43         reason_ = reason;
44         action_ = action;
45         delayMs_ = delay;
46     }
47     ~SuspendSource() = default;
GetReason()48     SuspendDeviceType GetReason() const
49     {
50         return reason_;
51     }
GetAction()52     uint32_t GetAction() const
53     {
54         return action_;
55     }
GetDelay()56     uint32_t GetDelay() const
57     {
58         return delayMs_;
59     }
60 
61 private:
62     SuspendDeviceType reason_;
63     uint32_t action_;
64     uint32_t delayMs_;
65 };
66 
67 class SuspendSources {
68 public:
69     static const constexpr char* POWERKEY_KEY = "powerkey";
70     static const constexpr char* TIMEOUT_KEY = "timeout";
71     static const constexpr char* LID_KEY = "lid";
72     static const constexpr char* SWITCH_KEY = "switch";
73     SuspendSources() = default;
74     ~SuspendSources() = default;
75     static SuspendDeviceType mapSuspendDeviceType(const std::string& key);
76     static std::vector<std::string> getSourceKeys();
77     void PutSource(SuspendSource& source);
78     std::vector<SuspendSource> GetSourceList();
79 
80 private:
81     std::vector<SuspendSource> sourceList_;
82     std::mutex sourceListMutex_;
83     static std::mutex sourceKeysMutex_;
84 };
85 
86 } // namespace PowerMgr
87 } // namespace OHOS
88 
89 #endif // POWERMGR_SUSPEND_SOURCES_H