1 /* 2 * Copyright (c) 2022 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 #ifndef FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_BATTERY_STATUS_LISTENER_H 16 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_BATTERY_STATUS_LISTENER_H 17 18 #ifdef POWERMGR_BATTERY_MANAGER_ENABLE 19 #include <memory> 20 21 #include "common_event_subscriber.h" 22 #include "icondition_listener.h" 23 #include "work_queue_manager.h" 24 25 namespace OHOS { 26 namespace WorkScheduler { 27 class WorkQueueManager; 28 class BatteryStatusListener : public IConditionListener { 29 public: 30 explicit BatteryStatusListener(std::shared_ptr<WorkQueueManager> workQueueManager); 31 ~BatteryStatusListener() override; 32 33 /** 34 * @brief The OnConditionChanged callback. 35 * 36 * @param conditionType The condition type. 37 * @param conditionVal The condition val. 38 */ 39 void OnConditionChanged(WorkCondition::Type conditionType, 40 std::shared_ptr<DetectorValue> conditionVal) override; 41 /** 42 * @brief Start. 43 * 44 * @return True if success,else false. 45 */ 46 bool Start() override; 47 /** 48 * @brief Stop. 49 * 50 * @return True if success,else false. 51 */ 52 bool Stop() override; 53 private: 54 std::shared_ptr<WorkQueueManager> workQueueManager_; 55 std::shared_ptr<EventFwk::CommonEventSubscriber> commonEventSubscriber = nullptr; 56 }; 57 58 class BatteryStatusEventSubscriber : public EventFwk::CommonEventSubscriber { 59 public: 60 BatteryStatusEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, 61 BatteryStatusListener &listener); 62 ~BatteryStatusEventSubscriber() override = default; 63 /** 64 * @brief The OnReceiveEvent callback. 65 * 66 * @param data The data. 67 */ 68 void OnReceiveEvent(const EventFwk::CommonEventData &data) override; 69 private: 70 BatteryStatusListener &listener_; 71 }; 72 } // namespace WorkScheduler 73 } // namespace OHOS 74 #endif // POWERMGR_BATTERY_MANAGER_ENABLE 75 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_BATTERY_STATUS_LISTENER_H