mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
improve remote ui
This commit is contained in:
parent
592c5e47f9
commit
5e53a54bfc
@ -2,6 +2,7 @@
|
||||
|
||||
2023/11/26
|
||||
* 增加函数wbuffer\_write\_value/rbuffer\_read\_value
|
||||
* 简化remote ui通讯协议。
|
||||
|
||||
2023/11/25
|
||||
* 修复combo_box的resize的处理不正常问题(感谢智明提供补丁)
|
||||
|
@ -33,19 +33,49 @@
|
||||
#ifdef WITH_FULL_REMOTE_UI
|
||||
#include "base/keys.h"
|
||||
#include "base/events.h"
|
||||
#endif/*WITH_FULL_REMOTE_UI*/
|
||||
#endif /*WITH_FULL_REMOTE_UI*/
|
||||
|
||||
#define REMOTE_UI_ISTREAM_TIMEOUT 100 * 1000
|
||||
|
||||
static ret_t my_rbuffer_destroy(rbuffer_t* rb) {
|
||||
return_value_if_fail(rb != NULL, RET_BAD_PARAMS);
|
||||
TKMEM_FREE(rb->data);
|
||||
TKMEM_FREE(rb);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static rbuffer_t* my_rbuffer_create(wbuffer_t* wb) {
|
||||
rbuffer_t* rb = NULL;
|
||||
return_value_if_fail(wb != NULL, NULL);
|
||||
|
||||
rb = (rbuffer_t*)TKMEM_ZALLOC(rbuffer_t);
|
||||
return_value_if_fail(rb != NULL, NULL);
|
||||
|
||||
rb->capacity = wb->cursor;
|
||||
rb->data = TKMEM_ALLOC(rb->capacity);
|
||||
|
||||
if (rb->data != NULL) {
|
||||
memcpy((void*)(rb->data), wb->data, wb->cursor);
|
||||
} else {
|
||||
my_rbuffer_destroy(rb);
|
||||
rb = NULL;
|
||||
}
|
||||
|
||||
return rb;
|
||||
}
|
||||
|
||||
static ret_t remote_ui_on_notify(remote_ui_t* ui, tk_msg_header_t* header, wbuffer_t* wb) {
|
||||
conf_doc_t* doc = NULL;
|
||||
rbuffer_t* rb = NULL;
|
||||
return_value_if_fail(ui != NULL && header != NULL && wb != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(header->data_type == MSG_DATA_TYPE_UBJSON, RET_BAD_PARAMS);
|
||||
|
||||
doc = conf_doc_load_ubjson(wb->data, wb->cursor);
|
||||
return_value_if_fail(doc != NULL, RET_BAD_PARAMS);
|
||||
rb = my_rbuffer_create(wb);
|
||||
return_value_if_fail(rb != NULL, RET_OOM);
|
||||
|
||||
darray_push(&(ui->pending_events), doc);
|
||||
if (darray_push(&(ui->pending_events), rb) != RET_OK) {
|
||||
my_rbuffer_destroy(rb);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -59,33 +89,24 @@ remote_ui_t* remote_ui_create(tk_iostream_t* io) {
|
||||
|
||||
ui->event_handlers = object_default_create_ex(FALSE);
|
||||
tk_client_init(&(ui->client), io, (tk_client_on_notify_t)remote_ui_on_notify);
|
||||
darray_init(&(ui->pending_events), 100, (tk_destroy_t)tk_object_unref, NULL);
|
||||
darray_init(&(ui->dispatching_events), 100, (tk_destroy_t)conf_doc_destroy, NULL);
|
||||
darray_init(&(ui->pending_events), 100, (tk_destroy_t)my_rbuffer_destroy, NULL);
|
||||
darray_init(&(ui->dispatching_events), 100, (tk_destroy_t)my_rbuffer_destroy, NULL);
|
||||
|
||||
return ui;
|
||||
}
|
||||
|
||||
static ubjson_writer_t* remote_ui_client_get_writer(remote_ui_t* ui) {
|
||||
wbuffer_t* wb = &(ui->client.wb);
|
||||
ubjson_writer_t* writer = &(ui->writer);
|
||||
|
||||
wb->cursor = 0;
|
||||
return ubjson_writer_init(writer, (ubjson_write_callback_t)wbuffer_write_binary, wb);
|
||||
}
|
||||
|
||||
ret_t remote_ui_login(remote_ui_t* ui, const char* username, const char* password) {
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(username != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(password != NULL, RET_BAD_PARAMS);
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_USERNAME, username);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_PASSWORD, password);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, username);
|
||||
wbuffer_write_string(wb, password);
|
||||
|
||||
return tk_client_request(&(ui->client), MSG_CODE_LOGIN, MSG_DATA_TYPE_UBJSON, &(ui->client.wb));
|
||||
return tk_client_request(&(ui->client), MSG_CODE_LOGIN, MSG_DATA_TYPE_BINARY, wb);
|
||||
}
|
||||
|
||||
ret_t remote_ui_logout(remote_ui_t* ui) {
|
||||
@ -106,34 +127,29 @@ 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) {
|
||||
conf_doc_t* doc = conf_doc_load_ubjson(wb->data, wb->cursor);
|
||||
if (doc != NULL) {
|
||||
rbuffer_t rb;
|
||||
if (rbuffer_init(&rb, wb->data, wb->cursor) == RET_OK) {
|
||||
const char* p = NULL;
|
||||
p = conf_doc_get_str(doc, REMOTE_UI_KEY_DEV_NAME, NULL);
|
||||
if (p != NULL) {
|
||||
|
||||
if (rbuffer_read_string(&rb, &p) == RET_OK) {
|
||||
tk_strncpy(info->name, p, sizeof(info->name) - 1);
|
||||
}
|
||||
|
||||
p = conf_doc_get_str(doc, REMOTE_UI_KEY_DEV_VERSION, NULL);
|
||||
if (p != NULL) {
|
||||
if (rbuffer_read_string(&rb, &p) == RET_OK) {
|
||||
tk_strncpy(info->version, p, sizeof(info->version) - 1);
|
||||
}
|
||||
|
||||
p = conf_doc_get_str(doc, REMOTE_UI_KEY_DEV_OS, NULL);
|
||||
if (p != NULL) {
|
||||
if (rbuffer_read_string(&rb, &p) == RET_OK) {
|
||||
tk_strncpy(info->os, p, sizeof(info->os) - 1);
|
||||
}
|
||||
|
||||
p = conf_doc_get_str(doc, REMOTE_UI_KEY_DEV_ARCH, NULL);
|
||||
if (p != NULL) {
|
||||
if (rbuffer_read_string(&rb, &p) == RET_OK) {
|
||||
tk_strncpy(info->arch, p, sizeof(info->arch) - 1);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
conf_doc_destroy(doc);
|
||||
rbuffer_read_uint32(&rb, &info->screen_width);
|
||||
rbuffer_read_uint32(&rb, &info->screen_height);
|
||||
rbuffer_read_uint32(&rb, &info->dpi);
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,11 +157,13 @@ ret_t remote_ui_get_dev_info(remote_ui_t* ui, remote_ui_dev_info_t* info) {
|
||||
}
|
||||
|
||||
ret_t remote_ui_reboot(remote_ui_t* ui, remote_ui_reboot_type_t reboot_type) {
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
|
||||
wbuffer_rewind(&(ui->client.wb));
|
||||
wbuffer_write_int32(&(ui->client.wb), reboot_type);
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_REBOOT, MSG_DATA_TYPE_NONE, &(ui->client.wb));
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_int32(wb, reboot_type);
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_REBOOT, MSG_DATA_TYPE_BINARY, wb);
|
||||
}
|
||||
|
||||
ret_t remote_ui_download_file(remote_ui_t* ui, const char* remote_file, const char* local_file) {
|
||||
@ -162,39 +180,42 @@ ret_t remote_ui_upload_file(remote_ui_t* ui, const char* remote_file, const char
|
||||
|
||||
ret_t remote_ui_create_dir(remote_ui_t* ui, const char* remote_dir) {
|
||||
ret_t ret = RET_OK;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(remote_dir != NULL, RET_BAD_PARAMS);
|
||||
|
||||
wbuffer_rewind(&(ui->client.wb));
|
||||
wbuffer_write_string(&(ui->client.wb), remote_dir);
|
||||
ret = tk_client_request(&(ui->client), REMOTE_UI_CREATE_DIR, MSG_DATA_TYPE_STRING,
|
||||
&(ui->client.wb));
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, remote_dir);
|
||||
ret = tk_client_request(&(ui->client), REMOTE_UI_CREATE_DIR, MSG_DATA_TYPE_STRING, wb);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_t remote_ui_remove_dir(remote_ui_t* ui, const char* remote_dir) {
|
||||
ret_t ret = RET_OK;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(remote_dir != NULL, RET_BAD_PARAMS);
|
||||
|
||||
wbuffer_rewind(&(ui->client.wb));
|
||||
wbuffer_write_string(&(ui->client.wb), remote_dir);
|
||||
ret = tk_client_request(&(ui->client), REMOTE_UI_REMOVE_DIR, MSG_DATA_TYPE_STRING,
|
||||
&(ui->client.wb));
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, remote_dir);
|
||||
ret = tk_client_request(&(ui->client), REMOTE_UI_REMOVE_DIR, MSG_DATA_TYPE_STRING, wb);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_t remote_ui_remove_file(remote_ui_t* ui, const char* remote_file) {
|
||||
ret_t ret = RET_OK;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(remote_file != NULL, RET_BAD_PARAMS);
|
||||
|
||||
wbuffer_rewind(&(ui->client.wb));
|
||||
wbuffer_write_string(&(ui->client.wb), remote_file);
|
||||
ret = tk_client_request(&(ui->client), REMOTE_UI_REMOVE_FILE, MSG_DATA_TYPE_STRING,
|
||||
&(ui->client.wb));
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, remote_file);
|
||||
ret = tk_client_request(&(ui->client), REMOTE_UI_REMOVE_FILE, MSG_DATA_TYPE_STRING, wb);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -228,27 +249,24 @@ static ret_t remote_ui_on_event_local(remote_ui_t* ui, const char* target, uint3
|
||||
(tk_destroy_t)emitter_destroy);
|
||||
}
|
||||
emitter_on(emitter, event, func, ctx);
|
||||
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t remote_ui_on_event(remote_ui_t* ui, const char* target, uint32_t event, event_func_t func,
|
||||
void* ctx) {
|
||||
ret_t ret = RET_FAIL;
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->event_handlers != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(target != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(func != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, target);
|
||||
wbuffer_write_int32(wb, event);
|
||||
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TARGET, target);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_EVENT, event);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
|
||||
ret =
|
||||
tk_client_request(&(ui->client), REMOTE_UI_ON_EVENT, MSG_DATA_TYPE_UBJSON, &(ui->client.wb));
|
||||
ret = tk_client_request(&(ui->client), REMOTE_UI_ON_EVENT, MSG_DATA_TYPE_BINARY, wb);
|
||||
if (ret == RET_OK) {
|
||||
target = (char*)(ui->client.wb.data);
|
||||
remote_ui_on_event_local(ui, target, event, func, ctx);
|
||||
@ -275,21 +293,19 @@ static ret_t remote_ui_off_event_local(remote_ui_t* ui, const char* target, uint
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t remote_ui_off_event(remote_ui_t* ui, const char* target, uint32_t event,
|
||||
event_func_t func, void* ctx) {
|
||||
ret_t remote_ui_off_event(remote_ui_t* ui, const char* target, uint32_t event, event_func_t func,
|
||||
void* ctx) {
|
||||
ret_t ret = RET_FAIL;
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->event_handlers != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(target != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TARGET, target);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_EVENT, event);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, target);
|
||||
wbuffer_write_int32(wb, event);
|
||||
|
||||
ret =
|
||||
tk_client_request(&(ui->client), REMOTE_UI_OFF_EVENT, MSG_DATA_TYPE_UBJSON, &(ui->client.wb));
|
||||
ret = tk_client_request(&(ui->client), REMOTE_UI_OFF_EVENT, MSG_DATA_TYPE_BINARY, wb);
|
||||
if (ret == RET_OK) {
|
||||
target = (char*)(ui->client.wb.data);
|
||||
remote_ui_off_event_local(ui, target, event, func, ctx);
|
||||
@ -298,7 +314,7 @@ ret_t remote_ui_off_event(remote_ui_t* ui, const char* target, uint32_t event,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef WITH_FULL_REMOTE_UI
|
||||
#ifdef WITH_FULL_REMOTE_UI
|
||||
ret_t remote_ui_click(remote_ui_t* ui, const char* target) {
|
||||
pointer_event_t e;
|
||||
pointer_event_init(&e, EVT_CLICK, NULL, 0, 0);
|
||||
@ -318,29 +334,30 @@ ret_t remote_ui_key(remote_ui_t* ui, const char* target, int32_t key_code) {
|
||||
}
|
||||
|
||||
ret_t remote_ui_send_event(remote_ui_t* ui, const char* target, event_t* event) {
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(target != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(event != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TARGET, target);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_EVENT, event->type);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, target);
|
||||
wbuffer_write_int32(wb, event->type);
|
||||
|
||||
switch (event->type) {
|
||||
case EVT_CLICK:
|
||||
case EVT_POINTER_DOWN:
|
||||
case EVT_POINTER_UP:
|
||||
case EVT_POINTER_MOVE: {
|
||||
pointer_event_t* e = (pointer_event_t*)event;
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_X, e->x);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_Y, e->y);
|
||||
wbuffer_write_int32(wb, e->x);
|
||||
wbuffer_write_int32(wb, e->y);
|
||||
break;
|
||||
}
|
||||
case EVT_KEY_DOWN:
|
||||
case EVT_KEY_UP: {
|
||||
key_event_t* e = (key_event_t*)event;
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_CODE, e->key);
|
||||
wbuffer_write_uint32(wb, e->key);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -348,50 +365,50 @@ ret_t remote_ui_send_event(remote_ui_t* ui, const char* target, event_t* event)
|
||||
return RET_NOT_IMPL;
|
||||
}
|
||||
}
|
||||
ubjson_writer_write_object_end(writer);
|
||||
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_SEND_EVENT, MSG_DATA_TYPE_UBJSON,
|
||||
&(ui->client.wb));
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_SEND_EVENT, MSG_DATA_TYPE_BINARY, wb);
|
||||
}
|
||||
|
||||
ret_t remote_ui_open_window(remote_ui_t* ui, const char* name, const char* xml,
|
||||
const char* init_json) {
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(name != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_NAME, name);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, name);
|
||||
|
||||
if (xml != NULL) {
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_XML, xml);
|
||||
wbuffer_write_string(wb, xml);
|
||||
} else {
|
||||
wbuffer_write_string(wb, "");
|
||||
}
|
||||
if (init_json != NULL) {
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_INIT, init_json);
|
||||
wbuffer_write_string(wb, init_json);
|
||||
} else {
|
||||
wbuffer_write_string(wb, "");
|
||||
}
|
||||
ubjson_writer_write_object_end(writer);
|
||||
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_OPEN_WINDOW, MSG_DATA_TYPE_UBJSON,
|
||||
&(ui->client.wb));
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_OPEN_WINDOW, MSG_DATA_TYPE_BINARY, wb);
|
||||
}
|
||||
|
||||
#endif/*WITH_FULL_REMOTE_UI*/
|
||||
#endif /*WITH_FULL_REMOTE_UI*/
|
||||
|
||||
static ret_t remote_ui_show_dialog(remote_ui_t* ui, const char* type, const char* title,
|
||||
const char* content, uint32_t duration) {
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(type != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TYPE, type);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TITLE, title);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_CONTENT, content);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_DURATION, duration);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, type);
|
||||
wbuffer_write_string(wb, title);
|
||||
wbuffer_write_string(wb, content);
|
||||
wbuffer_write_uint32(wb, duration);
|
||||
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_OPEN_DIALOG, MSG_DATA_TYPE_UBJSON,
|
||||
&(ui->client.wb));
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_OPEN_DIALOG, MSG_DATA_TYPE_BINARY, wb);
|
||||
}
|
||||
|
||||
ret_t remote_ui_show_confirm(remote_ui_t* ui, const char* title, const char* content) {
|
||||
@ -453,52 +470,42 @@ ret_t remote_ui_back_to_home(remote_ui_t* ui) {
|
||||
|
||||
ret_t remote_ui_set_prop(remote_ui_t* ui, const char* target, const char* name,
|
||||
const value_t* value) {
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(target != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(name != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(value != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TARGET, target);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_NAME, name);
|
||||
ubjson_writer_write_kv_value(writer, REMOTE_UI_KEY_VALUE, value);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, target);
|
||||
wbuffer_write_string(wb, name);
|
||||
wbuffer_write_value(wb, value);
|
||||
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_SET_PROP, MSG_DATA_TYPE_UBJSON,
|
||||
&(ui->client.wb));
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_SET_PROP, MSG_DATA_TYPE_BINARY, wb);
|
||||
}
|
||||
|
||||
ret_t remote_ui_get_prop(remote_ui_t* ui, const char* target, const char* name, value_t* value) {
|
||||
ret_t ret = RET_OK;
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(target != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(name != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(value != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TARGET, target);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_NAME, name);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, target);
|
||||
wbuffer_write_string(wb, name);
|
||||
|
||||
ret =
|
||||
tk_client_request(&(ui->client), REMOTE_UI_GET_PROP, MSG_DATA_TYPE_UBJSON, &(ui->client.wb));
|
||||
ret = tk_client_request(&(ui->client), REMOTE_UI_GET_PROP, MSG_DATA_TYPE_BINARY, wb);
|
||||
if (ret == RET_OK) {
|
||||
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;
|
||||
}
|
||||
value_t v;
|
||||
rbuffer_t rb;
|
||||
value_set_int(&v, 0);
|
||||
rbuffer_init(&rb, wb->data, wb->cursor);
|
||||
rbuffer_read_value(&rb, &v);
|
||||
value_deep_copy(value, &v);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -539,35 +546,31 @@ ret_t remote_ui_exec_fscript(remote_ui_t* ui, const char* script, str_t* str) {
|
||||
}
|
||||
|
||||
ret_t remote_ui_move_widget(remote_ui_t* ui, const char* target, int32_t x, int32_t y) {
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(target != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TARGET, target);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_X, x);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_Y, y);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, target);
|
||||
wbuffer_write_int32(wb, x);
|
||||
wbuffer_write_int32(wb, y);
|
||||
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_MOVE_WIDGET, MSG_DATA_TYPE_UBJSON,
|
||||
&(ui->client.wb));
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_MOVE_WIDGET, MSG_DATA_TYPE_BINARY, wb);
|
||||
}
|
||||
|
||||
ret_t remote_ui_resize_widget(remote_ui_t* ui, const char* target, uint32_t w, uint32_t h) {
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(target != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TARGET, target);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_W, w);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_H, h);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, target);
|
||||
wbuffer_write_uint32(wb, w);
|
||||
wbuffer_write_uint32(wb, h);
|
||||
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_RESIZE_WIDGET, MSG_DATA_TYPE_UBJSON,
|
||||
&(ui->client.wb));
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_RESIZE_WIDGET, MSG_DATA_TYPE_BINARY, wb);
|
||||
}
|
||||
|
||||
ret_t remote_ui_destroy_widget(remote_ui_t* ui, const char* target) {
|
||||
@ -581,19 +584,17 @@ ret_t remote_ui_destroy_widget(remote_ui_t* ui, const char* target) {
|
||||
}
|
||||
|
||||
ret_t remote_ui_create_widget(remote_ui_t* ui, const char* target, const char* xml) {
|
||||
ubjson_writer_t* writer = NULL;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(ui != NULL && ui->client.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(target != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(xml != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_client_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TARGET, target);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_XML, xml);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
wb = &(ui->client.wb);
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, target);
|
||||
wbuffer_write_string(wb, xml);
|
||||
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_CREATE_WIDGET, MSG_DATA_TYPE_UBJSON,
|
||||
&(ui->client.wb));
|
||||
return tk_client_request(&(ui->client), REMOTE_UI_CREATE_WIDGET, MSG_DATA_TYPE_BINARY, wb);
|
||||
}
|
||||
|
||||
ret_t remote_ui_get_loaded_images_info(remote_ui_t* ui, const char* file) {
|
||||
@ -663,24 +664,26 @@ static ret_t value_from_str(value_t* v, int32_t value_type, const char* str) {
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
#endif/*WITH_FULL_REMOTE_UI*/
|
||||
#endif /*WITH_FULL_REMOTE_UI*/
|
||||
|
||||
ret_t remote_ui_dispatch_one(remote_ui_t* ui, conf_doc_t* doc) {
|
||||
const char* target = NULL;
|
||||
ret_t remote_ui_dispatch_one(remote_ui_t* ui, rbuffer_t* rb) {
|
||||
uint32_t type = 0;
|
||||
return_value_if_fail(ui != NULL && doc != NULL, RET_BAD_PARAMS);
|
||||
const char* target = NULL;
|
||||
return_value_if_fail(ui != NULL && rb != NULL, RET_BAD_PARAMS);
|
||||
|
||||
rbuffer_read_string(rb, &target);
|
||||
rbuffer_read_uint32(rb, &type);
|
||||
|
||||
target = conf_doc_get_str(doc, REMOTE_UI_KEY_TARGET, NULL);
|
||||
type = conf_doc_get_int(doc, REMOTE_UI_KEY_EVENT, 0);
|
||||
if (target != NULL && type != 0) {
|
||||
emitter_t* emitter = tk_object_get_prop_pointer(ui->event_handlers, target);
|
||||
if (emitter != NULL) {
|
||||
switch (type) {
|
||||
#ifdef WITH_FULL_REMOTE_UI
|
||||
#ifdef WITH_FULL_REMOTE_UI
|
||||
case EVT_KEY_DOWN:
|
||||
case EVT_KEY_UP: {
|
||||
key_event_t e;
|
||||
int key = conf_doc_get_int(doc, REMOTE_UI_KEY_CODE, 0);
|
||||
int key = 0;
|
||||
rbuffer_read_int32(rb, &key);
|
||||
log_debug("key_event:: type:%d key:%d\n", type, key);
|
||||
emitter_dispatch(emitter, key_event_init(&e, type, emitter, key));
|
||||
break;
|
||||
@ -690,8 +693,10 @@ ret_t remote_ui_dispatch_one(remote_ui_t* ui, conf_doc_t* doc) {
|
||||
case EVT_POINTER_MOVE:
|
||||
case EVT_CLICK: {
|
||||
pointer_event_t e;
|
||||
int x = conf_doc_get_int(doc, REMOTE_UI_KEY_X, 0);
|
||||
int y = conf_doc_get_int(doc, REMOTE_UI_KEY_Y, 0);
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
rbuffer_read_int32(rb, &x);
|
||||
rbuffer_read_int32(rb, &y);
|
||||
log_debug("pointer_event:: type:%d x:%d y:%d\n", type, x, y);
|
||||
emitter_dispatch(emitter, pointer_event_init(&e, type, emitter, x, y));
|
||||
break;
|
||||
@ -699,21 +704,20 @@ ret_t remote_ui_dispatch_one(remote_ui_t* ui, conf_doc_t* doc) {
|
||||
case EVT_VALUE_CHANGED: {
|
||||
value_change_event_t e;
|
||||
value_change_event_init(&e, type, emitter);
|
||||
conf_doc_get(doc, REMOTE_UI_KEY_VALUE, &(e.new_value));
|
||||
rbuffer_read_value(rb, &(e.new_value));
|
||||
emitter_dispatch(emitter, (event_t*)&e);
|
||||
value_reset(&(e.new_value));
|
||||
break;
|
||||
}
|
||||
#endif/*WITH_FULL_REMOTE_UI*/
|
||||
#endif /*WITH_FULL_REMOTE_UI*/
|
||||
case EVT_PROP_CHANGED: {
|
||||
value_t value;
|
||||
prop_change_event_t e;
|
||||
const char* name = conf_doc_get_str(doc, REMOTE_UI_KEY_NAME, NULL);
|
||||
const char* name = NULL;
|
||||
rbuffer_read_string(rb, &name);
|
||||
value_set_int(&value, 0);
|
||||
conf_doc_get(doc, REMOTE_UI_KEY_VALUE, &value);
|
||||
rbuffer_read_value(rb, &value);
|
||||
prop_change_event_init(&e, type, name, &value);
|
||||
emitter_dispatch(emitter, (event_t*)&e);
|
||||
value_reset(&(value));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -745,7 +749,7 @@ ret_t remote_ui_dispatch(remote_ui_t* ui) {
|
||||
src->size = 0;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
conf_doc_t* iter = (conf_doc_t*)darray_get(dest, i);
|
||||
rbuffer_t* iter = (rbuffer_t*)darray_get(dest, i);
|
||||
remote_ui_dispatch_one(ui, iter);
|
||||
}
|
||||
darray_clear(dest);
|
||||
|
@ -74,14 +74,6 @@ tk_service_t* remote_ui_service_create(tk_iostream_t* io, void* args) {
|
||||
return (tk_service_t*)ui;
|
||||
}
|
||||
|
||||
static ubjson_writer_t* remote_ui_service_get_writer(remote_ui_service_t* ui) {
|
||||
wbuffer_t* wb = &(ui->service.wb);
|
||||
ubjson_writer_t* writer = &(ui->writer);
|
||||
|
||||
wb->cursor = 0;
|
||||
return ubjson_writer_init(writer, (ubjson_write_callback_t)wbuffer_write_binary, wb);
|
||||
}
|
||||
|
||||
static ret_t remote_ui_service_login(remote_ui_service_t* ui, const char* username,
|
||||
const char* password) {
|
||||
return_value_if_fail(ui != NULL && ui->service.io != NULL, RET_BAD_PARAMS);
|
||||
@ -241,7 +233,6 @@ static ret_t remote_ui_service_on_event_func(void* ctx, event_t* e) {
|
||||
ret_t ret = RET_OK;
|
||||
wbuffer_t* wb = NULL;
|
||||
char target[32] = {0};
|
||||
ubjson_writer_t* writer = NULL;
|
||||
remote_ui_service_t* ui = (remote_ui_service_t*)ctx;
|
||||
return_value_if_fail(ui != NULL, RET_REMOVE);
|
||||
return_value_if_fail(ui->service.destroy == (tk_service_destroy_t)remote_ui_service_destroy,
|
||||
@ -253,19 +244,19 @@ static ret_t remote_ui_service_on_event_func(void* ctx, event_t* e) {
|
||||
}
|
||||
|
||||
wb = &(ui->service.wb);
|
||||
writer = remote_ui_service_get_writer(ui);
|
||||
log_debug("remote_ui_service_on_event_func type=%d\n", e->type);
|
||||
|
||||
tk_snprintf(target, sizeof(target) - 1, "%p", e->target);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_TARGET, target);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_EVENT, e->type);
|
||||
|
||||
wbuffer_rewind(wb);
|
||||
wbuffer_write_string(wb, target);
|
||||
wbuffer_write_int32(wb, e->type);
|
||||
|
||||
switch (e->type) {
|
||||
case EVT_VALUE_CHANGED: {
|
||||
value_change_event_t* event = value_change_event_cast(e);
|
||||
value_t* v = &(event->new_value);
|
||||
ubjson_writer_write_kv_value(writer, REMOTE_UI_KEY_VALUE, v);
|
||||
wbuffer_write_value(wb, v);
|
||||
break;
|
||||
}
|
||||
case EVT_PROP_CHANGED: {
|
||||
@ -280,36 +271,34 @@ static ret_t remote_ui_service_on_event_func(void* ctx, event_t* e) {
|
||||
} else {
|
||||
v = (value_t*)(event->value);
|
||||
}
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_NAME, event->name);
|
||||
ubjson_writer_write_kv_value(writer, REMOTE_UI_KEY_VALUE, v);
|
||||
wbuffer_write_string(wb, event->name);
|
||||
wbuffer_write_value(wb, v);
|
||||
break;
|
||||
}
|
||||
case EVT_KEY_DOWN:
|
||||
case EVT_KEY_UP: {
|
||||
key_event_t* event = key_event_cast(e);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_VALUE_TYPE, event->key);
|
||||
wbuffer_write_int32(wb, event->key);
|
||||
break;
|
||||
}
|
||||
case EVT_POINTER_DOWN:
|
||||
case EVT_POINTER_MOVE:
|
||||
case EVT_POINTER_UP: {
|
||||
pointer_event_t* event = pointer_event_cast(e);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_X, event->x);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_Y, event->y);
|
||||
wbuffer_write_int32(wb, event->x);
|
||||
wbuffer_write_int32(wb, event->y);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ubjson_writer_write_object_end(writer);
|
||||
|
||||
ret = tk_service_send_resp(&(ui->service), MSG_CODE_NOTIFY, MSG_DATA_TYPE_UBJSON, RET_OK, wb);
|
||||
ret = tk_service_send_resp(&(ui->service), MSG_CODE_NOTIFY, MSG_DATA_TYPE_BINARY, RET_OK, wb);
|
||||
if (ret != RET_OK) {
|
||||
log_debug("send event %d failed\n", e->type);
|
||||
ret = RET_REMOVE;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -479,7 +468,7 @@ static ret_t remote_ui_service_open_window(remote_ui_service_t* ui, const char*
|
||||
|
||||
return_value_if_fail(win != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (init_json != NULL) {
|
||||
if (TK_STR_IS_NOT_EMPTY(init_json)) {
|
||||
conf_doc_t* doc = conf_doc_load_json(init_json, strlen(init_json));
|
||||
if (doc != NULL) {
|
||||
window_init_with_conf(win, doc);
|
||||
@ -578,7 +567,6 @@ static ret_t remote_ui_service_exec_script(remote_ui_service_t* ui, const char*
|
||||
tk_object_set_prop_pointer(obj, STR_PROP_WINDOW_MANAGER, wm);
|
||||
|
||||
ret = fscript_eval(obj, script, v);
|
||||
TK_OBJECT_UNREF(obj);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -602,30 +590,16 @@ static ret_t remote_ui_service_set_language(remote_ui_service_t* ui, const char*
|
||||
return locale_info_change(locale_info(), lang, country);
|
||||
}
|
||||
|
||||
static ret_t remote_ui_dev_info_write(ubjson_writer_t* writer, remote_ui_dev_info_t* info) {
|
||||
return_value_if_fail(writer != NULL && info != NULL, RET_BAD_PARAMS);
|
||||
static ret_t remote_ui_dev_info_write(wbuffer_t* wb, remote_ui_dev_info_t* info) {
|
||||
return_value_if_fail(wb != NULL && info != NULL, RET_BAD_PARAMS);
|
||||
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_DEV_NAME, info->name);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_DEV_OS, info->os);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_DEV_VERSION, info->version);
|
||||
ubjson_writer_write_kv_str(writer, REMOTE_UI_KEY_DEV_ARCH, info->arch);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_DEV_SCREEN_WIDTH, info->screen_width);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_DEV_SCREEN_HEIGHT, info->screen_height);
|
||||
ubjson_writer_write_kv_int(writer, REMOTE_UI_KEY_DEV_DPI, info->dpi);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t remote_ui_service_pack_value(remote_ui_service_t* ui, value_t* v) {
|
||||
ubjson_writer_t* writer = NULL;
|
||||
return_value_if_fail(ui != NULL && v != NULL, RET_BAD_PARAMS);
|
||||
|
||||
writer = remote_ui_service_get_writer(ui);
|
||||
ubjson_writer_write_object_begin(writer);
|
||||
ubjson_writer_write_kv_value(writer, REMOTE_UI_KEY_VALUE, v);
|
||||
ubjson_writer_write_object_end(writer);
|
||||
wbuffer_write_string(wb, info->name);
|
||||
wbuffer_write_string(wb, info->os);
|
||||
wbuffer_write_string(wb, info->version);
|
||||
wbuffer_write_string(wb, info->arch);
|
||||
wbuffer_write_uint32(wb, info->screen_width);
|
||||
wbuffer_write_uint32(wb, info->screen_height);
|
||||
wbuffer_write_uint32(wb, info->dpi);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -634,23 +608,23 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
wbuffer_t* wb) {
|
||||
value_t v;
|
||||
char buff[1024] = {0};
|
||||
tk_object_t* obj = NULL;
|
||||
ubjson_writer_t* writer = NULL;
|
||||
tk_msg_header_t resp;
|
||||
rbuffer_t rb;
|
||||
char local_file[MAX_PATH + 1] = {0};
|
||||
return_value_if_fail(ui != NULL && ui->service.io != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(req != NULL && wb != NULL, RET_BAD_PARAMS);
|
||||
|
||||
memset(&resp, 0x00, sizeof(resp));
|
||||
if (req->data_type == MSG_DATA_TYPE_UBJSON) {
|
||||
obj = conf_ubjson_load_from_buff(wb->data, wb->cursor, FALSE);
|
||||
}
|
||||
rbuffer_init(&rb, wb->data, wb->cursor);
|
||||
|
||||
resp.type = req->type;
|
||||
switch (req->type) {
|
||||
case MSG_CODE_LOGIN: {
|
||||
const char* username = tk_object_get_prop_str(obj, "username");
|
||||
const char* password = tk_object_get_prop_str(obj, "password");
|
||||
const char* username = NULL;
|
||||
const char* password = NULL;
|
||||
|
||||
rbuffer_read_string(&rb, &username);
|
||||
rbuffer_read_string(&rb, &password);
|
||||
resp.resp_code = remote_ui_service_login(ui, username, password);
|
||||
resp.data_type = MSG_DATA_TYPE_NONE;
|
||||
wbuffer_rewind(wb);
|
||||
@ -666,9 +640,9 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
remote_ui_dev_info_t info;
|
||||
memset(&info, 0x00, sizeof(info));
|
||||
resp.resp_code = remote_ui_service_get_dev_info(ui, &info);
|
||||
resp.data_type = MSG_DATA_TYPE_UBJSON;
|
||||
writer = remote_ui_service_get_writer(ui);
|
||||
remote_ui_dev_info_write(writer, &info);
|
||||
resp.data_type = MSG_DATA_TYPE_BINARY;
|
||||
wbuffer_rewind(wb);
|
||||
remote_ui_dev_info_write(wb, &info);
|
||||
break;
|
||||
}
|
||||
case REMOTE_UI_REBOOT: {
|
||||
@ -744,19 +718,29 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
break;
|
||||
}
|
||||
case REMOTE_UI_OPEN_WINDOW: {
|
||||
const char* name = tk_object_get_prop_str(obj, REMOTE_UI_KEY_NAME);
|
||||
const char* xml = tk_object_get_prop_str(obj, REMOTE_UI_KEY_XML);
|
||||
const char* init_json = tk_object_get_prop_str(obj, REMOTE_UI_KEY_INIT);
|
||||
const char* name = NULL;
|
||||
const char* xml = NULL;
|
||||
const char* init_json = NULL;
|
||||
|
||||
rbuffer_read_string(&rb, &name);
|
||||
rbuffer_read_string(&rb, &xml);
|
||||
rbuffer_read_string(&rb, &init_json);
|
||||
|
||||
resp.resp_code = remote_ui_service_open_window(ui, name, xml, init_json);
|
||||
resp.data_type = MSG_DATA_TYPE_NONE;
|
||||
wbuffer_rewind(wb);
|
||||
break;
|
||||
}
|
||||
case REMOTE_UI_OPEN_DIALOG: {
|
||||
const char* type = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TYPE);
|
||||
const char* title = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TITLE);
|
||||
const char* content = tk_object_get_prop_str(obj, REMOTE_UI_KEY_CONTENT);
|
||||
uint32_t duration = tk_object_get_prop_uint32(obj, REMOTE_UI_KEY_DURATION, 3000);
|
||||
const char* type = NULL;
|
||||
const char* title = NULL;
|
||||
const char* content = NULL;
|
||||
uint32_t duration = 0;
|
||||
|
||||
rbuffer_read_string(&rb, &type);
|
||||
rbuffer_read_string(&rb, &title);
|
||||
rbuffer_read_string(&rb, &content);
|
||||
rbuffer_read_uint32(&rb, &duration);
|
||||
|
||||
resp.resp_code = remote_ui_service_open_dialog(ui, type, title, content, duration);
|
||||
resp.data_type = MSG_DATA_TYPE_NONE;
|
||||
@ -784,10 +768,13 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
}
|
||||
case REMOTE_UI_SET_PROP: {
|
||||
value_t v;
|
||||
const char* target = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TARGET);
|
||||
const char* name = tk_object_get_prop_str(obj, REMOTE_UI_KEY_NAME);
|
||||
const char* target = NULL;
|
||||
const char* name = NULL;
|
||||
|
||||
if (tk_object_get_prop(obj, REMOTE_UI_KEY_VALUE, &v) == RET_OK) {
|
||||
value_set_int(&v, 0);
|
||||
rbuffer_read_string(&rb, &target);
|
||||
rbuffer_read_string(&rb, &name);
|
||||
if (rbuffer_read_value(&rb, &v) == RET_OK) {
|
||||
resp.resp_code = remote_ui_service_set_prop(ui, target, name, &v);
|
||||
} else {
|
||||
resp.resp_code = RET_FAIL;
|
||||
@ -797,14 +784,17 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
break;
|
||||
}
|
||||
case REMOTE_UI_GET_PROP: {
|
||||
const char* target = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TARGET);
|
||||
const char* name = tk_object_get_prop_str(obj, REMOTE_UI_KEY_NAME);
|
||||
const char* target = NULL;
|
||||
const char* name = NULL;
|
||||
|
||||
rbuffer_read_string(&rb, &target);
|
||||
rbuffer_read_string(&rb, &name);
|
||||
|
||||
value_set_int(&v, 0);
|
||||
resp.resp_code = remote_ui_service_get_prop(ui, target, name, &v);
|
||||
resp.data_type = MSG_DATA_TYPE_UBJSON;
|
||||
resp.data_type = MSG_DATA_TYPE_BINARY;
|
||||
wbuffer_rewind(wb);
|
||||
remote_ui_service_pack_value(ui, &v);
|
||||
wbuffer_write_value(wb, &v);
|
||||
break;
|
||||
}
|
||||
case REMOTE_UI_EXEC_FSCRIPT: {
|
||||
@ -819,35 +809,48 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
break;
|
||||
}
|
||||
case REMOTE_UI_ON_EVENT: {
|
||||
const char* target = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TARGET);
|
||||
uint32_t event_type = tk_object_get_prop_int(obj, REMOTE_UI_KEY_EVENT, 0);
|
||||
const char* target = NULL;
|
||||
uint32_t event_type = 0;
|
||||
|
||||
rbuffer_read_string(&rb, &target);
|
||||
rbuffer_read_uint32(&rb, &event_type);
|
||||
|
||||
return remote_ui_service_on_event(ui, target, event_type);
|
||||
}
|
||||
case REMOTE_UI_OFF_EVENT: {
|
||||
const char* target = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TARGET);
|
||||
uint32_t event_type = tk_object_get_prop_int(obj, REMOTE_UI_KEY_EVENT, 0);
|
||||
const char* target = NULL;
|
||||
uint32_t event_type = 0;
|
||||
|
||||
rbuffer_read_string(&rb, &target);
|
||||
rbuffer_read_uint32(&rb, &event_type);
|
||||
return remote_ui_service_off_event(ui, target, event_type);
|
||||
}
|
||||
case REMOTE_UI_SEND_EVENT: {
|
||||
event_t* e = NULL;
|
||||
const char* target = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TARGET);
|
||||
uint32_t event_type = tk_object_get_prop_int(obj, REMOTE_UI_KEY_EVENT, 0);
|
||||
const char* target = NULL;
|
||||
uint32_t event_type = 0;
|
||||
|
||||
rbuffer_read_string(&rb, &target);
|
||||
rbuffer_read_uint32(&rb, &event_type);
|
||||
switch (event_type) {
|
||||
case EVT_CLICK:
|
||||
case EVT_POINTER_DOWN:
|
||||
case EVT_POINTER_UP:
|
||||
case EVT_POINTER_MOVE: {
|
||||
pointer_event_t evt;
|
||||
int x = tk_object_get_prop_int(obj, REMOTE_UI_KEY_X, 0);
|
||||
int y = tk_object_get_prop_int(obj, REMOTE_UI_KEY_Y, 0);
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
rbuffer_read_int32(&rb, &x);
|
||||
rbuffer_read_int32(&rb, &y);
|
||||
e = pointer_event_init(&evt, event_type, NULL, x, y);
|
||||
break;
|
||||
}
|
||||
case EVT_KEY_DOWN:
|
||||
case EVT_KEY_UP: {
|
||||
key_event_t evt;
|
||||
uint32_t key = tk_object_get_prop_int(obj, REMOTE_UI_KEY_CODE, 0);
|
||||
uint32_t key = 0;
|
||||
rbuffer_read_uint32(&rb, &key);
|
||||
e = key_event_init(&evt, event_type, NULL, key);
|
||||
break;
|
||||
}
|
||||
@ -864,10 +867,16 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
break;
|
||||
}
|
||||
case REMOTE_UI_MOVE_WIDGET: {
|
||||
const char* target = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TARGET);
|
||||
int x = tk_object_get_prop_int(obj, REMOTE_UI_KEY_X, 0);
|
||||
int y = tk_object_get_prop_int(obj, REMOTE_UI_KEY_Y, 0);
|
||||
widget_t* widget = remote_ui_service_get_target_widget(ui, target);
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
widget_t* widget = NULL;
|
||||
const char* target = NULL;
|
||||
|
||||
rbuffer_read_string(&rb, &target);
|
||||
rbuffer_read_int32(&rb, &x);
|
||||
rbuffer_read_int32(&rb, &y);
|
||||
|
||||
widget = remote_ui_service_get_target_widget(ui, target);
|
||||
if (widget != NULL) {
|
||||
resp.resp_code = widget_move(widget, x, y);
|
||||
} else {
|
||||
@ -879,10 +888,16 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
break;
|
||||
}
|
||||
case REMOTE_UI_RESIZE_WIDGET: {
|
||||
const char* target = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TARGET);
|
||||
int w = tk_object_get_prop_int(obj, REMOTE_UI_KEY_W, 0);
|
||||
int h = tk_object_get_prop_int(obj, REMOTE_UI_KEY_H, 0);
|
||||
widget_t* widget = remote_ui_service_get_target_widget(ui, target);
|
||||
uint32_t w = 0;
|
||||
uint32_t h = 0;
|
||||
widget_t* widget = NULL;
|
||||
const char* target = NULL;
|
||||
|
||||
rbuffer_read_string(&rb, &target);
|
||||
rbuffer_read_uint32(&rb, &w);
|
||||
rbuffer_read_uint32(&rb, &h);
|
||||
|
||||
widget = remote_ui_service_get_target_widget(ui, target);
|
||||
if (widget != NULL) {
|
||||
resp.resp_code = widget_resize(widget, w, h);
|
||||
} else {
|
||||
@ -905,9 +920,14 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
break;
|
||||
}
|
||||
case REMOTE_UI_CREATE_WIDGET: {
|
||||
const char* target = tk_object_get_prop_str(obj, REMOTE_UI_KEY_TARGET);
|
||||
const char* xml = tk_object_get_prop_str(obj, REMOTE_UI_KEY_XML);
|
||||
widget_t* widget = remote_ui_service_get_target_widget(ui, target);
|
||||
widget_t* widget = NULL;
|
||||
const char* target = NULL;
|
||||
const char* xml = NULL;
|
||||
|
||||
rbuffer_read_string(&rb, &target);
|
||||
rbuffer_read_string(&rb, &xml);
|
||||
|
||||
widget = remote_ui_service_get_target_widget(ui, target);
|
||||
if (widget != NULL) {
|
||||
widget_t* new_widget = ui_loader_load_widget_from_xml(widget, xml, strlen(xml));
|
||||
if (new_widget != NULL) {
|
||||
@ -927,7 +947,6 @@ static ret_t remote_ui_service_dispatch_impl(remote_ui_service_t* ui, tk_msg_hea
|
||||
break;
|
||||
}
|
||||
}
|
||||
TK_OBJECT_UNREF(obj);
|
||||
|
||||
return tk_service_send_resp(&(ui->service), resp.type, resp.data_type, resp.resp_code, wb);
|
||||
}
|
||||
|
@ -2,6 +2,3 @@ en_US: type=strings size=9138
|
||||
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
|
||||
|
@ -5,16 +5,9 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user