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 static const constexpr char* POWERKEY_KEY = "powerkey"; 63 static const constexpr char* MOUSE_KEY = "mouse"; 64 static const constexpr char* KEYBOARD_KEY = "keyborad"; 65 static const constexpr char* TOUCHSCREEN_KEY = "touchscreen"; 66 static const constexpr char* TOUCHPAD_KEY = "touchpad"; 67 static const constexpr char* PEN_KEY = "pen"; 68 static const constexpr char* LID_KEY = "lid"; 69 static const constexpr char* SWITCH_KEY = "switch"; 70 static const constexpr uint32_t SINGLE_CLICK = 1; 71 static const constexpr uint32_t DOUBLC_CLICK = 2; 72 73 WakeupSources() = default; 74 ~WakeupSources() = default; 75 static WakeupDeviceType mapWakeupDeviceType(const std::string& key, uint32_t click); 76 static std::vector<std::string> getSourceKeys(); 77 void PutSource(WakeupSource& source); 78 std::vector<WakeupSource> GetSourceList(); 79 80 private: 81 std::vector<WakeupSource> 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