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