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_WAKEUP_SOURCES_H 17 #define POWERMGR_WAKEUP_SOURCES_H 18 19 #include "power_state_machine_info.h" 20 #include <cstdint> 21 #include <string> 22 #include <vector> 23 #include <mutex> 24 25 namespace OHOS { 26 namespace PowerMgr { 27 enum class WakeUpAction : uint32_t { CLICK_SINGLE = 1, CLICK_DOUBLE = 2 }; 28 29 class WakeupSource { 30 public: 31 static const constexpr char* ENABLE_KEY = "enable"; 32 static const constexpr char* KEYS_KEY = "click"; 33 WakeupSource(WakeupDeviceType reason,bool enable,uint32_t click)34 WakeupSource(WakeupDeviceType reason, bool enable, uint32_t click) : reason_(reason), enable_(enable), click_(click) 35 { 36 } 37 ~WakeupSource() = default; 38 GetReason()39 WakeupDeviceType GetReason() const 40 { 41 return reason_; 42 } 43 IsEnable()44 bool IsEnable() const 45 { 46 return enable_; 47 } 48 GetClick()49 uint32_t GetClick() const 50 { 51 return click_; 52 } 53 54 private: 55 WakeupDeviceType reason_; 56 bool enable_; 57 uint32_t click_; 58 }; 59 60 class WakeupSources { 61 public: 62 WakeupSources() = default; 63 ~WakeupSources() = default; 64 65 static const constexpr char* POWERKEY_KEY = "powerkey"; 66 static const constexpr char* MOUSE_KEY = "mouse"; 67 static const constexpr char* KEYBOARD_KEY = "keyborad"; 68 static const constexpr char* TOUCHSCREEN_KEY = "touchscreen"; 69 static const constexpr char* TOUCHPAD_KEY = "touchpad"; 70 static const constexpr char* PEN_KEY = "pen"; 71 static const constexpr char* LID_KEY = "lid"; 72 static const constexpr char* SWITCH_KEY = "switch"; 73 static const constexpr char* PICKUP_KEY = "pickup"; 74 static const constexpr uint32_t SINGLE_CLICK = 1; 75 static const constexpr uint32_t DOUBLC_CLICK = 2; 76 77 static WakeupDeviceType mapWakeupDeviceType(const std::string& key, uint32_t click); 78 static std::vector<std::string> getSourceKeys(); 79 void PutSource(WakeupSource& source); 80 std::vector<WakeupSource> GetSourceList(); GetParseErrorFlag()81 bool GetParseErrorFlag() const 82 { 83 return parseErrorFlag_; 84 } 85 SetParseErrorFlag(bool flag)86 void SetParseErrorFlag(bool flag) 87 { 88 parseErrorFlag_ = flag; 89 } 90 91 private: 92 static std::mutex sourceKeysMutex_; 93 std::vector<WakeupSource> sourceList_; 94 std::mutex sourceListMutex_; 95 bool parseErrorFlag_ {false}; 96 }; 97 98 } // namespace PowerMgr 99 } // namespace OHOS 100 101 #endif // POWERMGR_SUSPEND_SOURCES_H