1 /* 2 * Copyright (C) 2021 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_STANDBY_SERVICE_PLUGINS_EXT_INCLUDE_TIME_INFO_H 16 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_PLUGINS_EXT_INCLUDE_TIME_INFO_H 17 18 #ifdef STANDBY_SERVICE_UNIT_TEST 19 #define WEAK_FUNC __attribute__((weak)) 20 #else 21 #define WEAK_FUNC 22 #endif 23 24 #include <cstdint> 25 #include <functional> 26 #include <string> 27 #include <sys/time.h> 28 #include <vector> 29 30 #include "time_service_client.h" 31 #include "itimer_info.h" 32 33 namespace OHOS { 34 namespace DevStandbyMgr { 35 class TimedTask : public MiscServices::ITimerInfo { 36 public: 37 TimedTask(); 38 TimedTask(bool repeat, uint64_t interval, bool isExact, bool isIdle = false); 39 TimedTask(bool repeat, uint64_t interval, int type); 40 virtual ~TimedTask(); 41 void OnTrigger() override; 42 void SetType(const int &type) override; 43 void SetRepeat(bool repeat) override; 44 void SetInterval(const uint64_t& interval) override; 45 void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override; 46 void SetCallbackInfo(const std::function<void()>& callBack); 47 48 static uint64_t CreateTimer(bool repeat, uint64_t interval, bool isExact, bool isIdle, 49 const std::function<void()>& callBack); 50 static uint64_t CreateTimer(bool repeat, uint64_t interval, int type, const std::function<void()>& callBack); 51 static bool StartDayNightSwitchTimer(uint64_t& timeId); 52 static bool RegisterDayNightSwitchTimer(uint64_t& timeId, bool repeat, uint64_t interval, 53 const std::function<void()>& callBack); 54 public: 55 std::function<void()> callBack_ = nullptr; 56 }; 57 } // namespace DevStandbyMgr 58 } // namespace OHOS 59 #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_PLUGINS_EXT_INCLUDE_TIME_INFO_H