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