/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_RESOURCES_INCLUDE_RESOURCES_SUBSCRIBER_MGR_H #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_RESOURCES_INCLUDE_RESOURCES_SUBSCRIBER_MGR_H #include #include #include #include #include "singleton.h" #include "iremote_object.h" #include "bgtaskmgr_inner_errors.h" #include "ibackground_task_subscriber.h" namespace OHOS { namespace BackgroundTaskMgr { class ObserverDeathRecipient; enum class EfficiencyResourcesEventType: uint32_t { APP_RESOURCE_APPLY, APP_RESOURCE_RESET, RESOURCE_APPLY, RESOURCE_RESET, }; enum : int32_t { HISYSEVENT_APP_RESOURCE_APPLY = -1, HISYSEVENT_APP_RESOURCE_RESET = -2, HISYSEVENT_RESOURCE_APPLY = -3, HISYSEVENT_RESOURCE_RESET = -4, }; class ResourcesSubscriberMgr : public std::enable_shared_from_this { DECLARE_DELAYED_SINGLETON(ResourcesSubscriberMgr); public: ErrCode AddSubscriber(const sptr &subscriber); ErrCode RemoveSubscriber(const sptr &subscriber); void OnResourceChanged(const std::shared_ptr &callbackInfo, EfficiencyResourcesEventType type); void HandleSubscriberDeath(const wptr& remote); private: void HiSysEventResources(const std::shared_ptr callbackInfo, EfficiencyResourcesEventType type); void HiSysEventSubmit(const std::shared_ptr callbackInfo, int32_t hiSysEventType, const std::string &eventType); std::mutex subscriberLock_; std::list> subscriberList_ {}; sptr deathRecipient_ {nullptr}; }; class ObserverDeathRecipient final : public IRemoteObject::DeathRecipient { public: DISALLOW_COPY_AND_MOVE(ObserverDeathRecipient); explicit ObserverDeathRecipient(); ~ObserverDeathRecipient() override; void OnRemoteDied(const wptr& remote) override; }; } // namespace BackgroundTaskMgr } // namespace OHOS #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_RESOURCES_INCLUDE_RESOURCES_SUBSCRIBER_MGR_H