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 <mutex> 22#include <string> 23#include <vector> 24 25namespace OHOS { 26namespace PowerMgr { 27enum class WakeUpAction : uint32_t { CLICK_SINGLE = 1, CLICK_DOUBLE = 2 }; 28 29class WakeupSource { 30public: 31 static const constexpr char* ENABLE_KEY = "enable"; 32 static const constexpr char* KEYS_KEY = "click"; 33 34 WakeupSource(WakeupDeviceType reason, bool enable, uint32_t click) : reason_(reason), enable_(enable), click_(click) 35 { 36 } 37 ~WakeupSource() = default; 38 39 WakeupDeviceType GetReason() const 40 { 41 return reason_; 42 } 43 44 bool IsEnable() const 45 { 46 return enable_; 47 } 48 49 uint32_t GetClick() const 50 { 51 return click_; 52 } 53 54private: 55 WakeupDeviceType reason_; 56 bool enable_; 57 uint32_t click_; 58}; 59 60class WakeupSources { 61public: 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 char* PICKUP_KEY = "pickup"; 71 static const constexpr uint32_t SINGLE_CLICK = 1; 72 static const constexpr uint32_t DOUBLC_CLICK = 2; 73 74 WakeupSources() = default; 75 ~WakeupSources() = default; 76 static WakeupDeviceType mapWakeupDeviceType(const std::string& key, uint32_t click); 77 static std::vector<std::string> getSourceKeys(); 78 void PutSource(WakeupSource& source); 79 std::vector<WakeupSource> GetSourceList(); 80 81private: 82 std::vector<WakeupSource> sourceList_; 83 std::mutex sourceListMutex_; 84 static std::mutex sourceKeysMutex_; 85}; 86 87} // namespace PowerMgr 88} // namespace OHOS 89 90#endif // POWERMGR_SUSPEND_SOURCES_H