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