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