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 29 public: 30 DISALLOW_COPY_AND_MOVE(SleepCallbackHolder); 31 void AddCallback(const sptr<ISyncSleepCallback>& callback, SleepPriority priority); 32 void RemoveCallback(const sptr<ISyncSleepCallback>& callback); 33 34 std::set<sptr<ISyncSleepCallback>> GetHighPriorityCallbacks(); 35 std::set<sptr<ISyncSleepCallback>> GetDefaultPriorityCallbacks(); 36 std::set<sptr<ISyncSleepCallback>> GetLowPriorityCallbacks(); 37 38 private: 39 static void RemoveCallback(std::set<sptr<ISyncSleepCallback>>& callbacks, const sptr<ISyncSleepCallback>& callback); 40 41 std::mutex mutex_; 42 std::set<sptr<ISyncSleepCallback>> highPriorityCallbacks_; 43 std::set<sptr<ISyncSleepCallback>> defaultPriorityCallbacks_; 44 std::set<sptr<ISyncSleepCallback>> lowPriorityCallbacks_; 45 }; 46 } // namespace PowerMgr 47 } // namespace OHOS 48 49 #endif // POWERMGR_POWER_MANAGER_SLEEP_CALLBACK_HOLER_H 50