From 20fb48f1b6a7fc713138549eefa1b5b939f52737 Mon Sep 17 00:00:00 2001 From: caochufeng Date: Fri, 26 Jul 2024 11:40:33 +0800 Subject: [PATCH] =?UTF-8?q?TimedTask=E5=AE=9A=E6=97=B6=E5=99=A8=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=87=8D=E8=BD=BD=E5=87=BD=E6=95=B0,=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E5=AE=9A=E6=97=B6=E5=99=A8type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: caochufeng --- services/common/include/timed_task.h | 2 ++ services/common/src/timed_task.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/services/common/include/timed_task.h b/services/common/include/timed_task.h index bc6b289..0f80f2d 100644 --- a/services/common/include/timed_task.h +++ b/services/common/include/timed_task.h @@ -36,6 +36,7 @@ class TimedTask : public MiscServices::ITimerInfo { public: TimedTask(); TimedTask(bool repeat, uint64_t interval, bool isExact, bool isIdle = false); + TimedTask(bool repeat, uint64_t interval, int type); virtual ~TimedTask(); void OnTrigger() override; void SetType(const int &type) override; @@ -46,6 +47,7 @@ public: static uint64_t CreateTimer(bool repeat, uint64_t interval, bool isExact, bool isIdle, const std::function& callBack); + static uint64_t CreateTimer(bool repeat, uint64_t interval, int type, const std::function& callBack); static bool StartDayNightSwitchTimer(uint64_t& timeId); static bool RegisterDayNightSwitchTimer(uint64_t& timeId, bool repeat, uint64_t interval, const std::function& callBack); diff --git a/services/common/src/timed_task.cpp b/services/common/src/timed_task.cpp index 3854d7f..2d07a71 100644 --- a/services/common/src/timed_task.cpp +++ b/services/common/src/timed_task.cpp @@ -45,6 +45,13 @@ TimedTask::TimedTask(bool repeat, uint64_t interval, bool isExact, bool isIdle) } } +TimedTask::TimedTask(bool repeat, uint64_t interval, int type) +{ + this->repeat = repeat; + this->interval = interval; + this->type = type; +} + TimedTask::~TimedTask() {} @@ -91,6 +98,14 @@ uint64_t WEAK_FUNC TimedTask::CreateTimer(bool repeat, uint64_t interval, bool i return MiscServices::TimeServiceClient::GetInstance()->CreateTimer(timedTask); } +uint64_t WEAK_FUNC TimedTask::CreateTimer(bool repeat, uint64_t interval, int type, + const std::function& callBack) +{ + auto timedTask = std::make_shared(repeat, interval, type); + timedTask->SetCallbackInfo(callBack); + return MiscServices::TimeServiceClient::GetInstance()->CreateTimer(timedTask); +} + bool WEAK_FUNC TimedTask::StartDayNightSwitchTimer(uint64_t& timeId) { int64_t timeDiff {0}; -- Gitee