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_GROUP_LISTENER_H
16 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_GROUP_LISTENER_H
17 
18 #include <memory>
19 #include <string>
20 
21 #include "icondition_listener.h"
22 #include "work_queue_event_handler.h"
23 #include "work_queue_manager.h"
24 #include "work_scheduler_service.h"
25 
26 namespace OHOS {
27 namespace WorkScheduler {
28 class GroupListener : public IConditionListener {
29 public:
30     explicit GroupListener(std::shared_ptr<WorkQueueManager> workQueueManager,
31         const std::shared_ptr<AppExecFwk::EventRunner>& runner);
32     ~GroupListener() override = default;
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<AppExecFwk::EventRunner> eventRunner_;
56     std::shared_ptr<WorkQueueEventHandler> handler_;
57     const std::string GROUP_LISTENER = "GroupListener";
58 };
59 } // namespace WorkScheduler
60 } // namespace OHOS
61 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_GROUP_LISTENER_H