mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-01 03:28:53 +08:00
improve app conf
This commit is contained in:
parent
0faaef8448
commit
9637617618
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user