1 /* 2 * Copyright (c) 2024 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_POWER_MANAGER_HIBERNATE_CONTROLLER_H 17 #define POWERMGR_POWER_MANAGER_HIBERNATE_CONTROLLER_H 18 19 #include <set> 20 #include <map> 21 22 #include "ipc_skeleton.h" 23 #include "hibernate/isync_hibernate_callback.h" 24 25 namespace OHOS { 26 namespace PowerMgr { 27 enum class HibernateStatus { 28 HIBERNATE_SUCCESS = 0, 29 HIBERNATE_FAILURE, 30 HIBERNATE_INVALID_STATUS, 31 }; 32 class HibernateController { 33 public: 34 struct HibernateCallbackCompare { operatorHibernateCallbackCompare35 bool operator()(const sptr<ISyncHibernateCallback>& lhs, const sptr<ISyncHibernateCallback>& rhs) const 36 { 37 return lhs->AsObject() < rhs->AsObject(); 38 } 39 }; 40 using HibernateCallbackContainerType = std::set<sptr<ISyncHibernateCallback>, HibernateCallbackCompare>; 41 using HibernateCallbackCacheRegister = 42 std::map<sptr<ISyncHibernateCallback>, std::pair<int32_t, int32_t>, HibernateCallbackCompare>; HibernateController()43 HibernateController() {}; 44 virtual ~HibernateController() = default; 45 46 virtual HibernateStatus Hibernate(bool clearMemory); 47 virtual void RegisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& cb); 48 virtual void UnregisterSyncHibernateCallback(const sptr<ISyncHibernateCallback>& cb); 49 virtual void PreHibernate(); 50 virtual void PostHibernate(bool hibernateResult = false); 51 52 private: 53 bool prepared_ {false}; 54 std::mutex mutex_; 55 HibernateCallbackContainerType callbacks_; 56 HibernateCallbackCacheRegister cachedRegister_; 57 }; 58 } // namespace PowerMgr 59 } // namespace OHOS 60 61 #endif // POWERMGR_POWER_MANAGER_HIBERNATE_CONTROLLER_H 62