From f032f6ffdaf6aebf9be3817b22d566fee6ea0304 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 20 Feb 2018 18:23:24 +0800 Subject: [PATCH] feat(timer): add LCUITimer_SetTimeout() and LCUITimer_SetInterval() --- include/LCUI/timer.h | 10 ++++++++++ src/timer.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/LCUI/timer.h b/include/LCUI/timer.h index 7a004c95..af52a970 100644 --- a/include/LCUI/timer.h +++ b/include/LCUI/timer.h @@ -49,6 +49,16 @@ LCUI_BEGIN_HEADER LCUI_API int LCUITimer_Set( long int n_ms, void (*callback_func)(void*), void *arg, LCUI_BOOL reuse ); +/** repeatedly calls a function, with a fixed time delay between each call. */ +LCUI_API int LCUITimer_SetTimeout( long int n_ms, + void( *callback )(void*), + void *arg ); + +/** set a timer which execute a function once after the timer expires. */ +LCUI_API int LCUITimer_SetInterval( long int n_ms, + void( *callback )(void*), + void *arg ); + /** * 释放定时器 * 当不需要定时器时,可以使用该函数释放定时器占用的资源,并移除程序任务队列 diff --git a/src/timer.c b/src/timer.c index 68160d4a..e9abe90c 100644 --- a/src/timer.c +++ b/src/timer.c @@ -200,6 +200,20 @@ int LCUITimer_Set( long int n_ms, void (*func)(void*), return timer->id; } +int LCUITimer_SetTimeout( long int n_ms, + void( *callback )(void*), + void *arg ) +{ + return LCUITimer_Set( n_ms, callback, arg, FALSE ); +} + +int LCUITimer_SetInterval( long int n_ms, + void( *callback )(void*), + void *arg ) +{ + return LCUITimer_Set( n_ms, callback, arg, TRUE ); +} + int LCUITimer_Free( int timer_id ) { Timer timer;