mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-08 20:56:13 +00:00
Refine wgl native functions call (#225)
This commit is contained in:
parent
30bab1bcc3
commit
374e687938
|
@ -11,115 +11,139 @@
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* Button widget native function wrappers
|
* Button widget native function wrappers
|
||||||
* -------------------------------------------------------------------------*/
|
* -------------------------------------------------------------------------*/
|
||||||
static int32
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_create_wrapper)
|
||||||
lv_btn_create_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t *par, lv_obj_t *copy)
|
|
||||||
{
|
{
|
||||||
return wgl_native_wigdet_create(WIDGET_TYPE_BTN, par, copy, module_inst);
|
int32 res;
|
||||||
|
wgl_native_return_type(int32);
|
||||||
|
wgl_native_get_arg(uint32, par_obj_id);
|
||||||
|
wgl_native_get_arg(uint32, copy_obj_id);
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
|
res = wgl_native_wigdet_create(WIDGET_TYPE_BTN, par_obj_id, copy_obj_id, module_inst);
|
||||||
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_toggle_wrapper)
|
||||||
lv_btn_set_toggle_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn, bool tgl)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
wgl_native_get_arg(bool, tgl);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
lv_btn_set_toggle(btn, tgl);
|
lv_btn_set_toggle(btn, tgl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_state_wrapper)
|
||||||
lv_btn_set_state_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn, lv_btn_state_t state)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
wgl_native_get_arg(lv_btn_state_t, state);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
lv_btn_set_state(btn, state);
|
lv_btn_set_state(btn, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_ink_in_time_wrapper)
|
||||||
lv_btn_set_ink_in_time_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn, uint16_t time)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
wgl_native_get_arg(uint16_t, time);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
lv_btn_set_ink_in_time(btn, time);
|
lv_btn_set_ink_in_time(btn, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_ink_out_time_wrapper)
|
||||||
lv_btn_set_ink_out_time_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn, uint16_t time)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
wgl_native_get_arg(uint16_t, time);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
lv_btn_set_ink_out_time(btn, time);
|
lv_btn_set_ink_out_time(btn, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_ink_wait_time_wrapper)
|
||||||
lv_btn_set_ink_wait_time_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn, uint16_t time)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
wgl_native_get_arg(uint16_t, time);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
lv_btn_set_ink_wait_time(btn, time);
|
lv_btn_set_ink_wait_time(btn, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_ink_in_time_wrapper)
|
||||||
lv_btn_get_ink_in_time_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
uint16_t res;
|
||||||
return lv_btn_get_ink_in_time(btn);
|
wgl_native_return_type(uint16_t);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
|
res = lv_btn_get_ink_in_time(btn);
|
||||||
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_ink_out_time_wrapper)
|
||||||
lv_btn_get_ink_out_time_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
uint16_t res;
|
||||||
return lv_btn_get_ink_out_time(btn);
|
wgl_native_return_type(uint16_t);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
|
res = lv_btn_get_ink_out_time(btn);
|
||||||
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_ink_wait_time_wrapper)
|
||||||
lv_btn_get_ink_wait_time_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
uint16_t res;
|
||||||
return lv_btn_get_ink_wait_time(btn);
|
wgl_native_return_type(uint16_t);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
|
res = lv_btn_get_ink_wait_time(btn);
|
||||||
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static lv_btn_state_t
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_state_wrapper)
|
||||||
lv_btn_get_state_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
lv_btn_state_t res;
|
||||||
return lv_btn_get_state(btn);
|
wgl_native_return_type(lv_btn_state_t);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
|
res = lv_btn_get_state(btn);
|
||||||
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_toggle_wrapper)
|
||||||
lv_btn_get_toggle_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
bool res;
|
||||||
return lv_btn_get_toggle(btn);
|
wgl_native_return_type(bool);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
|
res = lv_btn_get_toggle(btn);
|
||||||
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_toggle_wrapper)
|
||||||
lv_btn_toggle_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * btn)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, btn);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
lv_btn_toggle(btn);
|
lv_btn_toggle(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WGLNativeFuncDef btn_native_func_defs[] = {
|
static WGLNativeFuncDef btn_native_func_defs[] = {
|
||||||
{ BTN_FUNC_ID_CREATE, lv_btn_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
{ BTN_FUNC_ID_CREATE, lv_btn_create_wrapper, 2, false },
|
||||||
{ BTN_FUNC_ID_SET_TOGGLE, lv_btn_set_toggle_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_SET_TOGGLE, lv_btn_set_toggle_wrapper, 2, true },
|
||||||
{ BTN_FUNC_ID_SET_STATE, lv_btn_set_state_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_SET_STATE, lv_btn_set_state_wrapper, 2, true },
|
||||||
// { BTN_FUNC_ID_SET_STYLE, _btn_set_style, NO_RET, 2, {0, -1}, {-1} },
|
{ BTN_FUNC_ID_SET_INK_IN_TIME, lv_btn_set_ink_in_time_wrapper, 2, true },
|
||||||
{ BTN_FUNC_ID_SET_INK_IN_TIME, lv_btn_set_ink_in_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_SET_INK_OUT_TIME, lv_btn_set_ink_out_time_wrapper, 2, true },
|
||||||
{ BTN_FUNC_ID_SET_INK_OUT_TIME, lv_btn_set_ink_out_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_SET_INK_WAIT_TIME, lv_btn_set_ink_wait_time_wrapper, 2, true },
|
||||||
{ BTN_FUNC_ID_SET_INK_WAIT_TIME, lv_btn_set_ink_wait_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_GET_INK_IN_TIME, lv_btn_get_ink_in_time_wrapper, 1, true },
|
||||||
{ BTN_FUNC_ID_GET_INK_IN_TIME, lv_btn_get_ink_in_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_GET_INK_OUT_TIME, lv_btn_get_ink_out_time_wrapper, 1, true },
|
||||||
{ BTN_FUNC_ID_GET_INK_OUT_TIME, lv_btn_get_ink_out_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_GET_INK_WAIT_TIME, lv_btn_get_ink_wait_time_wrapper, 1, true },
|
||||||
{ BTN_FUNC_ID_GET_INK_WAIT_TIME, lv_btn_get_ink_wait_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_GET_STATE, lv_btn_get_state_wrapper, 1, true },
|
||||||
{ BTN_FUNC_ID_GET_STATE, lv_btn_get_state_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_GET_TOGGLE, lv_btn_get_toggle_wrapper, 1, true },
|
||||||
{ BTN_FUNC_ID_GET_TOGGLE, lv_btn_get_toggle_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
{ BTN_FUNC_ID_TOGGLE, lv_btn_toggle_wrapper, 1, true },
|
||||||
{ BTN_FUNC_ID_TOGGLE, lv_btn_toggle_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -128,10 +152,9 @@ void
|
||||||
wasm_btn_native_call(wasm_exec_env_t exec_env,
|
wasm_btn_native_call(wasm_exec_env_t exec_env,
|
||||||
int32 func_id, uint32 *argv, uint32 argc)
|
int32 func_id, uint32 *argv, uint32 argc)
|
||||||
{
|
{
|
||||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
||||||
uint32 size = sizeof(btn_native_func_defs) / sizeof(WGLNativeFuncDef);
|
uint32 size = sizeof(btn_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||||
|
|
||||||
wgl_native_func_call(module_inst,
|
wgl_native_func_call(exec_env,
|
||||||
btn_native_func_defs,
|
btn_native_func_defs,
|
||||||
size,
|
size,
|
||||||
func_id,
|
func_id,
|
||||||
|
|
|
@ -12,62 +12,88 @@
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* Label widget native function wrappers
|
* Label widget native function wrappers
|
||||||
* -------------------------------------------------------------------------*/
|
* -------------------------------------------------------------------------*/
|
||||||
static int32
|
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_create_wrapper)
|
||||||
lv_cb_create_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t *par, lv_obj_t *copy)
|
|
||||||
{
|
{
|
||||||
return wgl_native_wigdet_create(WIDGET_TYPE_CB, par, copy, module_inst);
|
int32 res;
|
||||||
|
wgl_native_return_type(int32);
|
||||||
|
wgl_native_get_arg(uint32, par_obj_id);
|
||||||
|
wgl_native_get_arg(uint32, copy_obj_id);
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
|
res = wgl_native_wigdet_create(WIDGET_TYPE_CB, par_obj_id, copy_obj_id, module_inst);
|
||||||
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_set_text_wrapper)
|
||||||
lv_cb_set_text_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * cb, const char * txt)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
char *text;
|
||||||
lv_cb_set_text(cb, txt);
|
wgl_native_get_arg(lv_obj_t *, cb);
|
||||||
|
wgl_native_get_arg(uint32, text_offset);
|
||||||
|
wgl_native_get_arg(uint32, text_len);
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
|
if (!validate_app_addr(text_offset, text_len)
|
||||||
|
|| !(text = addr_app_to_native(text_offset)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
lv_cb_set_text(cb, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_set_static_text_wrapper)
|
||||||
lv_cb_set_static_text_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * cb, const char * txt)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
char *text;
|
||||||
lv_cb_set_static_text(cb, txt);
|
wgl_native_get_arg(lv_obj_t *, cb);
|
||||||
|
wgl_native_get_arg(uint32, text_offset);
|
||||||
|
wgl_native_get_arg(uint32, text_len);
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
|
if (!validate_app_addr(text_offset, text_len)
|
||||||
|
|| !(text = addr_app_to_native(text_offset)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
lv_cb_set_static_text(cb, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32
|
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_get_text_length_wrapper)
|
||||||
lv_cb_get_text_length_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t *cb)
|
|
||||||
{
|
{
|
||||||
const char *text = lv_cb_get_text(cb);
|
const char *text;
|
||||||
|
wgl_native_return_type(int32);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, cb);
|
||||||
|
|
||||||
if (text == NULL)
|
(void)exec_env;
|
||||||
return 0;
|
|
||||||
|
|
||||||
return strlen(text);
|
text = lv_cb_get_text(cb);
|
||||||
|
wgl_native_set_return(text ? strlen(text): 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_get_text_wrapper)
|
||||||
lv_cb_get_text_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t *cb, char *buffer, int buffer_len)
|
|
||||||
{
|
{
|
||||||
const char *text = lv_cb_get_text(cb);
|
const char *text;
|
||||||
|
char *buffer;
|
||||||
|
wgl_native_return_type(uint32);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, cb);
|
||||||
|
wgl_native_get_arg(uint32, buffer_offset);
|
||||||
|
wgl_native_get_arg(int, buffer_len);
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
if (text == NULL)
|
if (!validate_app_addr(buffer_offset, buffer_len)
|
||||||
return 0;
|
|| !(buffer = addr_app_to_native(buffer_offset)))
|
||||||
|
return;
|
||||||
|
|
||||||
strncpy(buffer, text, buffer_len - 1);
|
if ((text = lv_cb_get_text(cb))) {
|
||||||
buffer[buffer_len - 1] = '\0';
|
strncpy(buffer, text, buffer_len - 1);
|
||||||
|
buffer[buffer_len - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
return buffer;
|
wgl_native_set_return(buffer_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WGLNativeFuncDef cb_native_func_defs[] = {
|
static WGLNativeFuncDef cb_native_func_defs[] = {
|
||||||
{ CB_FUNC_ID_CREATE, lv_cb_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
{ CB_FUNC_ID_CREATE, lv_cb_create_wrapper, 2, false },
|
||||||
{ CB_FUNC_ID_SET_TEXT, lv_cb_set_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
|
{ CB_FUNC_ID_SET_TEXT, lv_cb_set_text_wrapper, 3, true },
|
||||||
{ CB_FUNC_ID_SET_STATIC_TEXT, lv_cb_set_static_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
|
{ CB_FUNC_ID_SET_STATIC_TEXT, lv_cb_set_static_text_wrapper, 3, true },
|
||||||
{ CB_FUNC_ID_GET_TEXT_LENGTH, lv_cb_get_text_length_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
{ CB_FUNC_ID_GET_TEXT_LENGTH, lv_cb_get_text_length_wrapper, 1, true },
|
||||||
{ CB_FUNC_ID_GET_TEXT, lv_cb_get_text_wrapper, RET_PTR, 4, {1, -1}, {2, -1} },
|
{ CB_FUNC_ID_GET_TEXT, lv_cb_get_text_wrapper, 3, true },
|
||||||
};
|
};
|
||||||
|
|
||||||
/*************** Native Interface to Wasm App ***********/
|
/*************** Native Interface to Wasm App ***********/
|
||||||
|
@ -75,10 +101,9 @@ void
|
||||||
wasm_cb_native_call(wasm_exec_env_t exec_env,
|
wasm_cb_native_call(wasm_exec_env_t exec_env,
|
||||||
int32 func_id, uint32 *argv, uint32 argc)
|
int32 func_id, uint32 *argv, uint32 argc)
|
||||||
{
|
{
|
||||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
||||||
uint32 size = sizeof(cb_native_func_defs) / sizeof(WGLNativeFuncDef);
|
uint32 size = sizeof(cb_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||||
|
|
||||||
wgl_native_func_call(module_inst,
|
wgl_native_func_call(exec_env,
|
||||||
cb_native_func_defs,
|
cb_native_func_defs,
|
||||||
size,
|
size,
|
||||||
func_id,
|
func_id,
|
||||||
|
|
|
@ -12,53 +12,72 @@
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* Label widget native function wrappers
|
* Label widget native function wrappers
|
||||||
* -------------------------------------------------------------------------*/
|
* -------------------------------------------------------------------------*/
|
||||||
static int32
|
DEFINE_WGL_NATIVE_WRAPPER(lv_label_create_wrapper)
|
||||||
lv_label_create_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t *par, lv_obj_t *copy)
|
|
||||||
{
|
{
|
||||||
return wgl_native_wigdet_create(WIDGET_TYPE_LABEL, par, copy, module_inst);
|
int32 res;
|
||||||
|
wgl_native_return_type(int32);
|
||||||
|
wgl_native_get_arg(uint32, par_obj_id);
|
||||||
|
wgl_native_get_arg(uint32, copy_obj_id);
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
|
res = wgl_native_wigdet_create(WIDGET_TYPE_LABEL, par_obj_id, copy_obj_id, module_inst);
|
||||||
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_label_set_text_wrapper)
|
||||||
lv_label_set_text_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * label, const char * text)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
char *text;
|
||||||
|
wgl_native_get_arg(lv_obj_t *, label);
|
||||||
|
wgl_native_get_arg(uint32, text_offset);
|
||||||
|
wgl_native_get_arg(uint32, text_len);
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
|
if (!validate_app_addr(text_offset, text_len)
|
||||||
|
|| !(text = addr_app_to_native(text_offset)))
|
||||||
|
return;
|
||||||
|
|
||||||
lv_label_set_text(label, text);
|
lv_label_set_text(label, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32
|
DEFINE_WGL_NATIVE_WRAPPER(lv_label_get_text_length_wrapper)
|
||||||
lv_label_get_text_length_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t *label)
|
|
||||||
{
|
{
|
||||||
char *text = lv_label_get_text(label);
|
wgl_native_return_type(int32);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, label);
|
||||||
|
const char *text;
|
||||||
|
|
||||||
if (text == NULL)
|
(void)exec_env;
|
||||||
return 0;
|
|
||||||
|
|
||||||
return strlen(text);
|
text = lv_label_get_text(label);
|
||||||
|
wgl_native_set_return(text ? strlen(text) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
DEFINE_WGL_NATIVE_WRAPPER(lv_label_get_text_wrapper)
|
||||||
lv_label_get_text_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t *label, char *buffer, int buffer_len)
|
|
||||||
{
|
{
|
||||||
char *text = lv_label_get_text(label);
|
const char *text;
|
||||||
|
char *buffer;
|
||||||
|
wgl_native_return_type(uint32);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, label);
|
||||||
|
wgl_native_get_arg(uint32, buffer_offset);
|
||||||
|
wgl_native_get_arg(int, buffer_len);
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
if (text == NULL)
|
if (!validate_app_addr(buffer_offset, buffer_len)
|
||||||
return 0;
|
|| !(buffer = addr_app_to_native(buffer_offset)))
|
||||||
|
return;
|
||||||
|
|
||||||
strncpy(buffer, text, buffer_len - 1);
|
if ((text = lv_label_get_text(label))) {
|
||||||
buffer[buffer_len - 1] = '\0';
|
strncpy(buffer, text, buffer_len - 1);
|
||||||
|
buffer[buffer_len - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
return buffer;
|
wgl_native_set_return(buffer_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WGLNativeFuncDef label_native_func_defs[] = {
|
static WGLNativeFuncDef label_native_func_defs[] = {
|
||||||
{ LABEL_FUNC_ID_CREATE, lv_label_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
{ LABEL_FUNC_ID_CREATE, lv_label_create_wrapper, 2, false },
|
||||||
{ LABEL_FUNC_ID_SET_TEXT, lv_label_set_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
|
{ LABEL_FUNC_ID_SET_TEXT, lv_label_set_text_wrapper, 3, true },
|
||||||
{ LABEL_FUNC_ID_GET_TEXT_LENGTH, lv_label_get_text_length_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
{ LABEL_FUNC_ID_GET_TEXT_LENGTH, lv_label_get_text_length_wrapper, 1, true },
|
||||||
{ LABEL_FUNC_ID_GET_TEXT, lv_label_get_text_wrapper, RET_PTR, 4, {1, -1}, {2, -1} },
|
{ LABEL_FUNC_ID_GET_TEXT, lv_label_get_text_wrapper, 3, true },
|
||||||
};
|
};
|
||||||
|
|
||||||
/*************** Native Interface to Wasm App ***********/
|
/*************** Native Interface to Wasm App ***********/
|
||||||
|
@ -66,10 +85,9 @@ void
|
||||||
wasm_label_native_call(wasm_exec_env_t exec_env,
|
wasm_label_native_call(wasm_exec_env_t exec_env,
|
||||||
int32 func_id, uint32 *argv, uint32 argc)
|
int32 func_id, uint32 *argv, uint32 argc)
|
||||||
{
|
{
|
||||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
||||||
uint32 size = sizeof(label_native_func_defs) / sizeof(WGLNativeFuncDef);
|
uint32 size = sizeof(label_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||||
|
|
||||||
wgl_native_func_call(module_inst,
|
wgl_native_func_call(exec_env,
|
||||||
label_native_func_defs,
|
label_native_func_defs,
|
||||||
size,
|
size,
|
||||||
func_id,
|
func_id,
|
||||||
|
|
|
@ -12,38 +12,53 @@
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* List widget native function wrappers
|
* List widget native function wrappers
|
||||||
* -------------------------------------------------------------------------*/
|
* -------------------------------------------------------------------------*/
|
||||||
static int32
|
DEFINE_WGL_NATIVE_WRAPPER(lv_list_create_wrapper)
|
||||||
lv_list_create_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t *par, lv_obj_t *copy)
|
|
||||||
{
|
{
|
||||||
return wgl_native_wigdet_create(WIDGET_TYPE_LIST, par, copy, module_inst);
|
int32 res;
|
||||||
|
wgl_native_return_type(int32);
|
||||||
|
wgl_native_get_arg(uint32, par_obj_id);
|
||||||
|
wgl_native_get_arg(uint32, copy_obj_id);
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
|
res = wgl_native_wigdet_create(WIDGET_TYPE_LIST, par_obj_id, copy_obj_id, module_inst);
|
||||||
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32
|
DEFINE_WGL_NATIVE_WRAPPER(lv_list_add_btn_wrapper)
|
||||||
lv_list_add_btn_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t *list, const char *text)
|
|
||||||
{
|
{
|
||||||
|
wgl_native_return_type(int32);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, list);
|
||||||
|
wgl_native_get_arg(uint32, text_offset);
|
||||||
|
wgl_native_get_arg(uint32, text_len);
|
||||||
uint32 btn_obj_id;
|
uint32 btn_obj_id;
|
||||||
lv_obj_t *btn;
|
lv_obj_t *btn;
|
||||||
uint32 mod_id;
|
uint32 mod_id;
|
||||||
|
char *text;
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
btn = lv_list_add_btn(list, NULL, text);
|
if (!validate_app_addr(text_offset, text_len)
|
||||||
|
|| !(text = addr_app_to_native(text_offset)))
|
||||||
|
return;
|
||||||
|
|
||||||
if (btn == NULL)
|
if (!(btn = lv_list_add_btn(list, NULL, text))) {
|
||||||
return 0;
|
wasm_runtime_set_exception(module_inst, "add button to list fail.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mod_id = app_manager_get_module_id(Module_WASM_App, module_inst);
|
mod_id = app_manager_get_module_id(Module_WASM_App, module_inst);
|
||||||
bh_assert(mod_id != ID_NONE);
|
bh_assert(mod_id != ID_NONE);
|
||||||
|
|
||||||
if (wgl_native_add_object(btn, mod_id, &btn_obj_id))
|
if (!wgl_native_add_object(btn, mod_id, &btn_obj_id)) {
|
||||||
return btn_obj_id; /* success return */
|
wasm_runtime_set_exception(module_inst, "add button to object list fail.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
wgl_native_set_return(btn_obj_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WGLNativeFuncDef list_native_func_defs[] = {
|
static WGLNativeFuncDef list_native_func_defs[] = {
|
||||||
{ LIST_FUNC_ID_CREATE, lv_list_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
{ LIST_FUNC_ID_CREATE, lv_list_create_wrapper, 2, false },
|
||||||
{ LIST_FUNC_ID_ADD_BTN, lv_list_add_btn_wrapper, HAS_RET, 3, {1, -1}, {2, -1} },
|
{ LIST_FUNC_ID_ADD_BTN, lv_list_add_btn_wrapper, 3, true },
|
||||||
};
|
};
|
||||||
|
|
||||||
/*************** Native Interface to Wasm App ***********/
|
/*************** Native Interface to Wasm App ***********/
|
||||||
|
@ -51,10 +66,9 @@ void
|
||||||
wasm_list_native_call(wasm_exec_env_t exec_env,
|
wasm_list_native_call(wasm_exec_env_t exec_env,
|
||||||
int32 func_id, uint32 *argv, uint32 argc)
|
int32 func_id, uint32 *argv, uint32 argc)
|
||||||
{
|
{
|
||||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
||||||
uint32 size = sizeof(list_native_func_defs) / sizeof(WGLNativeFuncDef);
|
uint32 size = sizeof(list_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||||
|
|
||||||
wgl_native_func_call(module_inst,
|
wgl_native_func_call(exec_env,
|
||||||
list_native_func_defs,
|
list_native_func_defs,
|
||||||
size,
|
size,
|
||||||
func_id,
|
func_id,
|
||||||
|
|
|
@ -10,18 +10,28 @@
|
||||||
|
|
||||||
#define THROW_EXC(msg) wasm_runtime_set_exception(module_inst, msg);
|
#define THROW_EXC(msg) wasm_runtime_set_exception(module_inst, msg);
|
||||||
|
|
||||||
void
|
uint32 wgl_native_wigdet_create(int8 widget_type,
|
||||||
wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
|
uint32 par_obj_id,
|
||||||
|
uint32 copy_obj_id,
|
||||||
uint32 wgl_native_wigdet_create(int8 widget_type, lv_obj_t *par, lv_obj_t *copy,
|
|
||||||
wasm_module_inst_t module_inst)
|
wasm_module_inst_t module_inst)
|
||||||
{
|
{
|
||||||
uint32 obj_id;
|
uint32 obj_id;
|
||||||
lv_obj_t *wigdet = NULL;
|
lv_obj_t *wigdet = NULL, *par = NULL, *copy = NULL;
|
||||||
uint32 mod_id;
|
uint32 mod_id;
|
||||||
|
|
||||||
//TODO: limit total widget number
|
//TODO: limit total widget number
|
||||||
|
|
||||||
|
/* validate the parent object id if not equal to 0 */
|
||||||
|
if (par_obj_id != 0 && !wgl_native_validate_object(par_obj_id, &par)) {
|
||||||
|
THROW_EXC("create widget with invalid parent object.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* validate the copy object id if not equal to 0 */
|
||||||
|
if (copy_obj_id != 0 && !wgl_native_validate_object(copy_obj_id, ©)) {
|
||||||
|
THROW_EXC("create widget with invalid copy object.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (par == NULL)
|
if (par == NULL)
|
||||||
par = lv_disp_get_scr_act(NULL);
|
par = lv_disp_get_scr_act(NULL);
|
||||||
|
|
||||||
|
@ -48,146 +58,58 @@ uint32 wgl_native_wigdet_create(int8 widget_type, lv_obj_t *par, lv_obj_t *copy,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void invokeNative(intptr_t argv[], uint32 argc, void (*native_code)())
|
void wgl_native_func_call(wasm_exec_env_t exec_env,
|
||||||
{
|
|
||||||
bh_assert(argc >= 1);
|
|
||||||
|
|
||||||
switch(argc) {
|
|
||||||
case 1:
|
|
||||||
native_code(argv[0]);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
native_code(argv[0], argv[1]);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
native_code(argv[0], argv[1], argv[2]);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
native_code(argv[0], argv[1], argv[2], argv[3]);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4]);
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
|
||||||
argv[6]);
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
|
||||||
argv[6], argv[7]);
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
|
||||||
argv[6], argv[7], argv[8]);
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
native_code(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5],
|
|
||||||
argv[6], argv[7], argv[8], argv[9]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
/* FIXME: If this happen, add more cases. */
|
|
||||||
wasm_module_inst_t module_inst = (wasm_module_inst_t)argv[0];
|
|
||||||
THROW_EXC("the argument number of native function exceeds maximum");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef void (*GenericFunctionPointer)();
|
|
||||||
typedef int32 (*Int32FuncPtr)(intptr_t *, uint32, GenericFunctionPointer);
|
|
||||||
typedef void (*VoidFuncPtr)(intptr_t *, uint32, GenericFunctionPointer);
|
|
||||||
|
|
||||||
static Int32FuncPtr invokeNative_Int32 = (Int32FuncPtr)invokeNative;
|
|
||||||
static VoidFuncPtr invokeNative_Void = (VoidFuncPtr)invokeNative;
|
|
||||||
|
|
||||||
void wgl_native_func_call(wasm_module_inst_t module_inst,
|
|
||||||
WGLNativeFuncDef *funcs,
|
WGLNativeFuncDef *funcs,
|
||||||
uint32 size,
|
uint32 size,
|
||||||
int32 func_id,
|
int32 func_id,
|
||||||
uint32 *argv,
|
uint32 *argv,
|
||||||
uint32 argc)
|
uint32 argc)
|
||||||
{
|
{
|
||||||
|
typedef void (*WGLNativeFuncPtr)(wasm_exec_env_t, uint64*, uint32*);
|
||||||
|
WGLNativeFuncPtr wglNativeFuncPtr;
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
WGLNativeFuncDef *func_def = funcs;
|
WGLNativeFuncDef *func_def = funcs;
|
||||||
WGLNativeFuncDef *func_def_end = func_def + size;
|
WGLNativeFuncDef *func_def_end = func_def + size;
|
||||||
|
|
||||||
while (func_def < func_def_end) {
|
/* Note: argv is validated in wasm_runtime_invoke_native()
|
||||||
if (func_def->func_id == func_id) {
|
* with pointer length equals to 1. Here validate the argv
|
||||||
int i, obj_arg_num = 0, ptr_arg_num = 0, argc1 = 0;
|
* buffer again but with its total length in bytes */
|
||||||
intptr_t argv_copy_buf[16];
|
if (!wasm_runtime_validate_native_addr(module_inst, argv, argc * sizeof(uint32)))
|
||||||
intptr_t *argv_copy = argv_copy_buf;
|
return;
|
||||||
|
|
||||||
argc1++; /* module_inst */
|
while (func_def < func_def_end) {
|
||||||
argc1 += func_def->arg_num;
|
if (func_def->func_id == func_id
|
||||||
if (argc1 > 16) {
|
&& (uint32)func_def->arg_num == argc) {
|
||||||
argv_copy = (intptr_t *)wasm_runtime_malloc(func_def->arg_num *
|
uint64 argv_copy_buf[16], size;
|
||||||
sizeof(intptr_t));
|
uint64 *argv_copy = argv_copy_buf;
|
||||||
if (argv_copy == NULL)
|
int i;
|
||||||
|
|
||||||
|
if (argc > sizeof(argv_copy_buf) / sizeof(uint64)) {
|
||||||
|
size = sizeof(uint64) * (uint64)argc;
|
||||||
|
if (size >= UINT32_MAX
|
||||||
|
|| !(argv_copy = wasm_runtime_malloc((uint32)size))) {
|
||||||
|
THROW_EXC("allocate memory failed.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
memset(argv_copy, 0, (uint32)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init argv_copy */
|
/* Init argv_copy */
|
||||||
argv_copy[0] = (intptr_t)module_inst;
|
|
||||||
for (i = 0; i < func_def->arg_num; i++)
|
for (i = 0; i < func_def->arg_num; i++)
|
||||||
argv_copy[i + 1] = (intptr_t)argv[i];
|
*(uint32*)&argv_copy[i] = argv[i];
|
||||||
|
|
||||||
/* Validate object arguments */
|
/* Validate the first argument which is a lvgl object if needed */
|
||||||
i = 0;
|
if (func_def->check_obj) {
|
||||||
for (; i < OBJ_ARG_NUM_MAX && func_def->obj_arg_indexes[i] != 0xff;
|
lv_obj_t *obj = NULL;
|
||||||
i++, obj_arg_num++) {
|
if (!wgl_native_validate_object(argv[0], &obj)) {
|
||||||
uint8 index = func_def->obj_arg_indexes[i];
|
|
||||||
bool null_ok = index & NULL_OK;
|
|
||||||
|
|
||||||
index = index & (~NULL_OK);
|
|
||||||
|
|
||||||
/* Some API's allow to pass NULL obj, such as xxx_create() */
|
|
||||||
if (argv_copy[index] == 0) {
|
|
||||||
if (!null_ok) {
|
|
||||||
THROW_EXC("the object id is 0 and invalid");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
/* Continue so that to pass null object validation */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wgl_native_validate_object(argv_copy[index],
|
|
||||||
(lv_obj_t **)&argv_copy[index])) {
|
|
||||||
THROW_EXC("the object is invalid");
|
THROW_EXC("the object is invalid");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
*(lv_obj_t **)&argv_copy[0] = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validate address arguments */
|
wglNativeFuncPtr = (WGLNativeFuncPtr)func_def->func_ptr;
|
||||||
i = 0;
|
wglNativeFuncPtr(exec_env, argv_copy, argv);
|
||||||
for (; i < PTR_ARG_NUM_MAX && func_def->ptr_arg_indexes[i] != 0xff;
|
|
||||||
i++, ptr_arg_num++) {
|
|
||||||
uint8 index = func_def->ptr_arg_indexes[i];
|
|
||||||
|
|
||||||
/* The index+1 arg is the data size to be validated */
|
|
||||||
if (!validate_app_addr(argv_copy[index], argv_copy[index + 1]))
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
/* Convert to native address before call lvgl function */
|
|
||||||
argv_copy[index] = (intptr_t)addr_app_to_native(argv_copy[index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (func_def->has_ret == NO_RET)
|
|
||||||
invokeNative_Void(argv_copy,
|
|
||||||
argc1,
|
|
||||||
func_def->func_ptr);
|
|
||||||
else {
|
|
||||||
argv[0] = invokeNative_Int32(argv_copy,
|
|
||||||
argc1,
|
|
||||||
func_def->func_ptr);
|
|
||||||
/* Convert to app memory offset if return value is a
|
|
||||||
* native address pointer */
|
|
||||||
if (func_def->has_ret == RET_PTR)
|
|
||||||
argv[0] = addr_native_to_app((char *)(intptr_t)argv[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argv_copy != argv_copy_buf)
|
if (argv_copy != argv_copy_buf)
|
||||||
wasm_runtime_free(argv_copy);
|
wasm_runtime_free(argv_copy);
|
||||||
|
|
|
@ -15,19 +15,12 @@ extern "C" {
|
||||||
#include "wasm_export.h"
|
#include "wasm_export.h"
|
||||||
#include "bi-inc/wgl_shared_utils.h"
|
#include "bi-inc/wgl_shared_utils.h"
|
||||||
|
|
||||||
#define OBJ_ARG_NUM_MAX 4
|
#define wgl_native_return_type(type) type *wgl_ret = (type*)(args_ret)
|
||||||
#define PTR_ARG_NUM_MAX 4
|
#define wgl_native_get_arg(type, name) type name = *((type*)(args++))
|
||||||
|
#define wgl_native_set_return(val) *wgl_ret = (val)
|
||||||
|
|
||||||
#define NULL_OK 0x80
|
#define DEFINE_WGL_NATIVE_WRAPPER(func_name) \
|
||||||
|
static void func_name(wasm_exec_env_t exec_env, uint64 *args, uint32 *args_ret)
|
||||||
enum {
|
|
||||||
/* The function has a normal return value (not a pointer) */
|
|
||||||
HAS_RET,
|
|
||||||
/* The function doesn't have return value */
|
|
||||||
NO_RET,
|
|
||||||
/* The function's return value is a native address pointer */
|
|
||||||
RET_PTR
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
WIDGET_TYPE_BTN,
|
WIDGET_TYPE_BTN,
|
||||||
|
@ -46,19 +39,11 @@ typedef struct WGLNativeFuncDef {
|
||||||
/* Native function pointer */
|
/* Native function pointer */
|
||||||
void *func_ptr;
|
void *func_ptr;
|
||||||
|
|
||||||
/* whether has return value */
|
|
||||||
uint8 has_ret;
|
|
||||||
|
|
||||||
/* argument number */
|
/* argument number */
|
||||||
uint8 arg_num;
|
uint8 arg_num;
|
||||||
|
|
||||||
/* low 7 bit: obj argument index
|
/* whether the first argument is lvgl object and needs validate */
|
||||||
* highest 1 bit: allow obj be null or not
|
bool check_obj;
|
||||||
* -1 means the end of this array */
|
|
||||||
uint8 obj_arg_indexes[OBJ_ARG_NUM_MAX];
|
|
||||||
|
|
||||||
/* pointer argument indexes, -1 means the end of this array */
|
|
||||||
uint8 ptr_arg_indexes[PTR_ARG_NUM_MAX];
|
|
||||||
} WGLNativeFuncDef;
|
} WGLNativeFuncDef;
|
||||||
|
|
||||||
bool wgl_native_validate_object(int32 obj_id, lv_obj_t **obj);
|
bool wgl_native_validate_object(int32 obj_id, lv_obj_t **obj);
|
||||||
|
@ -66,11 +51,11 @@ bool wgl_native_validate_object(int32 obj_id, lv_obj_t **obj);
|
||||||
bool wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id);
|
bool wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id);
|
||||||
|
|
||||||
uint32 wgl_native_wigdet_create(int8 widget_type,
|
uint32 wgl_native_wigdet_create(int8 widget_type,
|
||||||
lv_obj_t *par,
|
uint32 par_obj_id,
|
||||||
lv_obj_t *copy,
|
uint32 copy_obj_id,
|
||||||
wasm_module_inst_t module_inst);
|
wasm_module_inst_t module_inst);
|
||||||
|
|
||||||
void wgl_native_func_call(wasm_module_inst_t module_inst,
|
void wgl_native_func_call(wasm_exec_env_t exec_env,
|
||||||
WGLNativeFuncDef *funcs,
|
WGLNativeFuncDef *funcs,
|
||||||
uint32 size,
|
uint32 size,
|
||||||
int32 func_id,
|
int32 func_id,
|
||||||
|
|
|
@ -322,29 +322,34 @@ void wgl_exit(void)
|
||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* Obj native function wrappers
|
* Obj native function wrappers
|
||||||
* -------------------------------------------------------------------------*/
|
* -------------------------------------------------------------------------*/
|
||||||
static lv_res_t
|
DEFINE_WGL_NATIVE_WRAPPER(lv_obj_del_wrapper)
|
||||||
lv_obj_del_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
lv_res_t res;
|
||||||
|
wgl_native_return_type(lv_res_t);
|
||||||
|
wgl_native_get_arg(lv_obj_t *, obj);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
|
|
||||||
/* Recursively delete object node in the list belong to this
|
/* Recursively delete object node in the list belong to this
|
||||||
* parent object including itself */
|
* parent object including itself */
|
||||||
_obj_del_recursive(obj);
|
_obj_del_recursive(obj);
|
||||||
|
res = lv_obj_del(obj);
|
||||||
return lv_obj_del(obj);
|
wgl_native_set_return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_obj_del_async_wrapper)
|
||||||
lv_obj_del_async_wrapper(wasm_module_inst_t module_inst, lv_obj_t * obj)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, obj);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
lv_obj_del_async(obj);
|
lv_obj_del_async(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_obj_clean_wrapper)
|
||||||
lv_obj_clean_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, obj);
|
||||||
|
|
||||||
|
(void)exec_env;
|
||||||
|
|
||||||
/* Recursively delete child object node in the list belong to this
|
/* Recursively delete child object node in the list belong to this
|
||||||
* parent object */
|
* parent object */
|
||||||
|
@ -354,33 +359,40 @@ lv_obj_clean_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
||||||
lv_obj_clean(obj);
|
lv_obj_clean(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_obj_align_wrapper)
|
||||||
lv_obj_align_wrapper(wasm_module_inst_t module_inst,
|
|
||||||
lv_obj_t * obj,
|
|
||||||
const lv_obj_t * base,
|
|
||||||
lv_align_t align,
|
|
||||||
lv_coord_t x_mod,
|
|
||||||
lv_coord_t y_mod)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, obj);
|
||||||
|
wgl_native_get_arg(uint32, base_obj_id);
|
||||||
|
wgl_native_get_arg(lv_align_t, align);
|
||||||
|
wgl_native_get_arg(lv_coord_t, x_mod);
|
||||||
|
wgl_native_get_arg(lv_coord_t, y_mod);
|
||||||
|
lv_obj_t *base = NULL;
|
||||||
|
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||||
|
|
||||||
|
/* validate the base object id if not equal to 0 */
|
||||||
|
if (base_obj_id != 0 && !wgl_native_validate_object(base_obj_id, &base)) {
|
||||||
|
wasm_runtime_set_exception(module_inst, "align with invalid base object.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lv_obj_align(obj, base, align, x_mod, y_mod);
|
lv_obj_align(obj, base, align, x_mod, y_mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
DEFINE_WGL_NATIVE_WRAPPER(lv_obj_set_event_cb_wrapper)
|
||||||
lv_obj_set_event_cb_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
|
||||||
{
|
{
|
||||||
(void)module_inst;
|
wgl_native_get_arg(lv_obj_t *, obj);
|
||||||
|
(void)exec_env;
|
||||||
lv_obj_set_event_cb(obj, internal_lv_obj_event_cb);
|
lv_obj_set_event_cb(obj, internal_lv_obj_event_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
static WGLNativeFuncDef obj_native_func_defs[] = {
|
static WGLNativeFuncDef obj_native_func_defs[] = {
|
||||||
{ OBJ_FUNC_ID_DEL, lv_obj_del_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
{ OBJ_FUNC_ID_DEL, lv_obj_del_wrapper, 1, true },
|
||||||
{ OBJ_FUNC_ID_DEL_ASYNC, lv_obj_del_async_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
{ OBJ_FUNC_ID_DEL_ASYNC, lv_obj_del_async_wrapper, 1, true },
|
||||||
{ OBJ_FUNC_ID_CLEAN, lv_obj_clean_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
{ OBJ_FUNC_ID_CLEAN, lv_obj_clean_wrapper, 1, true },
|
||||||
{ OBJ_FUNC_ID_ALIGN, lv_obj_align_wrapper, NO_RET, 6, {1, 2 | NULL_OK, -1}, {-1} },
|
{ OBJ_FUNC_ID_ALIGN, lv_obj_align_wrapper, 5, true },
|
||||||
{ OBJ_FUNC_ID_SET_EVT_CB, lv_obj_set_event_cb_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
{ OBJ_FUNC_ID_SET_EVT_CB, lv_obj_set_event_cb_wrapper, 1, true },
|
||||||
};
|
};
|
||||||
|
|
||||||
/*************** Native Interface to Wasm App ***********/
|
/*************** Native Interface to Wasm App ***********/
|
||||||
|
@ -388,10 +400,9 @@ void
|
||||||
wasm_obj_native_call(wasm_exec_env_t exec_env,
|
wasm_obj_native_call(wasm_exec_env_t exec_env,
|
||||||
int32 func_id, uint32 *argv, uint32 argc)
|
int32 func_id, uint32 *argv, uint32 argc)
|
||||||
{
|
{
|
||||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
|
||||||
uint32 size = sizeof(obj_native_func_defs) / sizeof(WGLNativeFuncDef);
|
uint32 size = sizeof(obj_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||||
|
|
||||||
wgl_native_func_call(module_inst,
|
wgl_native_func_call(exec_env,
|
||||||
obj_native_func_defs,
|
obj_native_func_defs,
|
||||||
size,
|
size,
|
||||||
func_id,
|
func_id,
|
||||||
|
|
|
@ -362,6 +362,17 @@ wasm_application_execute_func(wasm_module_inst_t module_inst,
|
||||||
const char *
|
const char *
|
||||||
wasm_runtime_get_exception(wasm_module_inst_t module_inst);
|
wasm_runtime_get_exception(wasm_module_inst_t module_inst);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set exception info of the WASM module instance.
|
||||||
|
*
|
||||||
|
* @param module_inst the WASM module instance
|
||||||
|
*
|
||||||
|
* @param exception the exception string
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
wasm_runtime_set_exception(wasm_module_inst_t module_inst,
|
||||||
|
const char *exception);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear exception info of the WASM module instance.
|
* Clear exception info of the WASM module instance.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user