Add 'examples/hello/' from commit 'e88e5a6ff3b0f55671cb64c0a506e552360010e9'
git-subtree-dir: examples/hello git-subtree-mainline:f44e3bc6d0git-subtree-split:e88e5a6ff3
This commit is contained in:
commit
4f66da66ad
13 files changed
+1296
No files matched your search
@@ -0,0 +1,51 @@
|
||||
/* logic/state.c — 计数业务态(taps/secs)+ 可选推送监听器(biz→UI)。
|
||||
*
|
||||
* 纯 C(无 meow_ui.h 依赖):状态 + getter/setter + 监听器。UI 经 logic_taps_bump()/
|
||||
* logic_secs_add() 改状态;业务改后触发监听器(若已注册)通知 UI 刷新——契约 ①②(§B.1)。
|
||||
*/
|
||||
#include "logic.h"
|
||||
#include <stddef.h>
|
||||
|
||||
static int g_taps = 0;
|
||||
static int g_secs = 0;
|
||||
static int g_prog = 0; /* demo 进度语义值 0..100(批③ 自 ui/demo/demo.c 上收) */
|
||||
static logic_listener_fn g_listener = NULL;
|
||||
static void *g_listener_ctx = NULL;
|
||||
|
||||
int logic_taps_get(void)
|
||||
{
|
||||
return g_taps;
|
||||
}
|
||||
void logic_taps_bump(void)
|
||||
{
|
||||
g_taps++;
|
||||
if (g_listener) g_listener(LOGIC_EV_TAPS, g_listener_ctx);
|
||||
}
|
||||
|
||||
int logic_secs_get(void)
|
||||
{
|
||||
return g_secs;
|
||||
}
|
||||
void logic_secs_add(int n)
|
||||
{
|
||||
g_secs += n;
|
||||
if (g_listener) g_listener(LOGIC_EV_SECS, g_listener_ctx);
|
||||
}
|
||||
|
||||
int logic_prog_get(void)
|
||||
{
|
||||
return g_prog;
|
||||
}
|
||||
void logic_prog_set(int p)
|
||||
{
|
||||
if (p < 0) p = 0;
|
||||
if (p > 100) p = 100;
|
||||
g_prog = p;
|
||||
if (g_listener) g_listener(LOGIC_EV_PROG, g_listener_ctx);
|
||||
}
|
||||
|
||||
void logic_set_listener(logic_listener_fn cb, void *ctx)
|
||||
{
|
||||
g_listener = cb;
|
||||
g_listener_ctx = ctx;
|
||||
}
|
||||
Reference in new issue
Block a user