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_POWER_MANAGER_SLEEP_CALLBACK_HOLER_H 17 #define POWERMGR_POWER_MANAGER_SLEEP_CALLBACK_HOLER_H 18 19 #include <set> 20 #include <singleton.h> 21 #include "iremote_object.h" 22 #include "suspend/isync_sleep_callback.h" 23 24 namespace OHOS { 25 namespace PowerMgr { 26 class SleepCallbackHolder final : public DelayedRefSingleton<SleepCallbackHolder> { 27 DECLARE_DELAYED_REF_SINGLETON(SleepCallbackHolder); 28 DISALLOW_COPY_AND_MOVE(SleepCallbackHolder); 29 public: 30 struct SleepCallbackCompare { operatorSleepCallbackCompare31 bool operator()(const sptr<ISyncSleepCallback>& lhs, const sptr<ISyncSleepCallback>& rhs) const 32 { 33 return lhs->AsObject() < rhs->AsObject(); 34 } 35 }; 36 37 using SleepCallbackContainerType = std::set<sptr<ISyncSleepCallback>, SleepCallbackCompare>; 38 void AddCallback(const sptr<ISyncSleepCallback>& callback, SleepPriority priority); 39 void RemoveCallback(const sptr<ISyncSleepCallback>& callback); 40 SleepCallbackContainerType GetHighPriorityCallbacks(); 41 SleepCallbackContainerType GetDefaultPriorityCallbacks(); 42 SleepCallbackContainerType GetLowPriorityCallbacks(); 43 44 private: 45 static void RemoveCallback(SleepCallbackContainerType& callbacks, const sptr<ISyncSleepCallback>& callback); 46 47 std::mutex mutex_; 48 SleepCallbackContainerType highPriorityCallbacks_; 49 SleepCallbackContainerType defaultPriorityCallbacks_; 50 SleepCallbackContainerType lowPriorityCallbacks_; 51 }; 52 } // namespace PowerMgr 53 } // namespace OHOS 54 55 #endif // POWERMGR_POWER_MANAGER_SLEEP_CALLBACK_HOLER_H 56