Skip to content

Commit

Permalink
improve remote ui service
Browse files Browse the repository at this point in the history
  • Loading branch information
xianjimli committed Dec 3, 2023
1 parent 98bcda3 commit f6d8fe5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 最新动态

2023/12/03
* 修复编译警告。
* 完善remote ui service

2023/12/01
* conf_json 支持块注释/**/和行注释//
* 修复 iostream_serial.c 交叉编译问题(感谢明浩提供补丁)
Expand Down
23 changes: 18 additions & 5 deletions src/remote_ui/service/remote_ui_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ static ret_t remote_ui_on_log(void* ctx, log_level_t level, const char* msg) {

tk_service_send_resp(&(ui->service), MSG_CODE_NOTIFY, MSG_DATA_TYPE_BINARY, RET_OK, wb);
} else {
log_set_hook(NULL, NULL);
remote_ui_service_hook_log(ui, FALSE);
}

return RET_OK;
Expand Down Expand Up @@ -653,7 +653,7 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
resp.resp_code = remote_ui_service_logout(ui);
resp.data_type = MSG_DATA_TYPE_NONE;
wbuffer_rewind(wb);
log_set_hook(NULL, NULL);
remote_ui_service_hook_log(ui, FALSE);
break;
}
case REMOTE_UI_GET_DEV_INFO: {
Expand Down Expand Up @@ -965,13 +965,13 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
break;
}
case REMOTE_UI_HOOK_LOG: {
log_set_hook(remote_ui_on_log, ui);
remote_ui_service_hook_log(ui, TRUE);
resp.resp_code = RET_OK;
resp.data_type = MSG_DATA_TYPE_NONE;
break;
}
case REMOTE_UI_UNHOOK_LOG: {
log_set_hook(NULL, NULL);
remote_ui_service_hook_log(ui, FALSE);
resp.resp_code = RET_OK;
resp.data_type = MSG_DATA_TYPE_NONE;
break;
Expand Down Expand Up @@ -1004,7 +1004,7 @@ static ret_t remote_ui_service_dispatch(remote_ui_service_t* ui) {
static ret_t remote_ui_service_destroy(remote_ui_service_t* ui) {
return_value_if_fail(ui != NULL, RET_BAD_PARAMS);

log_set_hook(NULL, NULL);
remote_ui_service_hook_log(ui, FALSE);
memset(ui, 0x00, sizeof(*ui));
TKMEM_FREE(ui);

Expand Down Expand Up @@ -1037,3 +1037,16 @@ tk_service_t* remote_ui_service_start_with_uart(tk_iostream_t* io, void* args) {

return service;
}

ret_t remote_ui_service_hook_log(remote_ui_service_t* ui, bool_t hook) {
return_value_if_fail(ui != NULL, RET_BAD_PARAMS);

if (hook) {
log_set_hook(remote_ui_on_log, ui);
} else {
log_set_hook(NULL, NULL);
}

return RET_OK;
}

9 changes: 9 additions & 0 deletions src/remote_ui/service/remote_ui_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ tk_service_t* remote_ui_service_create(tk_iostream_t* io, void* args);
*/
tk_service_t* remote_ui_service_start_with_uart(tk_iostream_t* io, void* args);

/**
* @method remote_ui_service_hook_log
* 是否hook log。
* @param {remote_ui_service_t*} ui remote ui服务端。
* @param {bool_t} hook 是否hook log。
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
*/
ret_t remote_ui_service_hook_log(remote_ui_service_t* ui, bool_t hook);

END_C_DECLS

#endif /*TK_REMOTE_UI_SERVICE_H*/

0 comments on commit f6d8fe5

Please sign in to comment.