remote ui

This commit is contained in:
lixianjing 2023-11-25 22:26:42 +08:00
parent 2ddc7ab6e3
commit 09ab804906
12 changed files with 135 additions and 35 deletions

View File

@ -2,6 +2,9 @@
2023/11/25
* 修复combo_box的resize的处理不正常问题(感谢智明提供补丁)
* 修复STM32上编译的一些问题。
* service/client支持设置重试的次数默认不重试。
* 重构remote ui
2023/11/24
* 完善remote ui service

View File

@ -106,34 +106,34 @@ ret_t remote_ui_get_dev_info(remote_ui_t* ui, remote_ui_dev_info_t* info) {
memset(info, 0x00, sizeof(*info));
ret = tk_client_request(&(ui->client), REMOTE_UI_GET_DEV_INFO, MSG_DATA_TYPE_NONE, wb);
if (ret == RET_OK) {
tk_object_t* obj = conf_ubjson_load_from_buff(wb->data, wb->cursor, FALSE);
if (obj != NULL) {
conf_doc_t* doc = conf_doc_load_ubjson(wb->data, wb->cursor);
if (doc != NULL) {
const char* p = NULL;
p = tk_object_get_prop_str(obj, REMOTE_UI_KEY_DEV_NAME);
p = conf_doc_get_str(doc, REMOTE_UI_KEY_DEV_NAME, NULL);
if (p != NULL) {
tk_strncpy(info->name, p, sizeof(info->name) - 1);
}
p = tk_object_get_prop_str(obj, REMOTE_UI_KEY_DEV_VERSION);
p = conf_doc_get_str(doc, REMOTE_UI_KEY_DEV_VERSION, NULL);
if (p != NULL) {
tk_strncpy(info->version, p, sizeof(info->version) - 1);
}
p = tk_object_get_prop_str(obj, REMOTE_UI_KEY_DEV_OS);
p = conf_doc_get_str(doc, REMOTE_UI_KEY_DEV_OS, NULL);
if (p != NULL) {
tk_strncpy(info->os, p, sizeof(info->os) - 1);
}
p = tk_object_get_prop_str(obj, REMOTE_UI_KEY_DEV_ARCH);
p = conf_doc_get_str(doc, REMOTE_UI_KEY_DEV_ARCH, NULL);
if (p != NULL) {
tk_strncpy(info->arch, p, sizeof(info->arch) - 1);
}
info->screen_width = tk_object_get_prop_int(obj, REMOTE_UI_KEY_DEV_SCREEN_WIDTH, 0);
info->screen_height = tk_object_get_prop_int(obj, REMOTE_UI_KEY_DEV_SCREEN_HEIGHT, 0);
info->dpi = tk_object_get_prop_int(obj, REMOTE_UI_KEY_DEV_DPI, 0);
info->screen_width = conf_doc_get_int(doc, REMOTE_UI_KEY_DEV_SCREEN_WIDTH, 0);
info->screen_height = conf_doc_get_int(doc, REMOTE_UI_KEY_DEV_SCREEN_HEIGHT, 0);
info->dpi = conf_doc_get_int(doc, REMOTE_UI_KEY_DEV_DPI, 0);
TK_OBJECT_UNREF(obj);
conf_doc_destroy(doc);
}
}
@ -487,10 +487,15 @@ ret_t remote_ui_get_prop(remote_ui_t* ui, const char* target, const char* name,
ret =
tk_client_request(&(ui->client), REMOTE_UI_GET_PROP, MSG_DATA_TYPE_UBJSON, &(ui->client.wb));
if (ret == RET_OK) {
tk_object_t* obj = conf_ubjson_load_from_buff(ui->client.wb.data, ui->client.wb.cursor, FALSE);
if (obj != NULL) {
ret = tk_object_get_prop(obj, REMOTE_UI_KEY_VALUE, value);
TK_OBJECT_UNREF(obj);
conf_doc_t* doc = conf_doc_load_ubjson(ui->client.wb.data, ui->client.wb.cursor);
if (doc != NULL) {
value_t v;
value_set_int(&v, 0);
ret = conf_doc_get(doc, REMOTE_UI_KEY_VALUE, &v);
if (ret == RET_OK) {
value_deep_copy(value, &v);
}
conf_doc_destroy(doc);
} else {
ret = RET_OOM;
}

View File

@ -95,8 +95,13 @@ ret_t tk_client_send_req(tk_client_t* client, uint32_t type, uint32_t data_type,
int32_t len = 0;
int32_t retry_times = 0;
tk_msg_header_t header;
return_value_if_fail(client != NULL && client->io != NULL, RET_BAD_PARAMS);
while (retry_times < TK_MAX_RETRY_TIMES) {
if (client->retry_times < 1) {
return tk_client_send_req_impl(client, type, data_type, wb);
}
while (retry_times < client->retry_times) {
ret_t ret = tk_client_send_req_impl(client, type, data_type, wb);
break_if_fail(ret == RET_OK);
@ -166,10 +171,31 @@ static ret_t tk_client_read_resp_impl(tk_client_t* client, tk_msg_header_t* head
static ret_t tk_client_read_resp_ex(tk_client_t* client, bool_t read_notify,
tk_msg_header_t* header, wbuffer_t* wb) {
ret_t ret = RET_OK;
int32_t retry_times = 0;
return_value_if_fail(client != NULL && client->io != NULL, RET_BAD_PARAMS);
while (retry_times < TK_MAX_RETRY_TIMES) {
ret_t ret = tk_client_read_resp_impl(client, header, wb);
if (client->retry_times < 1) {
while (TRUE) {
ret = tk_client_read_resp_impl(client, header, wb);
if (header->type == MSG_CODE_NOTIFY) {
if (client->on_notify != NULL) {
client->on_notify(client, header, wb);
}
if (read_notify) {
return ret;
} else {
continue;
}
} else {
return ret;
}
}
}
while (retry_times < client->retry_times) {
ret = tk_client_read_resp_impl(client, header, wb);
if (ret != RET_IO) {
tk_client_confirm_packet(client, ret != RET_CRC);
}
@ -312,3 +338,11 @@ error:
return ret;
}
ret_t tk_client_set_retry_times(tk_client_t* client, uint32_t retry_times) {
return_value_if_fail(client != NULL, RET_BAD_PARAMS);
client->retry_times = retry_times;
return RET_OK;
}

View File

@ -50,6 +50,7 @@ struct _tk_client_t {
tk_iostream_t* io;
/*private*/
uint32_t retry_times;
tk_client_on_notify_t on_notify;
};
@ -139,6 +140,16 @@ ret_t tk_client_download_file(tk_client_t* client, const char* remote_file, cons
*/
ret_t tk_client_upload_file(tk_client_t* client, const char* remote_file, const char* local_file);
/**
* @method tk_client_set_retry_times
*
* @param {tk_client_t*} client client对象
* @param {uint32_t} retry_times
*
* @return {ret_t} RET_OK表示成功
*/
ret_t tk_client_set_retry_times(tk_client_t* client, uint32_t retry_times);
#define TK_CLIENT(obj) ((obj) != NULL ? &((obj)->client) : NULL)
END_C_DECLS

View File

@ -151,8 +151,6 @@ typedef struct _tk_msg_header_t {
uint8_t resp_code;
} tk_msg_header_t;
#define TK_MAX_RETRY_TIMES 3
END_C_DECLS
#endif /*TK_MSG_HEADER_H*/

View File

@ -245,7 +245,11 @@ ret_t tk_service_send_resp(tk_service_t* service, uint32_t type, uint32_t data_t
tk_msg_header_t header;
return_value_if_fail(service != NULL && wb != NULL, RET_BAD_PARAMS);
while (retry_times < TK_MAX_RETRY_TIMES) {
if (service->retry_times < 1) {
return tk_service_send_resp_impl(service, type, data_type, resp_code, wb);
}
while (retry_times < service->retry_times) {
ret_t ret = tk_service_send_resp_impl(service, type, data_type, resp_code, wb);
break_if_fail(ret == RET_OK);
@ -308,7 +312,11 @@ ret_t tk_service_read_req(tk_service_t* service, tk_msg_header_t* header, wbuffe
int32_t retry_times = 0;
return_value_if_fail(service != NULL && header != NULL && wb != NULL, RET_BAD_PARAMS);
while (retry_times < TK_MAX_RETRY_TIMES) {
if (service->retry_times < 1) {
return tk_service_read_req_impl(service, header, wb);
}
while (retry_times < service->retry_times) {
ret_t ret = tk_service_read_req_impl(service, header, wb);
if (ret != RET_IO) {
tk_service_confirm_packet(service, ret != RET_CRC);
@ -402,3 +410,11 @@ ret_t tk_service_download_file(tk_service_t* service, const char* filename) {
return RET_OK;
}
ret_t tk_service_set_retry_times(tk_service_t* service, uint32_t retry_times) {
return_value_if_fail(service != NULL, RET_BAD_PARAMS);
service->retry_times = retry_times;
return RET_OK;
}

View File

@ -57,6 +57,7 @@ struct _tk_service_t {
tk_iostream_t* io;
/*private*/
uint32_t retry_times;
tk_service_dispatch_t dispatch;
tk_service_destroy_t destroy;
};
@ -148,6 +149,15 @@ ret_t tk_service_upload_file(tk_service_t* service, const char* filename);
*/
ret_t tk_service_download_file(tk_service_t* service, const char* filename);
/**
* @method tk_service_set_retry_times
*
* @param {tk_service_t*} service service对象
* @param {uint32_t} retry_times
* @return {ret_t} RET_OK表示成功
*/
ret_t tk_service_set_retry_times(tk_service_t* service, uint32_t retry_times);
#define TK_SERVICE(obj) ((obj) != NULL ? &((obj)->service) : NULL)
END_C_DECLS

View File

@ -22,6 +22,8 @@
#include "tkc/value.h"
#include "tkc/object.h"
#include "tkc/endian.h"
#include "tkc/utils.h"
#include "tkc/mem.h"
#include "tkc/named_value.h"
#include "ubjson/ubjson_writer.h"
@ -322,6 +324,11 @@ ret_t ubjson_writer_write_kv_value(ubjson_writer_t* writer, const char* key, con
}
} else if (value->type == VALUE_TYPE_STRING) {
return ubjson_writer_write_str(writer, value_str(value));
} else if (value->type == VALUE_TYPE_WSTRING) {
char* str = tk_utf8_dup_wstr(value_wstr(value));
ret_t ret = ubjson_writer_write_str(writer, str);
TKMEM_FREE(str);
return ret;
} else if (value->type == VALUE_TYPE_BINARY) {
binary_data_t* data = value_binary_data(value);
return ubjson_writer_write_str_len(writer, data->data, data->size);

View File

@ -1,6 +1,8 @@
[create]
url=tcp://localhost:2233
[get_dev_info]
[open_window]
name=basic

View File

@ -1,4 +1,7 @@
en_US: type=strings size=9138
default: type=style size=60359
default: type=style size=61468
default_full: type=font size=1732392
system_bar: type=style size=884
edit: type=style size=2504
trado: type=font size=281560
keyboard: type=style size=4563

View File

@ -5,9 +5,16 @@ dialog_title: w=60 h=30 format=1
rgb: w=30 h=30 format=1
rgba: w=30 h=30 format=1
close_d: w=48 h=48 format=1
arrow_up_n: w=48 h=48 format=1
arrow_down_n: w=48 h=48 format=1
arrow_left_n: w=48 h=48 format=1
arrow_right_n: w=48 h=48 format=1
invisible: w=32 h=32 format=1
find: w=48 h=48 format=1
close_n: w=48 h=48 format=1
backspace: w=32 h=32 format=1
ani1: w=140 h=140 format=1
anic: w=140 h=140 format=1
close_n: w=48 h=48 format=1
ani5: w=140 h=140 format=1
ani4: w=140 h=140 format=1
ani2: w=140 h=140 format=1

View File

@ -310,17 +310,21 @@ static void run_script(conf_doc_t* doc, uint32_t times) {
check_return_code(ret, expected_ret, name, target, prop, value);
} else if (tk_str_eq(name, "get_prop")) {
value_t v;
char buff[64] = {0};
const char* ret_value = NULL;
const char* target = conf_node_get_child_value_str(iter, "target", NULL);
const char* prop = conf_node_get_child_value_str(iter, "name", NULL);
const char* value = conf_node_get_child_value_str(iter, "value", NULL);
value_set_str(&v, NULL);
ret = remote_ui_get_prop(ui, target, prop, &v);
ret_value = value_str_ex(&v, buff, sizeof(buff));
if (value != NULL) {
if (!tk_str_eq(value, value_str(&v))) {
if (!tk_str_eq(value, ret_value)) {
ret = RET_FAIL;
}
}
check_return_code(ret, expected_ret, name, target, prop, value_str(&v));
check_return_code(ret, expected_ret, name, target, prop, ret_value);
value_reset(&v);
} else if (tk_str_eq(name, "on_event")) {
const char* target = conf_node_get_child_value_str(iter, "target", NULL);
const char* event_name = conf_node_get_child_value_str(iter, "event", NULL);