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