Skip to content

Commit 374e687

Browse files
authored
Refine wgl native functions call (#225)
1 parent 30bab1b commit 374e687

File tree

8 files changed

+340
-331
lines changed

8 files changed

+340
-331
lines changed

core/app-framework/wgl/native/wgl_btn_wrapper.c

Lines changed: 91 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,115 +11,139 @@
1111
/* -------------------------------------------------------------------------
1212
* Button widget native function wrappers
1313
* -------------------------------------------------------------------------*/
14-
static int32
15-
lv_btn_create_wrapper(wasm_module_inst_t module_inst,
16-
lv_obj_t *par, lv_obj_t *copy)
14+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_create_wrapper)
1715
{
18-
return wgl_native_wigdet_create(WIDGET_TYPE_BTN, par, copy, module_inst);
16+
int32 res;
17+
wgl_native_return_type(int32);
18+
wgl_native_get_arg(uint32, par_obj_id);
19+
wgl_native_get_arg(uint32, copy_obj_id);
20+
wasm_module_inst_t module_inst = get_module_inst(exec_env);
21+
22+
res = wgl_native_wigdet_create(WIDGET_TYPE_BTN, par_obj_id, copy_obj_id, module_inst);
23+
wgl_native_set_return(res);
1924
}
2025

21-
static void
22-
lv_btn_set_toggle_wrapper(wasm_module_inst_t module_inst,
23-
lv_obj_t * btn, bool tgl)
26+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_toggle_wrapper)
2427
{
25-
(void)module_inst;
28+
wgl_native_get_arg(lv_obj_t *, btn);
29+
wgl_native_get_arg(bool, tgl);
30+
31+
(void)exec_env;
2632
lv_btn_set_toggle(btn, tgl);
2733
}
2834

29-
static void
30-
lv_btn_set_state_wrapper(wasm_module_inst_t module_inst,
31-
lv_obj_t * btn, lv_btn_state_t state)
35+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_state_wrapper)
3236
{
33-
(void)module_inst;
37+
wgl_native_get_arg(lv_obj_t *, btn);
38+
wgl_native_get_arg(lv_btn_state_t, state);
39+
40+
(void)exec_env;
3441
lv_btn_set_state(btn, state);
3542
}
3643

37-
static void
38-
lv_btn_set_ink_in_time_wrapper(wasm_module_inst_t module_inst,
39-
lv_obj_t * btn, uint16_t time)
44+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_ink_in_time_wrapper)
4045
{
41-
(void)module_inst;
46+
wgl_native_get_arg(lv_obj_t *, btn);
47+
wgl_native_get_arg(uint16_t, time);
48+
49+
(void)exec_env;
4250
lv_btn_set_ink_in_time(btn, time);
4351
}
4452

45-
static void
46-
lv_btn_set_ink_out_time_wrapper(wasm_module_inst_t module_inst,
47-
lv_obj_t * btn, uint16_t time)
53+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_ink_out_time_wrapper)
4854
{
49-
(void)module_inst;
55+
wgl_native_get_arg(lv_obj_t *, btn);
56+
wgl_native_get_arg(uint16_t, time);
57+
58+
(void)exec_env;
5059
lv_btn_set_ink_out_time(btn, time);
5160
}
5261

53-
static void
54-
lv_btn_set_ink_wait_time_wrapper(wasm_module_inst_t module_inst,
55-
lv_obj_t * btn, uint16_t time)
62+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_set_ink_wait_time_wrapper)
5663
{
57-
(void)module_inst;
64+
wgl_native_get_arg(lv_obj_t *, btn);
65+
wgl_native_get_arg(uint16_t, time);
66+
67+
(void)exec_env;
5868
lv_btn_set_ink_wait_time(btn, time);
5969
}
6070

61-
static uint16_t
62-
lv_btn_get_ink_in_time_wrapper(wasm_module_inst_t module_inst,
63-
lv_obj_t * btn)
71+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_ink_in_time_wrapper)
6472
{
65-
(void)module_inst;
66-
return lv_btn_get_ink_in_time(btn);
73+
uint16_t res;
74+
wgl_native_return_type(uint16_t);
75+
wgl_native_get_arg(lv_obj_t *, btn);
76+
77+
(void)exec_env;
78+
res = lv_btn_get_ink_in_time(btn);
79+
wgl_native_set_return(res);
6780
}
6881

69-
static uint16_t
70-
lv_btn_get_ink_out_time_wrapper(wasm_module_inst_t module_inst,
71-
lv_obj_t * btn)
82+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_ink_out_time_wrapper)
7283
{
73-
(void)module_inst;
74-
return lv_btn_get_ink_out_time(btn);
84+
uint16_t res;
85+
wgl_native_return_type(uint16_t);
86+
wgl_native_get_arg(lv_obj_t *, btn);
87+
88+
(void)exec_env;
89+
res = lv_btn_get_ink_out_time(btn);
90+
wgl_native_set_return(res);
7591
}
7692

77-
static uint16_t
78-
lv_btn_get_ink_wait_time_wrapper(wasm_module_inst_t module_inst,
79-
lv_obj_t * btn)
93+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_ink_wait_time_wrapper)
8094
{
81-
(void)module_inst;
82-
return lv_btn_get_ink_wait_time(btn);
95+
uint16_t res;
96+
wgl_native_return_type(uint16_t);
97+
wgl_native_get_arg(lv_obj_t *, btn);
98+
99+
(void)exec_env;
100+
res = lv_btn_get_ink_wait_time(btn);
101+
wgl_native_set_return(res);
83102
}
84103

85-
static lv_btn_state_t
86-
lv_btn_get_state_wrapper(wasm_module_inst_t module_inst,
87-
lv_obj_t * btn)
104+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_state_wrapper)
88105
{
89-
(void)module_inst;
90-
return lv_btn_get_state(btn);
106+
lv_btn_state_t res;
107+
wgl_native_return_type(lv_btn_state_t);
108+
wgl_native_get_arg(lv_obj_t *, btn);
109+
110+
(void)exec_env;
111+
res = lv_btn_get_state(btn);
112+
wgl_native_set_return(res);
91113
}
92114

93-
static bool
94-
lv_btn_get_toggle_wrapper(wasm_module_inst_t module_inst,
95-
lv_obj_t * btn)
115+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_get_toggle_wrapper)
96116
{
97-
(void)module_inst;
98-
return lv_btn_get_toggle(btn);
117+
bool res;
118+
wgl_native_return_type(bool);
119+
wgl_native_get_arg(lv_obj_t *, btn);
120+
121+
(void)exec_env;
122+
res = lv_btn_get_toggle(btn);
123+
wgl_native_set_return(res);
99124
}
100125

101-
static void
102-
lv_btn_toggle_wrapper(wasm_module_inst_t module_inst,
103-
lv_obj_t * btn)
126+
DEFINE_WGL_NATIVE_WRAPPER(lv_btn_toggle_wrapper)
104127
{
105-
(void)module_inst;
128+
wgl_native_get_arg(lv_obj_t *, btn);
129+
130+
(void)exec_env;
106131
lv_btn_toggle(btn);
107132
}
108133

109134
static WGLNativeFuncDef btn_native_func_defs[] = {
110-
{ BTN_FUNC_ID_CREATE, lv_btn_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
111-
{ BTN_FUNC_ID_SET_TOGGLE, lv_btn_set_toggle_wrapper, NO_RET, 3, {1, -1}, {-1} },
112-
{ BTN_FUNC_ID_SET_STATE, lv_btn_set_state_wrapper, NO_RET, 3, {1, -1}, {-1} },
113-
// { BTN_FUNC_ID_SET_STYLE, _btn_set_style, NO_RET, 2, {0, -1}, {-1} },
114-
{ BTN_FUNC_ID_SET_INK_IN_TIME, lv_btn_set_ink_in_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
115-
{ BTN_FUNC_ID_SET_INK_OUT_TIME, lv_btn_set_ink_out_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
116-
{ BTN_FUNC_ID_SET_INK_WAIT_TIME, lv_btn_set_ink_wait_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
117-
{ BTN_FUNC_ID_GET_INK_IN_TIME, lv_btn_get_ink_in_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
118-
{ BTN_FUNC_ID_GET_INK_OUT_TIME, lv_btn_get_ink_out_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
119-
{ BTN_FUNC_ID_GET_INK_WAIT_TIME, lv_btn_get_ink_wait_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
120-
{ BTN_FUNC_ID_GET_STATE, lv_btn_get_state_wrapper, HAS_RET, 2, {1, -1}, {-1} },
121-
{ BTN_FUNC_ID_GET_TOGGLE, lv_btn_get_toggle_wrapper, HAS_RET, 2, {1, -1}, {-1} },
122-
{ BTN_FUNC_ID_TOGGLE, lv_btn_toggle_wrapper, NO_RET, 2, {1, -1}, {-1} },
135+
{ BTN_FUNC_ID_CREATE, lv_btn_create_wrapper, 2, false },
136+
{ BTN_FUNC_ID_SET_TOGGLE, lv_btn_set_toggle_wrapper, 2, true },
137+
{ BTN_FUNC_ID_SET_STATE, lv_btn_set_state_wrapper, 2, true },
138+
{ BTN_FUNC_ID_SET_INK_IN_TIME, lv_btn_set_ink_in_time_wrapper, 2, true },
139+
{ BTN_FUNC_ID_SET_INK_OUT_TIME, lv_btn_set_ink_out_time_wrapper, 2, true },
140+
{ BTN_FUNC_ID_SET_INK_WAIT_TIME, lv_btn_set_ink_wait_time_wrapper, 2, true },
141+
{ BTN_FUNC_ID_GET_INK_IN_TIME, lv_btn_get_ink_in_time_wrapper, 1, true },
142+
{ BTN_FUNC_ID_GET_INK_OUT_TIME, lv_btn_get_ink_out_time_wrapper, 1, true },
143+
{ BTN_FUNC_ID_GET_INK_WAIT_TIME, lv_btn_get_ink_wait_time_wrapper, 1, true },
144+
{ BTN_FUNC_ID_GET_STATE, lv_btn_get_state_wrapper, 1, true },
145+
{ BTN_FUNC_ID_GET_TOGGLE, lv_btn_get_toggle_wrapper, 1, true },
146+
{ BTN_FUNC_ID_TOGGLE, lv_btn_toggle_wrapper, 1, true },
123147

124148
};
125149

@@ -128,10 +152,9 @@ void
128152
wasm_btn_native_call(wasm_exec_env_t exec_env,
129153
int32 func_id, uint32 *argv, uint32 argc)
130154
{
131-
wasm_module_inst_t module_inst = get_module_inst(exec_env);
132155
uint32 size = sizeof(btn_native_func_defs) / sizeof(WGLNativeFuncDef);
133156

134-
wgl_native_func_call(module_inst,
157+
wgl_native_func_call(exec_env,
135158
btn_native_func_defs,
136159
size,
137160
func_id,

core/app-framework/wgl/native/wgl_cb_wrapper.c

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,73 +12,98 @@
1212
/* -------------------------------------------------------------------------
1313
* Label widget native function wrappers
1414
* -------------------------------------------------------------------------*/
15-
static int32
16-
lv_cb_create_wrapper(wasm_module_inst_t module_inst,
17-
lv_obj_t *par, lv_obj_t *copy)
15+
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_create_wrapper)
1816
{
19-
return wgl_native_wigdet_create(WIDGET_TYPE_CB, par, copy, module_inst);
17+
int32 res;
18+
wgl_native_return_type(int32);
19+
wgl_native_get_arg(uint32, par_obj_id);
20+
wgl_native_get_arg(uint32, copy_obj_id);
21+
wasm_module_inst_t module_inst = get_module_inst(exec_env);
22+
23+
res = wgl_native_wigdet_create(WIDGET_TYPE_CB, par_obj_id, copy_obj_id, module_inst);
24+
wgl_native_set_return(res);
2025
}
2126

22-
static void
23-
lv_cb_set_text_wrapper(wasm_module_inst_t module_inst,
24-
lv_obj_t * cb, const char * txt)
27+
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_set_text_wrapper)
2528
{
26-
(void)module_inst;
27-
lv_cb_set_text(cb, txt);
29+
char *text;
30+
wgl_native_get_arg(lv_obj_t *, cb);
31+
wgl_native_get_arg(uint32, text_offset);
32+
wgl_native_get_arg(uint32, text_len);
33+
wasm_module_inst_t module_inst = get_module_inst(exec_env);
34+
35+
if (!validate_app_addr(text_offset, text_len)
36+
|| !(text = addr_app_to_native(text_offset)))
37+
return;
38+
39+
lv_cb_set_text(cb, text);
2840
}
2941

30-
static void
31-
lv_cb_set_static_text_wrapper(wasm_module_inst_t module_inst,
32-
lv_obj_t * cb, const char * txt)
42+
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_set_static_text_wrapper)
3343
{
34-
(void)module_inst;
35-
lv_cb_set_static_text(cb, txt);
44+
char *text;
45+
wgl_native_get_arg(lv_obj_t *, cb);
46+
wgl_native_get_arg(uint32, text_offset);
47+
wgl_native_get_arg(uint32, text_len);
48+
wasm_module_inst_t module_inst = get_module_inst(exec_env);
49+
50+
if (!validate_app_addr(text_offset, text_len)
51+
|| !(text = addr_app_to_native(text_offset)))
52+
return;
53+
54+
lv_cb_set_static_text(cb, text);
3655
}
3756

38-
static int32
39-
lv_cb_get_text_length_wrapper(wasm_module_inst_t module_inst,
40-
lv_obj_t *cb)
57+
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_get_text_length_wrapper)
4158
{
42-
const char *text = lv_cb_get_text(cb);
59+
const char *text;
60+
wgl_native_return_type(int32);
61+
wgl_native_get_arg(lv_obj_t *, cb);
4362

44-
if (text == NULL)
45-
return 0;
63+
(void)exec_env;
4664

47-
return strlen(text);
65+
text = lv_cb_get_text(cb);
66+
wgl_native_set_return(text ? strlen(text): 0);
4867
}
4968

50-
static char *
51-
lv_cb_get_text_wrapper(wasm_module_inst_t module_inst,
52-
lv_obj_t *cb, char *buffer, int buffer_len)
69+
DEFINE_WGL_NATIVE_WRAPPER(lv_cb_get_text_wrapper)
5370
{
54-
const char *text = lv_cb_get_text(cb);
71+
const char *text;
72+
char *buffer;
73+
wgl_native_return_type(uint32);
74+
wgl_native_get_arg(lv_obj_t *, cb);
75+
wgl_native_get_arg(uint32, buffer_offset);
76+
wgl_native_get_arg(int, buffer_len);
77+
wasm_module_inst_t module_inst = get_module_inst(exec_env);
5578

56-
if (text == NULL)
57-
return 0;
79+
if (!validate_app_addr(buffer_offset, buffer_len)
80+
|| !(buffer = addr_app_to_native(buffer_offset)))
81+
return;
5882

59-
strncpy(buffer, text, buffer_len - 1);
60-
buffer[buffer_len - 1] = '\0';
83+
if ((text = lv_cb_get_text(cb))) {
84+
strncpy(buffer, text, buffer_len - 1);
85+
buffer[buffer_len - 1] = '\0';
86+
}
6187

62-
return buffer;
88+
wgl_native_set_return(buffer_offset);
6389
}
6490

6591
static WGLNativeFuncDef cb_native_func_defs[] = {
66-
{ CB_FUNC_ID_CREATE, lv_cb_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
67-
{ CB_FUNC_ID_SET_TEXT, lv_cb_set_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
68-
{ CB_FUNC_ID_SET_STATIC_TEXT, lv_cb_set_static_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
69-
{ CB_FUNC_ID_GET_TEXT_LENGTH, lv_cb_get_text_length_wrapper, HAS_RET, 2, {1, -1}, {-1} },
70-
{ CB_FUNC_ID_GET_TEXT, lv_cb_get_text_wrapper, RET_PTR, 4, {1, -1}, {2, -1} },
92+
{ CB_FUNC_ID_CREATE, lv_cb_create_wrapper, 2, false },
93+
{ CB_FUNC_ID_SET_TEXT, lv_cb_set_text_wrapper, 3, true },
94+
{ CB_FUNC_ID_SET_STATIC_TEXT, lv_cb_set_static_text_wrapper, 3, true },
95+
{ CB_FUNC_ID_GET_TEXT_LENGTH, lv_cb_get_text_length_wrapper, 1, true },
96+
{ CB_FUNC_ID_GET_TEXT, lv_cb_get_text_wrapper, 3, true },
7197
};
7298

7399
/*************** Native Interface to Wasm App ***********/
74100
void
75101
wasm_cb_native_call(wasm_exec_env_t exec_env,
76102
int32 func_id, uint32 *argv, uint32 argc)
77103
{
78-
wasm_module_inst_t module_inst = get_module_inst(exec_env);
79104
uint32 size = sizeof(cb_native_func_defs) / sizeof(WGLNativeFuncDef);
80105

81-
wgl_native_func_call(module_inst,
106+
wgl_native_func_call(exec_env,
82107
cb_native_func_defs,
83108
size,
84109
func_id,

0 commit comments

Comments
 (0)