From 9637617618a5033520fca37da511d62f5359c129 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Mon, 15 Jun 2020 18:11:14 +0800 Subject: [PATCH] improve app conf --- src/conf_io/conf_obj.c | 19 ++++++++++++++----- src/tkc/object_locker.c | 11 +++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/conf_io/conf_obj.c b/src/conf_io/conf_obj.c index 0b6df0924..eab82625f 100644 --- a/src/conf_io/conf_obj.c +++ b/src/conf_io/conf_obj.c @@ -136,20 +136,29 @@ static bool_t conf_obj_can_exec(object_t* obj, const char* name, const char* arg } static ret_t conf_obj_exec(object_t* obj, const char* name, const char* args) { + ret_t ret = RET_NOT_IMPL; conf_obj_t* o = CONF_OBJ(obj); return_value_if_fail(o != NULL, RET_BAD_PARAMS); if (tk_str_ieq(name, CONF_CMD_SAVE)) { - return conf_obj_save(obj); + ret = conf_obj_save(obj); } else if (tk_str_ieq(name, CONF_CMD_RELOAD)) { - return conf_obj_reload(obj); + conf_obj_reload(obj); + ret = RET_ITEMS_CHANGED; } else if (tk_str_ieq(name, CONF_CMD_MOVE_UP)) { - return conf_obj_move_up(obj, args); + conf_obj_move_up(obj, args); + ret = RET_ITEMS_CHANGED; } else if (tk_str_ieq(name, CONF_CMD_MOVE_DOWN)) { - return conf_obj_move_down(obj, args); + conf_obj_move_down(obj, args); + ret = RET_ITEMS_CHANGED; } - return RET_NOT_IMPL; + if (ret == RET_ITEMS_CHANGED) { + emitter_dispatch_simple_event(EMITTER(obj), EVT_PROPS_CHANGED); + emitter_dispatch_simple_event(EMITTER(obj), EVT_ITEMS_CHANGED); + } + + return RET_OK; } static ret_t conf_obj_destroy(object_t* obj) { diff --git a/src/tkc/object_locker.c b/src/tkc/object_locker.c index 635d4c2f6..5bfd75200 100644 --- a/src/tkc/object_locker.c +++ b/src/tkc/object_locker.c @@ -27,6 +27,7 @@ static ret_t object_locker_on_destroy(object_t* obj) { object_locker_t* o = OBJECT_LOCKER(obj); tk_mutex_destroy(o->mutex); + emitter_off_by_ctx(EMITTER(o->obj), o); OBJECT_UNREF(o->obj); return RET_OK; @@ -127,6 +128,14 @@ static const object_vtable_t s_object_locker_vtable = {.type = "object_locker", .remove_prop = object_locker_remove_prop, .foreach_prop = object_locker_foreach_prop}; +static ret_t object_locker_forward_events(void* ctx, event_t* e) { + object_locker_t* o = OBJECT_LOCKER(ctx); + + emitter_dispatch_simple_event(EMITTER(o), e->type); + + return RET_OK; +} + object_t* object_locker_create(object_t* obj) { object_t* o = NULL; object_locker_t* wrapper = NULL; @@ -139,6 +148,8 @@ object_t* object_locker_create(object_t* obj) { wrapper->mutex = tk_mutex_create(); if (wrapper->mutex != NULL) { wrapper->obj = object_ref(obj); + emitter_on(EMITTER(obj), EVT_ITEMS_CHANGED, object_locker_forward_events, o); + emitter_on(EMITTER(obj), EVT_PROPS_CHANGED, object_locker_forward_events, o); } else { OBJECT_UNREF(wrapper->obj); }