From 709ef092284ed4b267044c7d273b127fdf1fc2a2 Mon Sep 17 00:00:00 2001 From: gaozhichao Date: Mon, 4 Aug 2025 17:27:45 +0800 Subject: [PATCH] =?UTF-8?q?[add]=20arkts1.2=E5=AE=9A=E6=97=B6=E5=99=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9B=9E=E8=B0=83=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaozhichao --- .../idl/ohos.time_service.systemtimer.taihe | 8 +++++++- .../system_timer/include/ani_system_timer.h | 4 ++++ .../system_timer/src/ani_system_timer.cpp | 20 ++++++++++++++----- .../ohos.time_service.systemtimer.impl.cpp | 12 ++++++++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/framework/js/taihe/system_timer/idl/ohos.time_service.systemtimer.taihe b/framework/js/taihe/system_timer/idl/ohos.time_service.systemtimer.taihe index 6c185d0e..6efc6b63 100644 --- a/framework/js/taihe/system_timer/idl/ohos.time_service.systemtimer.taihe +++ b/framework/js/taihe/system_timer/idl/ohos.time_service.systemtimer.taihe @@ -17,7 +17,13 @@ @!sts_inject(""" static { loadLibrary("systemtimer_taihe_native.z") } """) -struct TimerOptions {type: i64; repeat: bool; interval: i64; name: String;} +struct TimerOptions { + type: i32; + repeat: bool; + interval: Optional; + name: Optional; + callback: Optional<() => void>; +} @const enum TimerType: i32 { diff --git a/framework/js/taihe/system_timer/include/ani_system_timer.h b/framework/js/taihe/system_timer/include/ani_system_timer.h index 9911d397..2a2048d3 100644 --- a/framework/js/taihe/system_timer/include/ani_system_timer.h +++ b/framework/js/taihe/system_timer/include/ani_system_timer.h @@ -36,6 +36,10 @@ public: virtual void SetRepeat(bool repeat) override; virtual void SetInterval(const uint64_t &interval) override; virtual void SetWantAgent(std::shared_ptr wantAgent) override; + void SetCallbackInfo(const std::function &callBack); + + private: + std::function callBack = nullptr; }; } } diff --git a/framework/js/taihe/system_timer/src/ani_system_timer.cpp b/framework/js/taihe/system_timer/src/ani_system_timer.cpp index 46feac90..047f927e 100644 --- a/framework/js/taihe/system_timer/src/ani_system_timer.cpp +++ b/framework/js/taihe/system_timer/src/ani_system_timer.cpp @@ -28,11 +28,6 @@ ITimerInfoInstance::~ITimerInfoInstance() { } -void ITimerInfoInstance::OnTrigger() -{ - return; -} - void ITimerInfoInstance::SetType(const int &_type) { type = _type; @@ -42,14 +37,29 @@ void ITimerInfoInstance::SetRepeat(bool _repeat) { repeat = _repeat; } + void ITimerInfoInstance::SetInterval(const uint64_t &_interval) { interval = _interval; } + void ITimerInfoInstance::SetWantAgent(std::shared_ptr _wantAgent) { wantAgent = _wantAgent; } + +void ITimerInfoInstance::SetCallbackInfo(const std::function &_callBack) +{ + callBack = _callBack; +} + +void ITimerInfoInstance::OnTrigger() +{ + if (callBack) { + callBack(); + } +} + } // namespace Time } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/framework/js/taihe/system_timer/src/ohos.time_service.systemtimer.impl.cpp b/framework/js/taihe/system_timer/src/ohos.time_service.systemtimer.impl.cpp index 0c14824a..fc193721 100644 --- a/framework/js/taihe/system_timer/src/ohos.time_service.systemtimer.impl.cpp +++ b/framework/js/taihe/system_timer/src/ohos.time_service.systemtimer.impl.cpp @@ -28,13 +28,19 @@ using namespace OHOS::MiscServices::Time; namespace { // To be implemented. -int64_t CreateTimerSync(TimerOptions const& options) +int64_t CreateTimerSync(::ohos::time_service::systemtimer::TimerOptions const& options) { std::shared_ptr iTimerInfoInstance = std::make_shared(); iTimerInfoInstance->SetType(options.type); iTimerInfoInstance->SetRepeat(options.repeat); - iTimerInfoInstance->SetInterval(options.interval); - iTimerInfoInstance->SetName(std::string(options.name)); + int64_t intervalValue = options.interval.value_or(0); + iTimerInfoInstance->SetInterval(intervalValue); + std::string nameValue = std::string(options.name.value_or("")); + iTimerInfoInstance->SetName(nameValue); + auto callback = options.callback; + if (callback.has_value()) { + iTimerInfoInstance->SetCallbackInfo(std::function(callback.value())); + } uint64_t timerId = 0; auto innerCode = TimeServiceClient::GetInstance()->CreateTimerV9(iTimerInfoInstance, timerId); if (innerCode != JsErrorCode::ERROR_OK) { -- Gitee