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_ACTION_SOURCES_H 17 #define POWERMGR_WAKEUP_ACTION_SOURCES_H 18 19 #include <cstdint> 20 #include <map> 21 #include <mutex> 22 23 #include "power_state_machine_info.h" 24 25 namespace OHOS { 26 namespace PowerMgr { 27 enum class WakeupAction : uint32_t { 28 ACTION_NONE = 0, // no action 29 ACTION_HIBERNATE, // entry hibernate 30 ACTION_SHUTDOWN, // shutdown 31 ACTION_INVALID 32 }; 33 34 class WakeupActionSource { 35 public: 36 static const constexpr char* SCENE_KEY = "scene"; 37 static const constexpr char* ACTION_KEY = "action"; 38 WakeupActionSource(std::string scene,uint32_t action)39 explicit WakeupActionSource(std::string scene, uint32_t action) 40 { 41 scene_ = scene; 42 action_ = action; 43 } 44 ~WakeupActionSource() = default; GetScene()45 std::string GetScene() const 46 { 47 return scene_; 48 } GetAction()49 uint32_t GetAction() const 50 { 51 return action_; 52 } 53 54 private: 55 std::string scene_; 56 uint32_t action_; 57 }; 58 59 class WakeupActionSources { 60 public: 61 static const constexpr char* LOW_CAPACITY_KEY = "53"; 62 WakeupActionSources() = default; 63 ~WakeupActionSources() = default; 64 static SuspendDeviceType mapSuspendDeviceType(const std::string& reason); 65 void PutSource(const std::string& key, std::shared_ptr<WakeupActionSource>& source); 66 std::map<std::string, std::shared_ptr<WakeupActionSource>> GetSourceMap(); 67 68 private: 69 std::map<std::string, std::shared_ptr<WakeupActionSource>> sourceMap_; 70 std::mutex sourceMapMutex_; 71 }; 72 73 } // namespace PowerMgr 74 } // namespace OHOS 75 76 #endif // POWERMGR_WAKEUP_ACTION_SOURCES_H