Add parameter module inst for native wrapper functions (#117)
And add asm code of em64/arm/mips version to call native wrapper functions; Fix some issues of calling wrapper functions;
This commit is contained in:
@ -18,6 +18,8 @@
|
||||
#include "request.h"
|
||||
#include "shared_utils.h"
|
||||
#include "wasm_app.h"
|
||||
#include "req_resp_api.h"
|
||||
#include "timer_api.h"
|
||||
|
||||
#define TRANSACTION_TIMEOUT_MS 5000
|
||||
|
||||
@ -138,15 +140,15 @@ static bool register_url_handler(const char *url,
|
||||
|
||||
// tell app mgr to route this url to me
|
||||
if (reg_type == Reg_Request)
|
||||
wasm_register_resource((int32)url);
|
||||
wasm_register_resource(url);
|
||||
else
|
||||
wasm_sub_event((int32)url);
|
||||
wasm_sub_event(url);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool api_register_resource_handler(const char *url,
|
||||
request_handler_f request_handler)
|
||||
request_handler_f request_handler)
|
||||
{
|
||||
return register_url_handler(url, request_handler, Reg_Request);
|
||||
}
|
||||
@ -242,7 +244,7 @@ void api_send_request(request_t * request, response_handler_f response_handler,
|
||||
}
|
||||
}
|
||||
|
||||
wasm_post_request((int32)buffer, size);
|
||||
wasm_post_request(buffer, size);
|
||||
|
||||
free_req_resp_packet(buffer);
|
||||
}
|
||||
@ -329,7 +331,7 @@ void api_response_send(response_t *response)
|
||||
if (buffer == NULL)
|
||||
return;
|
||||
|
||||
wasm_response_send((int32)buffer, size);
|
||||
wasm_response_send(buffer, size);
|
||||
free_req_resp_packet(buffer);
|
||||
}
|
||||
|
||||
@ -343,7 +345,7 @@ bool api_publish_event(const char *url, int fmt, void *payload, int payload_len)
|
||||
char * buffer = pack_request(request, &size);
|
||||
if (buffer == NULL)
|
||||
return false;
|
||||
wasm_post_request((int32)buffer, size);
|
||||
wasm_post_request(buffer, size);
|
||||
|
||||
free_req_resp_packet(buffer);
|
||||
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
#ifndef _AEE_REQUEST_H_
|
||||
#define _AEE_REQUEST_H_
|
||||
|
||||
#include "native_interface.h"
|
||||
#include "shared_utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "timer_wasm_app.h"
|
||||
#include "native_interface.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "timer_wasm_app.h"
|
||||
#include "timer_api.h"
|
||||
|
||||
#if 1
|
||||
#include <stdio.h>
|
||||
#else
|
||||
|
||||
@ -32,7 +32,6 @@
|
||||
#ifndef _LIB_AEE_H_
|
||||
#define _LIB_AEE_H_
|
||||
|
||||
#include "native_interface.h"
|
||||
#include "shared_utils.h"
|
||||
#include "attr_container.h"
|
||||
#include "request.h"
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "connection.h"
|
||||
#include "native_interface.h"
|
||||
#include "connection_api.h"
|
||||
|
||||
/* Raw connection structure */
|
||||
typedef struct _connection {
|
||||
@ -44,7 +44,7 @@ connection_t *api_open_connection(const char *name,
|
||||
char *args_buffer = (char *)args;
|
||||
uint32 handle, args_len = attr_container_get_serialize_length(args);
|
||||
|
||||
handle = wasm_open_connection((int32)name, (int32)args_buffer, args_len);
|
||||
handle = wasm_open_connection(name, args_buffer, args_len);
|
||||
if (handle == -1)
|
||||
return NULL;
|
||||
|
||||
@ -91,7 +91,7 @@ void api_close_connection(connection_t *c)
|
||||
|
||||
int api_send_on_connection(connection_t *conn, const char *data, uint32 len)
|
||||
{
|
||||
return wasm_send_on_connection(conn->handle, (int32)data, len);
|
||||
return wasm_send_on_connection(conn->handle, data, len);
|
||||
}
|
||||
|
||||
bool api_config_connection(connection_t *conn, attr_container_t *cfg)
|
||||
@ -99,7 +99,7 @@ bool api_config_connection(connection_t *conn, attr_container_t *cfg)
|
||||
char *cfg_buffer = (char *)cfg;
|
||||
uint32 cfg_len = attr_container_get_serialize_length(cfg);
|
||||
|
||||
return wasm_config_connection(conn->handle, (int32)cfg_buffer, cfg_len);
|
||||
return wasm_config_connection(conn->handle, cfg_buffer, cfg_len);
|
||||
}
|
||||
|
||||
void on_connection_data(uint32 handle, char *buffer, uint32 len)
|
||||
|
||||
@ -15,11 +15,11 @@
|
||||
*/
|
||||
|
||||
#include "wgl.h"
|
||||
#include "native_interface.h"
|
||||
|
||||
#include "bh_platform.h"
|
||||
#include "gui_api.h"
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_BTN_NATIVE_FUNC(id) wasm_btn_native_call(id, (int32)argv, ARGC)
|
||||
#define CALL_BTN_NATIVE_FUNC(id) wasm_btn_native_call(id, argv, ARGC)
|
||||
|
||||
wgl_obj_t wgl_btn_create(wgl_obj_t par, wgl_obj_t copy)
|
||||
{
|
||||
|
||||
@ -15,12 +15,12 @@
|
||||
*/
|
||||
|
||||
#include "wgl.h"
|
||||
#include "native_interface.h"
|
||||
#include "gui_api.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_CB_NATIVE_FUNC(id) wasm_cb_native_call(id, (uint32)argv, ARGC)
|
||||
#define CALL_CB_NATIVE_FUNC(id) wasm_cb_native_call(id, argv, ARGC)
|
||||
|
||||
wgl_obj_t wgl_cb_create(wgl_obj_t par, const wgl_obj_t copy)
|
||||
{
|
||||
|
||||
@ -16,12 +16,12 @@
|
||||
|
||||
|
||||
#include "wgl.h"
|
||||
#include "native_interface.h"
|
||||
#include "gui_api.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_LABEL_NATIVE_FUNC(id) wasm_label_native_call(id, (uint32)argv, ARGC)
|
||||
#define CALL_LABEL_NATIVE_FUNC(id) wasm_label_native_call(id, argv, ARGC)
|
||||
|
||||
wgl_obj_t wgl_label_create(wgl_obj_t par, wgl_obj_t copy)
|
||||
{
|
||||
|
||||
@ -15,12 +15,12 @@
|
||||
*/
|
||||
|
||||
#include "wgl.h"
|
||||
#include "native_interface.h"
|
||||
#include "gui_api.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_LIST_NATIVE_FUNC(id) wasm_list_native_call(id, (int32)argv, ARGC)
|
||||
#define CALL_LIST_NATIVE_FUNC(id) wasm_list_native_call(id, argv, ARGC)
|
||||
|
||||
|
||||
wgl_obj_t wgl_list_create(wgl_obj_t par, const wgl_obj_t copy)
|
||||
|
||||
@ -15,12 +15,12 @@
|
||||
*/
|
||||
|
||||
#include "wgl.h"
|
||||
#include "native_interface.h"
|
||||
#include "gui_api.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ARGC sizeof(argv)/sizeof(uint32)
|
||||
#define CALL_OBJ_NATIVE_FUNC(id) wasm_obj_native_call(id, (int32)argv, ARGC)
|
||||
#define CALL_OBJ_NATIVE_FUNC(id) wasm_obj_native_call(id, argv, ARGC)
|
||||
|
||||
typedef struct _obj_evt_cb {
|
||||
struct _obj_evt_cb *next;
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "sensor.h"
|
||||
#include "native_interface.h"
|
||||
#include "sensor_api.h"
|
||||
|
||||
typedef struct _sensor {
|
||||
struct _sensor * next;
|
||||
@ -31,7 +31,7 @@ sensor_t sensor_open(const char* name, int index,
|
||||
sensor_event_handler_f sensor_event_handler,
|
||||
void *user_data)
|
||||
{
|
||||
uint32 id = wasm_sensor_open((int32)name, index);
|
||||
uint32 id = wasm_sensor_open(name, index);
|
||||
if (id == -1)
|
||||
return NULL;
|
||||
|
||||
@ -66,7 +66,7 @@ bool sensor_config_with_attr_container(sensor_t sensor, attr_container_t *cfg)
|
||||
char *buffer = (char *)cfg;
|
||||
int len = attr_container_get_serialize_length(cfg);
|
||||
|
||||
return wasm_sensor_config_with_attr_container(sensor->handle, (int32)buffer, len);
|
||||
return wasm_sensor_config_with_attr_container(sensor->handle, buffer, len);
|
||||
}
|
||||
|
||||
bool sensor_config(sensor_t sensor, int interval, int bit_cfg, int delay)
|
||||
|
||||
@ -16,23 +16,28 @@
|
||||
|
||||
#ifndef CONNECTION_API_H_
|
||||
#define CONNECTION_API_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint32 wasm_open_connection(int32 name_offset, int32 args_offset, uint32 len);
|
||||
uint32
|
||||
wasm_open_connection(const char *name, char *args_buf, uint32 args_buf_len);
|
||||
|
||||
void wasm_close_connection(uint32 handle);
|
||||
void
|
||||
wasm_close_connection(uint32 handle);
|
||||
|
||||
int wasm_send_on_connection(uint32 handle, int32 data_offset, uint32 len);
|
||||
int
|
||||
wasm_send_on_connection(uint32 handle, const char *data, uint32 data_len);
|
||||
|
||||
bool wasm_config_connection(uint32 handle, int32 cfg_offset, uint32 len);
|
||||
bool
|
||||
wasm_config_connection(uint32 handle, const char *cfg_buf, uint32 cfg_buf_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* CONNECTION_API_H_ */
|
||||
#endif /* end of CONNECTION_API_H_ */
|
||||
|
||||
@ -14,19 +14,29 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GUI_API_H_
|
||||
#define GUI_API_H_
|
||||
#ifndef _GUI_API_H_
|
||||
#define _GUI_API_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void wasm_obj_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
void wasm_btn_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
void wasm_label_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
void wasm_cb_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
void wasm_list_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
void
|
||||
wasm_obj_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_btn_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_label_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_cb_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_list_native_call(int32 func_id, uint32 *argv, uint32 argc);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -34,4 +44,4 @@ void wasm_list_native_call(int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* GUI_API_H_ */
|
||||
#endif /* end of _GUI_API_H_ */
|
||||
|
||||
@ -14,12 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_NATIVE_INTERFACE_H_
|
||||
#define DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_NATIVE_INTERFACE_H_
|
||||
#ifndef _NATIVE_INTERFACE_H_
|
||||
#define _NATIVE_INTERFACE_H_
|
||||
|
||||
// note: the bh_plaform.h is the only head file separately
|
||||
// implemented by both [app] and [native] worlds
|
||||
/* Note: the bh_plaform.h is the only head file separately
|
||||
implemented by both [app] and [native] worlds */
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#define get_module_inst() \
|
||||
wasm_runtime_get_current_module_inst()
|
||||
@ -39,52 +40,102 @@
|
||||
#define module_free(offset) \
|
||||
wasm_runtime_module_free(module_inst, offset)
|
||||
|
||||
char *wa_strdup(const char *);
|
||||
|
||||
bool
|
||||
wasm_response_send(int32 buffer_offset, int size);
|
||||
|
||||
void wasm_register_resource(int32 url_offset);
|
||||
|
||||
void wasm_post_request(int32 buffer_offset, int size);
|
||||
|
||||
void wasm_sub_event(int32 url_offset);
|
||||
/*char *wa_strdup(const char *);*/
|
||||
|
||||
/*
|
||||
* ************* sensor interfaces *************
|
||||
* request/response interfaces
|
||||
*/
|
||||
|
||||
bool
|
||||
wasm_sensor_config(uint32 sensor, int interval, int bit_cfg, int delay);
|
||||
uint32
|
||||
wasm_sensor_open(int32 name_offset, int instance);
|
||||
bool
|
||||
wasm_sensor_config_with_attr_container(uint32 sensor, int32 buffer_offset,
|
||||
int len);
|
||||
|
||||
bool
|
||||
wasm_sensor_close(uint32 sensor);
|
||||
wasm_response_send(wasm_module_inst_t module_inst,
|
||||
int32 buffer_offset, int size);
|
||||
void
|
||||
wasm_register_resource(wasm_module_inst_t module_inst,
|
||||
int32 url_offset);
|
||||
void
|
||||
wasm_post_request(wasm_module_inst_t module_inst,
|
||||
int32 buffer_offset, int size);
|
||||
void
|
||||
wasm_sub_event(wasm_module_inst_t module_inst,
|
||||
int32 url_offset);
|
||||
|
||||
/*
|
||||
* *** timer interface ***
|
||||
* sensor interfaces
|
||||
*/
|
||||
|
||||
bool
|
||||
wasm_sensor_config(wasm_module_inst_t module_inst,
|
||||
uint32 sensor, int interval, int bit_cfg, int delay);
|
||||
uint32
|
||||
wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
int32 name_offset, int instance);
|
||||
bool
|
||||
wasm_sensor_config_with_attr_container(wasm_module_inst_t module_inst,
|
||||
uint32 sensor,
|
||||
int32 buffer_offset, int len);
|
||||
bool
|
||||
wasm_sensor_close(wasm_module_inst_t module_inst,
|
||||
uint32 sensor);
|
||||
|
||||
/*
|
||||
* timer interfaces
|
||||
*/
|
||||
|
||||
typedef unsigned int timer_id_t;
|
||||
timer_id_t wasm_create_timer(int interval, bool is_period, bool auto_start);
|
||||
void wasm_timer_destory(timer_id_t timer_id);
|
||||
void wasm_timer_cancel(timer_id_t timer_id);
|
||||
void wasm_timer_restart(timer_id_t timer_id, int interval);
|
||||
uint32 wasm_get_sys_tick_ms(void);
|
||||
|
||||
timer_id_t
|
||||
wasm_create_timer(wasm_module_inst_t module_inst,
|
||||
int interval, bool is_period, bool auto_start);
|
||||
void
|
||||
wasm_timer_destory(wasm_module_inst_t module_inst, timer_id_t timer_id);
|
||||
void
|
||||
wasm_timer_cancel(wasm_module_inst_t module_inst, timer_id_t timer_id);
|
||||
void
|
||||
wasm_timer_restart(wasm_module_inst_t module_inst,
|
||||
timer_id_t timer_id, int interval);
|
||||
uint32
|
||||
wasm_get_sys_tick_ms(wasm_module_inst_t module_inst);
|
||||
|
||||
/*
|
||||
* *** connection interface ***
|
||||
* connection interfaces
|
||||
*/
|
||||
uint32 wasm_open_connection(int32 name_offset, int32 args_offset, uint32 len);
|
||||
void wasm_close_connection(uint32 handle);
|
||||
int wasm_send_on_connection(uint32 handle, int32 data_offset, uint32 len);
|
||||
bool wasm_config_connection(uint32 handle, int32 cfg_offset, uint32 len);
|
||||
|
||||
#include "gui_api.h"
|
||||
uint32
|
||||
wasm_open_connection(wasm_module_inst_t module_inst,
|
||||
int32 name_offset, int32 args_offset, uint32 len);
|
||||
void
|
||||
wasm_close_connection(wasm_module_inst_t module_inst,
|
||||
uint32 handle);
|
||||
int
|
||||
wasm_send_on_connection(wasm_module_inst_t module_inst,
|
||||
uint32 handle, int32 data_offset, uint32 len);
|
||||
bool
|
||||
wasm_config_connection(wasm_module_inst_t module_inst,
|
||||
uint32 handle, int32 cfg_offset, uint32 len);
|
||||
|
||||
/**
|
||||
* gui interfaces
|
||||
*/
|
||||
|
||||
void
|
||||
wasm_obj_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_btn_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_label_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_cb_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_list_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
#endif /* end of _NATIVE_INTERFACE_H */
|
||||
|
||||
#endif /* DEPS_SSG_MICRO_RUNTIME_WASM_PO
|
||||
C_APP_LIBS_NATIVE_INTERFACE_NATIVE_INTERFACE_H_ */
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Attention:
|
||||
=======
|
||||
Only add files are shared by both wasm application and native runtime into this directory!
|
||||
Only add files which are shared by both wasm application and native runtime into this directory!
|
||||
|
||||
The c files are both compiled into the the WASM APP and native runtime.
|
||||
|
||||
|
||||
43
core/iwasm/lib/native-interface/req_resp_api.h
Normal file
43
core/iwasm/lib/native-interface/req_resp_api.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _REQ_RESP_API_H_
|
||||
#define _REQ_RESP_API_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool
|
||||
wasm_response_send(const char *buf, int size);
|
||||
|
||||
void
|
||||
wasm_register_resource(const char *url);
|
||||
|
||||
void
|
||||
wasm_post_request(const char *buf, int size);
|
||||
|
||||
void
|
||||
wasm_sub_event(const char *url);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _REQ_RESP_API_H_ */
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "native_interface.h"
|
||||
#include "shared_utils.h"
|
||||
|
||||
/* Serialization of request and response message
|
||||
|
||||
@ -14,8 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DEPS_IWASM_APP_LIBS_NATIVE_INTERFACE_SENSOR_API_H_
|
||||
#define DEPS_IWASM_APP_LIBS_NATIVE_INTERFACE_SENSOR_API_H_
|
||||
#ifndef _SENSOR_API_H_
|
||||
#define _SENSOR_API_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -29,7 +30,7 @@ bool
|
||||
wasm_sensor_config(uint32 sensor, int interval, int bit_cfg, int delay);
|
||||
|
||||
bool
|
||||
wasm_sensor_config_with_attr_container(uint32 sensor, char * buffer, int len);
|
||||
wasm_sensor_config_with_attr_container(uint32 sensor, char *buffer, int len);
|
||||
|
||||
bool
|
||||
wasm_sensor_close(uint32 sensor);
|
||||
@ -38,4 +39,5 @@ wasm_sensor_close(uint32 sensor);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DEPS_IWASM_APP_LIBS_NATIVE_INTERFACE_SENSOR_API_H_ */
|
||||
#endif /* end of _SENSOR_API_H_ */
|
||||
|
||||
|
||||
@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_SHARED_UTILS_H_
|
||||
#define DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_SHARED_UTILS_H_
|
||||
#ifndef _SHARED_UTILS_H_
|
||||
#define _SHARED_UTILS_H_
|
||||
|
||||
#include "native_interface.h"
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -71,16 +71,27 @@ typedef struct response {
|
||||
unsigned long reciever;
|
||||
} response_t;
|
||||
|
||||
int check_url_start(const char* url, int url_len, const char * leading_str);
|
||||
bool match_url(char * pattern, char * matched);
|
||||
char * find_key_value(char * buffer, int buffer_len, char * key, char * value,
|
||||
int value_len, char delimiter);
|
||||
int
|
||||
check_url_start(const char* url, int url_len, const char * leading_str);
|
||||
|
||||
request_t *clone_request(request_t *request);
|
||||
void request_cleaner(request_t *request);
|
||||
bool
|
||||
match_url(char * pattern, char * matched);
|
||||
|
||||
response_t * clone_response(response_t * response);
|
||||
void response_cleaner(response_t * response);
|
||||
char *
|
||||
find_key_value(char * buffer, int buffer_len, char * key, char * value,
|
||||
int value_len, char delimiter);
|
||||
|
||||
request_t *
|
||||
clone_request(request_t *request);
|
||||
|
||||
void
|
||||
request_cleaner(request_t *request);
|
||||
|
||||
response_t *
|
||||
clone_response(response_t * response);
|
||||
|
||||
void
|
||||
response_cleaner(response_t * response);
|
||||
|
||||
/**
|
||||
* @brief Set fields of response.
|
||||
@ -95,8 +106,9 @@ void response_cleaner(response_t * response);
|
||||
*
|
||||
* @warning the response pointer MUST NOT be NULL
|
||||
*/
|
||||
response_t * set_response(response_t * response, int status, int fmt,
|
||||
const char *payload, int payload_len);
|
||||
response_t *
|
||||
set_response(response_t * response, int status, int fmt,
|
||||
const char *payload, int payload_len);
|
||||
|
||||
/**
|
||||
* @brief Make a response for a request.
|
||||
@ -108,8 +120,8 @@ response_t * set_response(response_t * response, int status, int fmt,
|
||||
*
|
||||
* @warning the request and response pointers MUST NOT be NULL
|
||||
*/
|
||||
response_t * make_response_for_request(request_t * request,
|
||||
response_t * response);
|
||||
response_t *
|
||||
make_response_for_request(request_t * request, response_t * response);
|
||||
|
||||
/**
|
||||
* @brief Initialize a request.
|
||||
@ -125,14 +137,24 @@ response_t * make_response_for_request(request_t * request,
|
||||
*
|
||||
* @warning the request pointer MUST NOT be NULL
|
||||
*/
|
||||
request_t * init_request(request_t * request, char *url, int action, int fmt,
|
||||
void *payload, int payload_len);
|
||||
request_t *
|
||||
init_request(request_t * request, char *url, int action, int fmt,
|
||||
void *payload, int payload_len);
|
||||
|
||||
char * pack_request(request_t *request, int * size);
|
||||
request_t * unpack_request(char * packet, int size, request_t * request);
|
||||
char * pack_response(response_t *response, int * size);
|
||||
response_t * unpack_response(char * packet, int size, response_t * response);
|
||||
void free_req_resp_packet(char * packet);
|
||||
char *
|
||||
pack_request(request_t *request, int * size);
|
||||
|
||||
request_t *
|
||||
unpack_request(char * packet, int size, request_t * request);
|
||||
|
||||
char *
|
||||
pack_response(response_t *response, int * size);
|
||||
|
||||
response_t *
|
||||
unpack_response(char * packet, int size, response_t * response);
|
||||
|
||||
void
|
||||
free_req_resp_packet(char * packet);
|
||||
|
||||
#include "wgl_shared_utils.h"
|
||||
|
||||
@ -140,4 +162,4 @@ void free_req_resp_packet(char * packet);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_SHARED_UTILS_H_ */
|
||||
#endif /* end of _SHARED_UTILS_H_ */
|
||||
|
||||
48
core/iwasm/lib/native-interface/timer_api.h
Normal file
48
core/iwasm/lib/native-interface/timer_api.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _TIMER_API_H_
|
||||
#define _TIMER_API_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef unsigned int timer_id_t;
|
||||
|
||||
timer_id_t
|
||||
wasm_create_timer(int interval, bool is_period, bool auto_start);
|
||||
|
||||
void
|
||||
wasm_timer_destory(timer_id_t timer_id);
|
||||
|
||||
void
|
||||
wasm_timer_cancel(timer_id_t timer_id);
|
||||
|
||||
void
|
||||
wasm_timer_restart(timer_id_t timer_id, int interval);
|
||||
|
||||
uint32
|
||||
wasm_get_sys_tick_ms(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _TIMER_API_H_ */
|
||||
|
||||
102
core/iwasm/lib/native-interface/wasm_export_api.h
Normal file
102
core/iwasm/lib/native-interface/wasm_export_api.h
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _WASM_EXPORT_H
|
||||
#define _WASM_EXPORT_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* API exported to WASM application
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Get current WASM module instance of the current native thread
|
||||
*
|
||||
* @return current WASM module instance of the current native thread, 0
|
||||
* if not found
|
||||
* Note: the return type is uint64_t but not pointer type, because that
|
||||
* the we only supports WASM-32, in which the pointer type is
|
||||
* compiled to WASM i32 type, but the pointer type in native can be
|
||||
* 32-bit and 64-bit. And if the native pointer is 64-bit, data loss
|
||||
* occurs after converting it to WASM i32 type.
|
||||
*/
|
||||
uint64_t
|
||||
wasm_runtime_get_current_module_inst();
|
||||
|
||||
/**
|
||||
* Validate the app address, check whether it belongs to WASM module
|
||||
* instance's address space, or in its heap space or memory space.
|
||||
*
|
||||
* @param module_inst the WASM module instance
|
||||
* @param app_offset the app address to validate, which is a relative address
|
||||
* @param size the size bytes of the app address
|
||||
*
|
||||
* @return true if success, false otherwise.
|
||||
*/
|
||||
bool
|
||||
wasm_runtime_validate_app_addr(uint64_t module_inst,
|
||||
int32_t app_offset, uint32_t size);
|
||||
|
||||
/**
|
||||
* Validate the native address, check whether it belongs to WASM module
|
||||
* instance's address space, or in its heap space or memory space.
|
||||
*
|
||||
* @param module_inst the WASM module instance
|
||||
* @param native_ptr the native address to validate, which is an absolute
|
||||
* address
|
||||
* @param size the size bytes of the app address
|
||||
*
|
||||
* @return true if success, false otherwise.
|
||||
*/
|
||||
bool
|
||||
wasm_runtime_validate_native_addr(uint64_t module_inst,
|
||||
uint64_t native_ptr, uint32_t size);
|
||||
|
||||
/**
|
||||
* Convert app address(relative address) to native address(absolute address)
|
||||
*
|
||||
* @param module_inst the WASM module instance
|
||||
* @param app_offset the app adress
|
||||
*
|
||||
* @return the native address converted
|
||||
*/
|
||||
uint64_t
|
||||
wasm_runtime_addr_app_to_native(uint64_t module_inst,
|
||||
int32_t app_offset);
|
||||
|
||||
/**
|
||||
* Convert native address(absolute address) to app address(relative address)
|
||||
*
|
||||
* @param module_inst the WASM module instance
|
||||
* @param native_ptr the native address
|
||||
*
|
||||
* @return the app address converted
|
||||
*/
|
||||
int32_t
|
||||
wasm_runtime_addr_native_to_app(uint64_t module_inst,
|
||||
uint64_t native_ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _WASM_EXPORT_H */
|
||||
@ -26,19 +26,17 @@
|
||||
#endif
|
||||
|
||||
static uint64
|
||||
wasm_runtime_get_current_module_inst_wrapper()
|
||||
wasm_runtime_get_current_module_inst_wrapper(wasm_module_inst_t module_inst)
|
||||
{
|
||||
return (uint64)(uintptr_t)
|
||||
wasm_runtime_get_current_module_inst();
|
||||
return (uint64)(uintptr_t)module_inst;
|
||||
}
|
||||
|
||||
static bool
|
||||
wasm_runtime_validate_app_addr_wrapper(uint32 inst_part0, uint32 inst_part1,
|
||||
wasm_runtime_validate_app_addr_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 inst_part0, uint32 inst_part1,
|
||||
int32 app_offset, uint32 size)
|
||||
{
|
||||
bool ret;
|
||||
wasm_module_inst_t module_inst =
|
||||
wasm_runtime_get_current_module_inst();
|
||||
union { uint64 u64; uint32 parts[2]; } inst;
|
||||
|
||||
inst.parts[0] = inst_part0;
|
||||
@ -56,14 +54,13 @@ wasm_runtime_validate_app_addr_wrapper(uint32 inst_part0, uint32 inst_part1,
|
||||
}
|
||||
|
||||
static bool
|
||||
wasm_runtime_validate_native_addr_wrapper(uint32 inst_part0, uint32 inst_part1,
|
||||
wasm_runtime_validate_native_addr_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 inst_part0, uint32 inst_part1,
|
||||
uint32 native_ptr_part0,
|
||||
uint32 native_ptr_part1,
|
||||
uint32 size)
|
||||
{
|
||||
bool ret;
|
||||
wasm_module_inst_t module_inst =
|
||||
wasm_runtime_get_current_module_inst();
|
||||
union { uint64 u64; uint32 parts[2]; } inst;
|
||||
union { uint64 u64; uint32 parts[2]; } native_ptr;
|
||||
|
||||
@ -86,11 +83,10 @@ wasm_runtime_validate_native_addr_wrapper(uint32 inst_part0, uint32 inst_part1,
|
||||
}
|
||||
|
||||
static uint64
|
||||
wasm_runtime_addr_app_to_native_wrapper(uint32 inst_part0, uint32 inst_part1,
|
||||
wasm_runtime_addr_app_to_native_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 inst_part0, uint32 inst_part1,
|
||||
int32 app_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst =
|
||||
wasm_runtime_get_current_module_inst();
|
||||
union { uint64 u64; uint32 parts[2]; } inst;
|
||||
|
||||
inst.parts[0] = inst_part0;
|
||||
@ -105,12 +101,11 @@ wasm_runtime_addr_app_to_native_wrapper(uint32 inst_part0, uint32 inst_part1,
|
||||
}
|
||||
|
||||
static int32
|
||||
wasm_runtime_addr_native_to_app_wrapper(uint32 inst_part0, uint32 inst_part1,
|
||||
wasm_runtime_addr_native_to_app_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 inst_part0, uint32 inst_part1,
|
||||
uint32 native_ptr_part0,
|
||||
uint32 native_ptr_part1)
|
||||
{
|
||||
wasm_module_inst_t module_inst =
|
||||
wasm_runtime_get_current_module_inst();
|
||||
union { uint64 u64; uint32 parts[2]; } inst;
|
||||
union { uint64 u64; uint32 parts[2]; } native_ptr;
|
||||
|
||||
|
||||
@ -14,16 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_interface.h"
|
||||
#include "app_manager_export.h"
|
||||
#include "coap_ext.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
extern void module_request_handler(request_t *request, void *user_data);
|
||||
|
||||
bool wasm_response_send(int32 buffer_offset, int size)
|
||||
bool
|
||||
wasm_response_send(wasm_module_inst_t module_inst,
|
||||
int32 buffer_offset, int size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *buffer = NULL;
|
||||
|
||||
if (!validate_app_addr(buffer_offset, size))
|
||||
@ -45,9 +45,9 @@ bool wasm_response_send(int32 buffer_offset, int size)
|
||||
return false;
|
||||
}
|
||||
|
||||
void wasm_register_resource(int32 url_offset)
|
||||
void
|
||||
wasm_register_resource(wasm_module_inst_t module_inst, int32 url_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *url = NULL;
|
||||
|
||||
if (!validate_app_addr(url_offset, 1))
|
||||
@ -61,9 +61,10 @@ void wasm_register_resource(int32 url_offset)
|
||||
}
|
||||
}
|
||||
|
||||
void wasm_post_request(int32 buffer_offset, int size)
|
||||
void
|
||||
wasm_post_request(wasm_module_inst_t module_inst,
|
||||
int32 buffer_offset, int size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *buffer = NULL;
|
||||
|
||||
if (!validate_app_addr(buffer_offset, size))
|
||||
@ -92,9 +93,9 @@ void wasm_post_request(int32 buffer_offset, int size)
|
||||
}
|
||||
}
|
||||
|
||||
void wasm_sub_event(int32 url_offset)
|
||||
void
|
||||
wasm_sub_event(wasm_module_inst_t module_inst, int32 url_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *url = NULL;
|
||||
|
||||
if (!validate_app_addr(url_offset, 1))
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
#ifndef LIB_BASE_RUNTIME_LIB_H_
|
||||
#define LIB_BASE_RUNTIME_LIB_H_
|
||||
|
||||
#include "native_interface.h"
|
||||
|
||||
#include "runtime_timer.h"
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ void wasm_timer_callback(timer_id_t id, unsigned int mod_id)
|
||||
|
||||
// !!! the length parameter must be 0, so the receiver will
|
||||
// not free the payload pointer.
|
||||
bh_post_msg(module->queue, TIMER_EVENT_WASM, (char *) id, 0);
|
||||
bh_post_msg(module->queue, TIMER_EVENT_WASM, (char *)(uintptr_t)id, 0);
|
||||
}
|
||||
|
||||
///
|
||||
@ -149,30 +149,37 @@ timer_ctx_t get_wasm_timer_ctx()
|
||||
return m->timer_ctx;
|
||||
}
|
||||
|
||||
timer_id_t wasm_create_timer(int interval, bool is_period, bool auto_start)
|
||||
timer_id_t
|
||||
wasm_create_timer(wasm_module_inst_t module_inst,
|
||||
int interval, bool is_period, bool auto_start)
|
||||
{
|
||||
return sys_create_timer(get_wasm_timer_ctx(), interval, is_period,
|
||||
auto_start);
|
||||
}
|
||||
|
||||
void wasm_timer_destory(timer_id_t timer_id)
|
||||
void
|
||||
wasm_timer_destory(wasm_module_inst_t module_inst, timer_id_t timer_id)
|
||||
{
|
||||
sys_timer_destory(get_wasm_timer_ctx(), timer_id);
|
||||
}
|
||||
|
||||
void wasm_timer_cancel(timer_id_t timer_id)
|
||||
void
|
||||
wasm_timer_cancel(wasm_module_inst_t module_inst, timer_id_t timer_id)
|
||||
{
|
||||
sys_timer_cancel(get_wasm_timer_ctx(), timer_id);
|
||||
}
|
||||
|
||||
void wasm_timer_restart(timer_id_t timer_id, int interval)
|
||||
void
|
||||
wasm_timer_restart(wasm_module_inst_t module_inst,
|
||||
timer_id_t timer_id, int interval)
|
||||
{
|
||||
sys_timer_restart(get_wasm_timer_ctx(), timer_id, interval);
|
||||
}
|
||||
|
||||
extern uint32 get_sys_tick_ms();
|
||||
|
||||
uint32 wasm_get_sys_tick_ms(void)
|
||||
uint32
|
||||
wasm_get_sys_tick_ms(wasm_module_inst_t module_inst)
|
||||
{
|
||||
return (uint32) bh_get_tick_ms();
|
||||
}
|
||||
|
||||
@ -23,10 +23,10 @@
|
||||
* This file is the consumer of connection lib which is implemented by different platforms
|
||||
*/
|
||||
|
||||
|
||||
uint32 wasm_open_connection(int32 name_offset, int32 args_offset, uint32 len)
|
||||
uint32
|
||||
wasm_open_connection(wasm_module_inst_t module_inst,
|
||||
int32 name_offset, int32 args_offset, uint32 len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
attr_container_t *args;
|
||||
char *name, *args_buf;
|
||||
|
||||
@ -44,15 +44,17 @@ uint32 wasm_open_connection(int32 name_offset, int32 args_offset, uint32 len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void wasm_close_connection(uint32 handle)
|
||||
void
|
||||
wasm_close_connection(wasm_module_inst_t module_inst, uint32 handle)
|
||||
{
|
||||
if (connection_impl._close != NULL)
|
||||
connection_impl._close(handle);
|
||||
}
|
||||
|
||||
int wasm_send_on_connection(uint32 handle, int32 data_offset, uint32 len)
|
||||
int
|
||||
wasm_send_on_connection(wasm_module_inst_t module_inst,
|
||||
uint32 handle, int32 data_offset, uint32 len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *data;
|
||||
|
||||
if (!validate_app_addr(data_offset, len) ||
|
||||
@ -65,9 +67,10 @@ int wasm_send_on_connection(uint32 handle, int32 data_offset, uint32 len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool wasm_config_connection(uint32 handle, int32 cfg_offset, uint32 len)
|
||||
bool
|
||||
wasm_config_connection(wasm_module_inst_t module_inst,
|
||||
uint32 handle, int32 cfg_offset, uint32 len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *cfg_buf;
|
||||
attr_container_t *cfg;
|
||||
|
||||
|
||||
@ -45,7 +45,9 @@ static WGLNativeFuncDef btn_native_func_defs[] = {
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void wasm_btn_native_call(int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
void
|
||||
wasm_btn_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
uint32 size = sizeof(btn_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
|
||||
@ -61,7 +61,9 @@ static WGLNativeFuncDef cb_native_func_defs[] = {
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void wasm_cb_native_call(int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
void
|
||||
wasm_cb_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
uint32 size = sizeof(cb_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
|
||||
@ -60,7 +60,9 @@ static WGLNativeFuncDef label_native_func_defs[] = {
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void wasm_label_native_call(int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
void
|
||||
wasm_label_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
uint32 size = sizeof(label_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
|
||||
@ -51,7 +51,9 @@ static WGLNativeFuncDef list_native_func_defs[] = {
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void wasm_list_native_call(int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
void
|
||||
wasm_list_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
uint32 size = sizeof(list_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
|
||||
@ -341,7 +341,9 @@ static WGLNativeFuncDef obj_native_func_defs[] = {
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void wasm_obj_native_call(int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
void
|
||||
wasm_obj_native_call(wasm_module_inst_t module_inst,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
uint32 size = sizeof(obj_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
|
||||
@ -22,8 +22,10 @@
|
||||
|
||||
static sys_sensor_t * g_sys_sensors = NULL;
|
||||
static int g_sensor_id_max = 0;
|
||||
static sensor_client_t *find_sensor_client(sys_sensor_t * sensor,
|
||||
unsigned int client_id, bool remove_if_found);
|
||||
|
||||
static sensor_client_t *
|
||||
find_sensor_client(sys_sensor_t * sensor,
|
||||
unsigned int client_id, bool remove_if_found);
|
||||
|
||||
void (*rechedule_sensor_callback)() = NULL;
|
||||
|
||||
@ -32,7 +34,8 @@ void (*rechedule_sensor_callback)() = NULL;
|
||||
*
|
||||
*/
|
||||
|
||||
static void sensor_event_cleaner(sensor_event_data_t *sensor_event)
|
||||
static void
|
||||
sensor_event_cleaner(sensor_event_data_t *sensor_event)
|
||||
{
|
||||
if (sensor_event->data != NULL) {
|
||||
if (sensor_event->data_fmt == FMT_ATTR_CONTAINER)
|
||||
@ -44,8 +47,8 @@ static void sensor_event_cleaner(sensor_event_data_t *sensor_event)
|
||||
bh_free(sensor_event);
|
||||
}
|
||||
|
||||
static void wasm_sensor_callback(void *client, uint32 sensor_id,
|
||||
void *user_data)
|
||||
static void
|
||||
wasm_sensor_callback(void *client, uint32 sensor_id, void *user_data)
|
||||
{
|
||||
attr_container_t *sensor_data = (attr_container_t *) user_data;
|
||||
attr_container_t *sensor_data_clone;
|
||||
@ -92,7 +95,10 @@ static void wasm_sensor_callback(void *client, uint32 sensor_id,
|
||||
bh_post_msg2(module->queue, msg);
|
||||
}
|
||||
|
||||
bool wasm_sensor_config(uint32 sensor, int interval, int bit_cfg, int delay)
|
||||
bool
|
||||
wasm_sensor_config(wasm_module_inst_t module_inst,
|
||||
uint32 sensor, int interval,
|
||||
int bit_cfg, int delay)
|
||||
{
|
||||
attr_container_t * attr_cont;
|
||||
sensor_client_t * c;
|
||||
@ -132,9 +138,10 @@ bool wasm_sensor_config(uint32 sensor, int interval, int bit_cfg, int delay)
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32 wasm_sensor_open(int32 name_offset, int instance)
|
||||
uint32
|
||||
wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
int32 name_offset, int instance)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *name = NULL;
|
||||
|
||||
if (!validate_app_addr(name_offset, 1))
|
||||
@ -185,10 +192,11 @@ uint32 wasm_sensor_open(int32 name_offset, int instance)
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool wasm_sensor_config_with_attr_container(uint32 sensor, int32 buffer_offset,
|
||||
int len)
|
||||
bool
|
||||
wasm_sensor_config_with_attr_container(wasm_module_inst_t module_inst,
|
||||
uint32 sensor, int32 buffer_offset,
|
||||
int len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *buffer = NULL;
|
||||
|
||||
if (!validate_app_addr(buffer_offset, len))
|
||||
@ -211,7 +219,8 @@ bool wasm_sensor_config_with_attr_container(uint32 sensor, int32 buffer_offset,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wasm_sensor_close(uint32 sensor)
|
||||
bool
|
||||
wasm_sensor_close(wasm_module_inst_t module_inst, uint32 sensor)
|
||||
{
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App);
|
||||
unsigned int client_id = mod_id;
|
||||
@ -271,8 +280,9 @@ void refresh_read_interval(sensor_obj_t sensor)
|
||||
sensor->read_interval = interval;
|
||||
}
|
||||
|
||||
sensor_obj_t add_sys_sensor(char * name, char * description, int instance,
|
||||
uint32 default_interval, void * read_func, void * config_func)
|
||||
sensor_obj_t
|
||||
add_sys_sensor(char * name, char * description, int instance,
|
||||
uint32 default_interval, void * read_func, void * config_func)
|
||||
{
|
||||
sys_sensor_t * s = (sys_sensor_t *) bh_malloc(sizeof(sys_sensor_t));
|
||||
if (s == NULL)
|
||||
|
||||
@ -19,6 +19,8 @@
|
||||
|
||||
#include "bh_platform.h"
|
||||
#include "attr_container.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
struct _sys_sensor;
|
||||
typedef struct _sys_sensor* sensor_obj_t;
|
||||
|
||||
@ -60,16 +62,19 @@ int check_sensor_timers();
|
||||
void reschedule_sensor_read();
|
||||
|
||||
uint32
|
||||
wasm_sensor_open(int32 name_offset, int instance);
|
||||
wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
int32 name_offset, int instance);
|
||||
|
||||
bool
|
||||
wasm_sensor_config(uint32 sensor, int interval, int bit_cfg, int delay);
|
||||
wasm_sensor_config(wasm_module_inst_t module_inst,
|
||||
uint32 sensor, int interval, int bit_cfg, int delay);
|
||||
|
||||
bool
|
||||
wasm_sensor_config_with_attr_container(uint32 sensor, int32 buffer_offset,
|
||||
int len);
|
||||
wasm_sensor_config_with_attr_container(wasm_module_inst_t module_inst,
|
||||
uint32 sensor, int32 buffer_offset,
|
||||
int len);
|
||||
|
||||
bool
|
||||
wasm_sensor_close(uint32 sensor);
|
||||
wasm_sensor_close(wasm_module_inst_t module_inst, uint32 sensor);
|
||||
|
||||
#endif /* LIB_EXTENSION_RUNTIME_SENSOR_H_ */
|
||||
|
||||
@ -34,9 +34,6 @@ wasm_runtime_get_llvm_stack(wasm_module_inst_t module);
|
||||
void
|
||||
wasm_runtime_set_llvm_stack(wasm_module_inst_t module, uint32 llvm_stack);
|
||||
|
||||
#define get_module_inst() \
|
||||
wasm_runtime_get_current_module_inst()
|
||||
|
||||
#define validate_app_addr(offset, size) \
|
||||
wasm_runtime_validate_app_addr(module_inst, offset, size)
|
||||
|
||||
@ -454,9 +451,9 @@ parse_printf_args(wasm_module_inst_t module_inst, int32 fmt_offset,
|
||||
}
|
||||
|
||||
static int
|
||||
_printf_wrapper(int32 fmt_offset, int32 va_list_offset)
|
||||
_printf_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 fmt_offset, int32 va_list_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
struct str_context ctx = { NULL, 0, 0 };
|
||||
const char *fmt;
|
||||
_va_list va_args;
|
||||
@ -470,9 +467,9 @@ _printf_wrapper(int32 fmt_offset, int32 va_list_offset)
|
||||
}
|
||||
|
||||
static int
|
||||
_sprintf_wrapper(int32 str_offset, int32 fmt_offset, int32 va_list_offset)
|
||||
_sprintf_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 str_offset, int32 fmt_offset, int32 va_list_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
int32 app_end_offset;
|
||||
struct str_context ctx;
|
||||
char *str;
|
||||
@ -505,10 +502,10 @@ _sprintf_wrapper(int32 str_offset, int32 fmt_offset, int32 va_list_offset)
|
||||
}
|
||||
|
||||
static int
|
||||
_snprintf_wrapper(int32 str_offset, int32 size, int32 fmt_offset,
|
||||
_snprintf_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 str_offset, int32 size, int32 fmt_offset,
|
||||
int32 va_list_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
struct str_context ctx;
|
||||
char *str;
|
||||
const char *fmt;
|
||||
@ -537,9 +534,9 @@ _snprintf_wrapper(int32 str_offset, int32 size, int32 fmt_offset,
|
||||
}
|
||||
|
||||
static int
|
||||
_puts_wrapper(int32 str_offset)
|
||||
_puts_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 str_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
const char *str;
|
||||
|
||||
if (!validate_str_addr(module_inst, str_offset))
|
||||
@ -550,16 +547,16 @@ _puts_wrapper(int32 str_offset)
|
||||
}
|
||||
|
||||
static int
|
||||
_putchar_wrapper(int c)
|
||||
_putchar_wrapper(wasm_module_inst_t module_inst, int c)
|
||||
{
|
||||
bh_printf("%c", c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32
|
||||
_strdup_wrapper(int32 str_offset)
|
||||
_strdup_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 str_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *str, *str_ret;
|
||||
uint32 len;
|
||||
int32 str_ret_offset = 0;
|
||||
@ -583,9 +580,9 @@ _strdup_wrapper(int32 str_offset)
|
||||
}
|
||||
|
||||
static int32
|
||||
_memcmp_wrapper(int32 s1_offset, int32 s2_offset, int32 size)
|
||||
_memcmp_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 s1_offset, int32 s2_offset, int32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
void *s1, *s2;
|
||||
|
||||
if (!validate_app_addr(s1_offset, size)
|
||||
@ -598,9 +595,9 @@ _memcmp_wrapper(int32 s1_offset, int32 s2_offset, int32 size)
|
||||
}
|
||||
|
||||
static int32
|
||||
_memcpy_wrapper(int32 dst_offset, int32 src_offset, int32 size)
|
||||
_memcpy_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 dst_offset, int32 src_offset, int32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
void *dst, *src;
|
||||
|
||||
if (size == 0)
|
||||
@ -617,9 +614,9 @@ _memcpy_wrapper(int32 dst_offset, int32 src_offset, int32 size)
|
||||
}
|
||||
|
||||
static int32
|
||||
_memmove_wrapper(int32 dst_offset, int32 src_offset, int32 size)
|
||||
_memmove_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 dst_offset, int32 src_offset, int32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
void *dst, *src;
|
||||
|
||||
if (!validate_app_addr(dst_offset, size)
|
||||
@ -633,9 +630,9 @@ _memmove_wrapper(int32 dst_offset, int32 src_offset, int32 size)
|
||||
}
|
||||
|
||||
static int32
|
||||
_memset_wrapper(int32 s_offset, int32 c, int32 size)
|
||||
_memset_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 s_offset, int32 c, int32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
void *s;
|
||||
|
||||
if (!validate_app_addr(s_offset, size))
|
||||
@ -647,9 +644,9 @@ _memset_wrapper(int32 s_offset, int32 c, int32 size)
|
||||
}
|
||||
|
||||
static int32
|
||||
_strchr_wrapper(int32 s_offset, int32 c)
|
||||
_strchr_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 s_offset, int32 c)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
const char *s;
|
||||
char *ret;
|
||||
|
||||
@ -662,9 +659,9 @@ _strchr_wrapper(int32 s_offset, int32 c)
|
||||
}
|
||||
|
||||
static int32
|
||||
_strcmp_wrapper(int32 s1_offset, int32 s2_offset)
|
||||
_strcmp_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 s1_offset, int32 s2_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
void *s1, *s2;
|
||||
|
||||
if (!validate_str_addr(module_inst, s1_offset)
|
||||
@ -677,9 +674,9 @@ _strcmp_wrapper(int32 s1_offset, int32 s2_offset)
|
||||
}
|
||||
|
||||
static int32
|
||||
_strncmp_wrapper(int32 s1_offset, int32 s2_offset, uint32 size)
|
||||
_strncmp_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 s1_offset, int32 s2_offset, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
void *s1, *s2;
|
||||
|
||||
if (!validate_app_addr(s1_offset, size)
|
||||
@ -692,9 +689,9 @@ _strncmp_wrapper(int32 s1_offset, int32 s2_offset, uint32 size)
|
||||
}
|
||||
|
||||
static int32
|
||||
_strcpy_wrapper(int32 dst_offset, int32 src_offset)
|
||||
_strcpy_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 dst_offset, int32 src_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *dst, *src;
|
||||
uint32 len;
|
||||
|
||||
@ -713,9 +710,9 @@ _strcpy_wrapper(int32 dst_offset, int32 src_offset)
|
||||
}
|
||||
|
||||
static int32
|
||||
_strncpy_wrapper(int32 dst_offset, int32 src_offset, uint32 size)
|
||||
_strncpy_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 dst_offset, int32 src_offset, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *dst, *src;
|
||||
|
||||
if (!validate_app_addr(dst_offset, size)
|
||||
@ -729,9 +726,9 @@ _strncpy_wrapper(int32 dst_offset, int32 src_offset, uint32 size)
|
||||
}
|
||||
|
||||
static uint32
|
||||
_strlen_wrapper(int32 s_offset)
|
||||
_strlen_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 s_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char *s;
|
||||
|
||||
if (!validate_str_addr(module_inst, s_offset))
|
||||
@ -742,17 +739,17 @@ _strlen_wrapper(int32 s_offset)
|
||||
}
|
||||
|
||||
static int32
|
||||
_malloc_wrapper(uint32 size)
|
||||
_malloc_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
return module_malloc(size);
|
||||
}
|
||||
|
||||
static int32
|
||||
_calloc_wrapper(uint32 nmemb, uint32 size)
|
||||
_calloc_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 nmemb, uint32 size)
|
||||
{
|
||||
uint64 total_size = (uint64) nmemb * (uint64) size;
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
uint32 ret_offset = 0;
|
||||
uint8 *ret_ptr;
|
||||
|
||||
@ -769,31 +766,30 @@ _calloc_wrapper(uint32 nmemb, uint32 size)
|
||||
}
|
||||
|
||||
static void
|
||||
_free_wrapper(int32 ptr_offset)
|
||||
_free_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 ptr_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
|
||||
if (!validate_app_addr(ptr_offset, 4))
|
||||
return;
|
||||
return module_free(ptr_offset);
|
||||
}
|
||||
|
||||
static void
|
||||
setTempRet0_wrapper(uint32 temp_ret)
|
||||
setTempRet0_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 temp_ret)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
wasm_runtime_set_temp_ret(module_inst, temp_ret);
|
||||
}
|
||||
|
||||
static uint32
|
||||
getTempRet0_wrapper()
|
||||
getTempRet0_wrapper(wasm_module_inst_t module_inst)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
return wasm_runtime_get_temp_ret(module_inst);
|
||||
}
|
||||
|
||||
static uint32
|
||||
_llvm_bswap_i16_wrapper(uint32 data)
|
||||
_llvm_bswap_i16_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 data)
|
||||
{
|
||||
return (data & 0xFFFF0000)
|
||||
| ((data & 0xFF) << 8)
|
||||
@ -801,7 +797,8 @@ _llvm_bswap_i16_wrapper(uint32 data)
|
||||
}
|
||||
|
||||
static uint32
|
||||
_llvm_bswap_i32_wrapper(uint32 data)
|
||||
_llvm_bswap_i32_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 data)
|
||||
{
|
||||
return ((data & 0xFF) << 24)
|
||||
| ((data & 0xFF00) << 8)
|
||||
@ -810,10 +807,10 @@ _llvm_bswap_i32_wrapper(uint32 data)
|
||||
}
|
||||
|
||||
static uint32
|
||||
_bitshift64Lshr_wrapper(uint32 uint64_part0, uint32 uint64_part1,
|
||||
_bitshift64Lshr_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 uint64_part0, uint32 uint64_part1,
|
||||
uint32 bits)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
union {
|
||||
uint64 value;
|
||||
uint32 parts[2];
|
||||
@ -829,10 +826,10 @@ _bitshift64Lshr_wrapper(uint32 uint64_part0, uint32 uint64_part1,
|
||||
}
|
||||
|
||||
static uint32
|
||||
_bitshift64Shl_wrapper(uint32 int64_part0, uint32 int64_part1,
|
||||
_bitshift64Shl_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 int64_part0, uint32 int64_part1,
|
||||
uint32 bits)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
union {
|
||||
int64 value;
|
||||
uint32 parts[2];
|
||||
@ -848,26 +845,25 @@ _bitshift64Shl_wrapper(uint32 int64_part0, uint32 int64_part1,
|
||||
}
|
||||
|
||||
static void
|
||||
_llvm_stackrestore_wrapper(uint32 llvm_stack)
|
||||
_llvm_stackrestore_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 llvm_stack)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
bh_printf("_llvm_stackrestore called!\n");
|
||||
wasm_runtime_set_llvm_stack(module_inst, llvm_stack);
|
||||
}
|
||||
|
||||
static uint32
|
||||
_llvm_stacksave_wrapper()
|
||||
_llvm_stacksave_wrapper(wasm_module_inst_t module_inst)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
bh_printf("_llvm_stacksave called!\n");
|
||||
return wasm_runtime_get_llvm_stack(module_inst);
|
||||
}
|
||||
|
||||
static int32
|
||||
_emscripten_memcpy_big_wrapper(int32 dst_offset, int32 src_offset,
|
||||
_emscripten_memcpy_big_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 dst_offset, int32 src_offset,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
void *dst, *src;
|
||||
|
||||
if (!validate_app_addr(dst_offset, size)
|
||||
@ -882,27 +878,27 @@ _emscripten_memcpy_big_wrapper(int32 dst_offset, int32 src_offset,
|
||||
}
|
||||
|
||||
static void
|
||||
abort_wrapper(int32 code)
|
||||
abort_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 code)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "env.abort(%i)", code);
|
||||
wasm_runtime_set_exception(module_inst, buf);
|
||||
}
|
||||
|
||||
static void
|
||||
abortStackOverflow_wrapper(int32 code)
|
||||
abortStackOverflow_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 code)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "env.abortStackOverflow(%i)", code);
|
||||
wasm_runtime_set_exception(module_inst, buf);
|
||||
}
|
||||
|
||||
static void
|
||||
nullFunc_X_wrapper(int32 code)
|
||||
nullFunc_X_wrapper(wasm_module_inst_t module_inst,
|
||||
int32 code)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst();
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "env.nullFunc_X(%i)", code);
|
||||
wasm_runtime_set_exception(module_inst, buf);
|
||||
@ -912,13 +908,13 @@ nullFunc_X_wrapper(int32 code)
|
||||
|
||||
#ifdef ENABLE_SPEC_TEST
|
||||
static void
|
||||
print_i32_wrapper(int i32)
|
||||
print_i32_wrapper(wasm_module_inst_t module_inst, int i32)
|
||||
{
|
||||
bh_printf("%d\n", i32);
|
||||
}
|
||||
|
||||
static void
|
||||
print_wrapper(int i32)
|
||||
print_wrapper(wasm_module_inst_t module_inst, int i32)
|
||||
{
|
||||
bh_printf("%d\n", i32);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user