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_TIMER_LISTENER_H 16 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_TIMER_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 TimerListener : public IConditionListener { 29 public: 30 explicit TimerListener(std::shared_ptr<WorkQueueManager> workQueueManager); 31 ~TimerListener() override = default; 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<AppExecFwk::EventRunner> eventRunner_; 55 std::shared_ptr<WorkQueueEventHandler> handler_; 56 const std::string TIMER_LISTENER = "TimerListener"; 57 }; 58 } // namespace WorkScheduler 59 } // namespace OHOS 60 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_CONDITIONS_TIMER_LISTENER_H