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