Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent * Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default * Add a new extension library: connection * Fix bug of reading magic number and version in big endian platform * Re-org platform APIs: move most platform APIs from iwasm to shared-lib * Enhance wasm loader to fix some security issues * Fix issue about illegal load of EXC_RETURN into PC on stm32 board * Updates that let a restricted version of the interpreter run in SGX * Enable native/app address validation and conversion for wasm app * Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused * Refine binary size and fix several minor issues Optimize interpreter LOAD/STORE opcodes to decrease the binary size Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper Add macros of global heap size, stack size, heap size for Zephyr main.c Clear compile warning of wasm_application.c * Add more strict security checks for libc wrapper API's * Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files * Enhance security of libc strcpy/sprintf wrapper function * Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions * Remove get_module_inst() and fix issue of call native * Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate * Refine interpreter call native process, refine memory boudary check * Fix issues of invokeNative function of arm/mips/general version * Add a switch to build simple sample without gui support * Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code * Re-org shared lib header files, remove unused info; fix compile issues of vxworks * Add build target general * Remove unused files * Update license header * test push * Restore file * Sync up with internal/feature * Sync up with internal/feature * Rename build_wamr_app to build_wasm_app * Fix small issues of README * Enhance malformed wasm file checking Fix issue of print hex int and implement utf8 string check Fix wasi file read/write right issue Fix minor issue of build wasm app doc * Sync up with internal/feature * Sync up with internal/feature: fix interpreter arm issue, fix read leb issue * Sync up with internal/feature * Fix bug of config.h and rename wasi config.h to ssp_config.h * Sync up with internal/feature * Import wamr aot * update document * update document * Update document, disable WASI in 32bit * update document * remove files * update document * Update document * update document * update document * update samples * Sync up with internal repo
This commit is contained in:
11
core/app-framework/app-native-shared/README.md
Normal file
11
core/app-framework/app-native-shared/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
Notes:
|
||||
=======
|
||||
This folder is for the source files shared by both WASM APP and native runtime
|
||||
|
||||
- The c files in this directory are compiled into both the WASM APP and runtime.
|
||||
- The header files for distributing to SDK are placed in the "bi-inc" folder.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "attr_container.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
|
||||
typedef union jvalue {
|
||||
bool z;
|
||||
@ -145,9 +145,7 @@ unpack_response(char * packet, int size, response_t * response);
|
||||
void
|
||||
free_req_resp_packet(char * packet);
|
||||
|
||||
#if WASM_ENABLE_GUI != 0
|
||||
#include "wgl_shared_utils.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -6,15 +6,19 @@
|
||||
#ifndef WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H
|
||||
#define WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../3rdparty/lv_conf.h"
|
||||
#include "lv_conf.h"
|
||||
|
||||
typedef lv_coord_t wgl_coord_t; /* lv_coord_t is defined in lv_conf.h */
|
||||
typedef void * wgl_font_user_data_t;
|
||||
|
||||
/**
|
||||
* Represents a point on the screen.
|
||||
@ -10,3 +10,6 @@ file (GLOB_RECURSE source_all ${NATIVE_INTERFACE_DIR}/*.c)
|
||||
|
||||
set (NATIVE_INTERFACE_SOURCE ${source_all})
|
||||
|
||||
set (WASM_APP_BI_INC_DIR "${NATIVE_INTERFACE_DIR}/bi-inc")
|
||||
LIST (APPEND RUNTIME_LIB_HEADER_LIST "${NATIVE_INTERFACE_DIR}/native_interface.h")
|
||||
|
||||
@ -11,6 +11,9 @@
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#define get_module_inst(exec_env) \
|
||||
wasm_runtime_get_module_inst(exec_env)
|
||||
|
||||
#define validate_app_addr(offset, size) \
|
||||
wasm_runtime_validate_app_addr(module_inst, offset, size)
|
||||
|
||||
@ -36,16 +39,16 @@
|
||||
*/
|
||||
|
||||
bool
|
||||
wasm_response_send(wasm_module_inst_t module_inst,
|
||||
wasm_response_send(wasm_exec_env_t exec_env,
|
||||
int32 buffer_offset, int size);
|
||||
void
|
||||
wasm_register_resource(wasm_module_inst_t module_inst,
|
||||
wasm_register_resource(wasm_exec_env_t exec_env,
|
||||
int32 url_offset);
|
||||
void
|
||||
wasm_post_request(wasm_module_inst_t module_inst,
|
||||
wasm_post_request(wasm_exec_env_t exec_env,
|
||||
int32 buffer_offset, int size);
|
||||
void
|
||||
wasm_sub_event(wasm_module_inst_t module_inst,
|
||||
wasm_sub_event(wasm_exec_env_t exec_env,
|
||||
int32 url_offset);
|
||||
|
||||
/*
|
||||
@ -53,17 +56,17 @@ wasm_sub_event(wasm_module_inst_t module_inst,
|
||||
*/
|
||||
|
||||
bool
|
||||
wasm_sensor_config(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_config(wasm_exec_env_t exec_env,
|
||||
uint32 sensor, int interval, int bit_cfg, int delay);
|
||||
uint32
|
||||
wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_open(wasm_exec_env_t exec_env,
|
||||
int32 name_offset, int instance);
|
||||
bool
|
||||
wasm_sensor_config_with_attr_container(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_config_with_attr_container(wasm_exec_env_t exec_env,
|
||||
uint32 sensor,
|
||||
int32 buffer_offset, int len);
|
||||
bool
|
||||
wasm_sensor_close(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_close(wasm_exec_env_t exec_env,
|
||||
uint32 sensor);
|
||||
|
||||
/*
|
||||
@ -73,33 +76,33 @@ wasm_sensor_close(wasm_module_inst_t module_inst,
|
||||
typedef unsigned int timer_id_t;
|
||||
|
||||
timer_id_t
|
||||
wasm_create_timer(wasm_module_inst_t module_inst,
|
||||
wasm_create_timer(wasm_exec_env_t exec_env,
|
||||
int interval, bool is_period, bool auto_start);
|
||||
void
|
||||
wasm_timer_destroy(wasm_module_inst_t module_inst, timer_id_t timer_id);
|
||||
wasm_timer_destroy(wasm_exec_env_t exec_env, timer_id_t timer_id);
|
||||
void
|
||||
wasm_timer_cancel(wasm_module_inst_t module_inst, timer_id_t timer_id);
|
||||
wasm_timer_cancel(wasm_exec_env_t exec_env, timer_id_t timer_id);
|
||||
void
|
||||
wasm_timer_restart(wasm_module_inst_t module_inst,
|
||||
wasm_timer_restart(wasm_exec_env_t exec_env,
|
||||
timer_id_t timer_id, int interval);
|
||||
uint32
|
||||
wasm_get_sys_tick_ms(wasm_module_inst_t module_inst);
|
||||
wasm_get_sys_tick_ms(wasm_exec_env_t exec_env);
|
||||
|
||||
/*
|
||||
* connection interfaces
|
||||
*/
|
||||
|
||||
uint32
|
||||
wasm_open_connection(wasm_module_inst_t module_inst,
|
||||
wasm_open_connection(wasm_exec_env_t exec_env,
|
||||
int32 name_offset, int32 args_offset, uint32 len);
|
||||
void
|
||||
wasm_close_connection(wasm_module_inst_t module_inst,
|
||||
wasm_close_connection(wasm_exec_env_t exec_env,
|
||||
uint32 handle);
|
||||
int
|
||||
wasm_send_on_connection(wasm_module_inst_t module_inst,
|
||||
wasm_send_on_connection(wasm_exec_env_t exec_env,
|
||||
uint32 handle, int32 data_offset, uint32 len);
|
||||
bool
|
||||
wasm_config_connection(wasm_module_inst_t module_inst,
|
||||
wasm_config_connection(wasm_exec_env_t exec_env,
|
||||
uint32 handle, int32 cfg_offset, uint32 len);
|
||||
|
||||
/**
|
||||
@ -107,23 +110,23 @@ wasm_config_connection(wasm_module_inst_t module_inst,
|
||||
*/
|
||||
|
||||
void
|
||||
wasm_obj_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_obj_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_btn_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_btn_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_label_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_label_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_cb_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_cb_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_list_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_list_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc);
|
||||
|
||||
#endif /* end of _NATIVE_INTERFACE_H */
|
||||
@ -8,7 +8,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "shared_utils.h"
|
||||
#include "bi-inc/shared_utils.h"
|
||||
|
||||
/* Serialization of request and response message
|
||||
*
|
||||
86
core/app-framework/app_framework.cmake
Normal file
86
core/app-framework/app_framework.cmake
Normal file
@ -0,0 +1,86 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (APP_FRAMEWORK_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# app-native-shared and base are required
|
||||
include (${APP_FRAMEWORK_ROOT_DIR}/app-native-shared/native_interface.cmake)
|
||||
LIST (APPEND WASM_APP_SOURCE_ALL ${NATIVE_INTERFACE_SOURCE})
|
||||
|
||||
MACRO(SUBDIRLIST result curdir)
|
||||
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
||||
SET(dirlist "")
|
||||
FOREACH(child ${children})
|
||||
IF(IS_DIRECTORY ${curdir}/${child})
|
||||
LIST(APPEND dirlist ${child})
|
||||
ENDIF()
|
||||
ENDFOREACH()
|
||||
SET(${result} ${dirlist})
|
||||
ENDMACRO()
|
||||
|
||||
function (add_module_native arg)
|
||||
message ("Add native module ${ARGV0}")
|
||||
include (${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native/wasm_lib.cmake)
|
||||
|
||||
file (GLOB header
|
||||
${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native/*.h
|
||||
${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native/*.inl
|
||||
)
|
||||
LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})
|
||||
set (RUNTIME_LIB_HEADER_LIST ${RUNTIME_LIB_HEADER_LIST} PARENT_SCOPE)
|
||||
|
||||
LIST (APPEND WASM_APP_LIB_SOURCE_ALL ${WASM_APP_LIB_CURRENT_SOURCE})
|
||||
set (WASM_APP_LIB_SOURCE_ALL ${WASM_APP_LIB_SOURCE_ALL} PARENT_SCOPE)
|
||||
|
||||
# VARIABLES in function are only used in this scope,
|
||||
# set PARENT_SCOPE to pass to top CMakeLists
|
||||
set (WASM_LIB_BASE_SOURCE ${WASM_LIB_BASE_SOURCE} PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
function (add_module_app arg)
|
||||
message ("Add app module ${ARGV0}")
|
||||
include (${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/app/wasm_app.cmake)
|
||||
|
||||
LIST (APPEND WASM_APP_WA_INC_DIR_LIST "${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/app/wa-inc")
|
||||
set (WASM_APP_WA_INC_DIR_LIST ${WASM_APP_WA_INC_DIR_LIST} PARENT_SCOPE)
|
||||
|
||||
LIST (APPEND WASM_APP_NAME ${ARGV0})
|
||||
set (WASM_APP_NAME ${WASM_APP_NAME} PARENT_SCOPE)
|
||||
|
||||
LIST (APPEND WASM_APP_SOURCE_ALL ${WASM_APP_CURRENT_SOURCE})
|
||||
set (WASM_APP_SOURCE_ALL ${WASM_APP_SOURCE_ALL} PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
if ("${WAMR_BUILD_APP_LIST}" STREQUAL "WAMR_APP_BUILD_ALL")
|
||||
# add all modules under this folder
|
||||
SUBDIRLIST(SUBDIRS ${APP_FRAMEWORK_ROOT_DIR})
|
||||
|
||||
FOREACH(subdir ${SUBDIRS})
|
||||
if ("${subdir}" STREQUAL "app-native-shared")
|
||||
continue()
|
||||
endif ()
|
||||
if ("${subdir}" STREQUAL "template")
|
||||
continue()
|
||||
endif ()
|
||||
|
||||
if ( NOT DEFINED APP_FRAMEWORK_INCLUDE_TYPE )
|
||||
add_module_native (${subdir})
|
||||
else ()
|
||||
add_module_app (${subdir})
|
||||
endif ()
|
||||
ENDFOREACH()
|
||||
|
||||
else ()
|
||||
# add each module in the list
|
||||
FOREACH (dir IN LISTS WAMR_BUILD_APP_LIST)
|
||||
string(REPLACE "WAMR_APP_BUILD_" "" dir ${dir})
|
||||
string(TOLOWER ${dir} dir)
|
||||
|
||||
if ( NOT DEFINED APP_FRAMEWORK_INCLUDE_TYPE )
|
||||
add_module_native (${dir})
|
||||
else ()
|
||||
add_module_app (${dir})
|
||||
endif ()
|
||||
ENDFOREACH (dir)
|
||||
|
||||
endif()
|
||||
@ -3,9 +3,10 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "attr_container.h"
|
||||
#include "request.h"
|
||||
#include "shared_utils.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "wa-inc/request.h"
|
||||
#include "wa-inc/timer_wasm_app.h"
|
||||
#include "bi-inc/shared_utils.h"
|
||||
#include "wasm_app.h"
|
||||
#include "req_resp_api.h"
|
||||
#include "timer_api.h"
|
||||
@ -6,7 +6,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "timer_wasm_app.h"
|
||||
#include "wa-inc/timer_wasm_app.h"
|
||||
#include "timer_api.h"
|
||||
|
||||
#if 1
|
||||
@ -6,12 +6,59 @@
|
||||
#ifndef _AEE_REQUEST_H_
|
||||
#define _AEE_REQUEST_H_
|
||||
|
||||
#include "shared_utils.h"
|
||||
#include "bi-inc/shared_utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* CoAP request method codes */
|
||||
typedef enum {
|
||||
COAP_GET = 1,
|
||||
COAP_POST,
|
||||
COAP_PUT,
|
||||
COAP_DELETE,
|
||||
COAP_EVENT = (COAP_DELETE + 2)
|
||||
} coap_method_t;
|
||||
|
||||
/* CoAP response codes */
|
||||
typedef enum {
|
||||
NO_ERROR = 0,
|
||||
|
||||
CREATED_2_01 = 65, /* CREATED */
|
||||
DELETED_2_02 = 66, /* DELETED */
|
||||
VALID_2_03 = 67, /* NOT_MODIFIED */
|
||||
CHANGED_2_04 = 68, /* CHANGED */
|
||||
CONTENT_2_05 = 69, /* OK */
|
||||
CONTINUE_2_31 = 95, /* CONTINUE */
|
||||
|
||||
BAD_REQUEST_4_00 = 128, /* BAD_REQUEST */
|
||||
UNAUTHORIZED_4_01 = 129, /* UNAUTHORIZED */
|
||||
BAD_OPTION_4_02 = 130, /* BAD_OPTION */
|
||||
FORBIDDEN_4_03 = 131, /* FORBIDDEN */
|
||||
NOT_FOUND_4_04 = 132, /* NOT_FOUND */
|
||||
METHOD_NOT_ALLOWED_4_05 = 133, /* METHOD_NOT_ALLOWED */
|
||||
NOT_ACCEPTABLE_4_06 = 134, /* NOT_ACCEPTABLE */
|
||||
PRECONDITION_FAILED_4_12 = 140, /* BAD_REQUEST */
|
||||
REQUEST_ENTITY_TOO_LARGE_4_13 = 141, /* REQUEST_ENTITY_TOO_LARGE */
|
||||
UNSUPPORTED_MEDIA_TYPE_4_15 = 143, /* UNSUPPORTED_MEDIA_TYPE */
|
||||
|
||||
INTERNAL_SERVER_ERROR_5_00 = 160, /* INTERNAL_SERVER_ERROR */
|
||||
NOT_IMPLEMENTED_5_01 = 161, /* NOT_IMPLEMENTED */
|
||||
BAD_GATEWAY_5_02 = 162, /* BAD_GATEWAY */
|
||||
SERVICE_UNAVAILABLE_5_03 = 163, /* SERVICE_UNAVAILABLE */
|
||||
GATEWAY_TIMEOUT_5_04 = 164, /* GATEWAY_TIMEOUT */
|
||||
PROXYING_NOT_SUPPORTED_5_05 = 165, /* PROXYING_NOT_SUPPORTED */
|
||||
|
||||
/* Erbium errors */
|
||||
MEMORY_ALLOCATION_ERROR = 192, PACKET_SERIALIZATION_ERROR,
|
||||
|
||||
/* Erbium hooks */
|
||||
MANUAL_RESPONSE, PING_RESPONSE
|
||||
} coap_status_t;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef request_handler_f
|
||||
*
|
||||
13
core/app-framework/base/app/wasm_app.cmake
Normal file
13
core/app-framework/base/app/wasm_app.cmake
Normal file
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_APP_BASE_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(${WASM_APP_BASE_DIR})
|
||||
|
||||
add_definitions (-DWASM_ENABLE_BASE_LIB)
|
||||
|
||||
file (GLOB_RECURSE source_all ${WASM_APP_BASE_DIR}/*.c)
|
||||
|
||||
set (WASM_APP_CURRENT_SOURCE ${source_all})
|
||||
set (WASM_APP_BASE_DIR ${WASM_APP_BASE_DIR} PARENT_SCOPE)
|
||||
@ -3,19 +3,19 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _WASM_DLFCN_H
|
||||
#define _WASM_DLFCN_H
|
||||
#ifndef _LIB_AEE_H_
|
||||
#define _LIB_AEE_H_
|
||||
|
||||
#include "bi-inc/shared_utils.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void *
|
||||
wasm_dlsym(void *handle, const char *symbol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _WASM_DLFCN_H */
|
||||
|
||||
#endif /* end of _LIB_AEE_H_ */
|
||||
@ -7,16 +7,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "lib_export.h"
|
||||
|
||||
#ifdef WASM_ENABLE_BASE_LIB
|
||||
#include "base_lib_export.h"
|
||||
#endif
|
||||
|
||||
static NativeSymbol extended_native_symbol_defs[] = {
|
||||
/* TODO: use macro EXPORT_WASM_API() or EXPORT_WASM_API2() to
|
||||
add functions to register. */
|
||||
|
||||
#ifdef WASM_ENABLE_BASE_LIB
|
||||
EXPORT_WASM_API(wasm_register_resource),
|
||||
EXPORT_WASM_API(wasm_response_send),
|
||||
EXPORT_WASM_API(wasm_post_request),
|
||||
@ -26,7 +21,6 @@ static NativeSymbol extended_native_symbol_defs[] = {
|
||||
EXPORT_WASM_API(wasm_timer_cancel),
|
||||
EXPORT_WASM_API(wasm_timer_restart),
|
||||
EXPORT_WASM_API(wasm_get_sys_tick_ms),
|
||||
#endif
|
||||
};
|
||||
|
||||
int get_base_lib_export_apis(NativeSymbol **p_base_lib_apis)
|
||||
@ -6,7 +6,7 @@
|
||||
#ifndef _BASE_LIB_EXPORT_H_
|
||||
#define _BASE_LIB_EXPORT_H_
|
||||
|
||||
#include "attr_container.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "native_interface.h"
|
||||
|
||||
#endif /* end of _BASE_LIB_EXPORT_H_ */
|
||||
32
core/app-framework/base/native/req_resp_api.h
Normal file
32
core/app-framework/base/native/req_resp_api.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _REQ_RESP_API_H_
|
||||
#define _REQ_RESP_API_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool
|
||||
wasm_response_send(int32 buf_offset, int size);
|
||||
|
||||
void
|
||||
wasm_register_resource(int32 url_offset);
|
||||
|
||||
void
|
||||
wasm_post_request(int32 buf_offset, int size);
|
||||
|
||||
void
|
||||
wasm_sub_event(int32 url_offset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _REQ_RESP_API_H_ */
|
||||
|
||||
@ -11,9 +11,10 @@
|
||||
extern void module_request_handler(request_t *request, void *user_data);
|
||||
|
||||
bool
|
||||
wasm_response_send(wasm_module_inst_t module_inst,
|
||||
wasm_response_send(wasm_exec_env_t exec_env,
|
||||
int32 buffer_offset, int size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *buffer = NULL;
|
||||
|
||||
if (!validate_app_addr(buffer_offset, size))
|
||||
@ -36,8 +37,9 @@ wasm_response_send(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
void
|
||||
wasm_register_resource(wasm_module_inst_t module_inst, int32 url_offset)
|
||||
wasm_register_resource(wasm_exec_env_t exec_env, int32 url_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *url = NULL;
|
||||
|
||||
if (!validate_app_str_addr(url_offset))
|
||||
@ -54,9 +56,10 @@ wasm_register_resource(wasm_module_inst_t module_inst, int32 url_offset)
|
||||
}
|
||||
|
||||
void
|
||||
wasm_post_request(wasm_module_inst_t module_inst,
|
||||
wasm_post_request(wasm_exec_env_t exec_env,
|
||||
int32 buffer_offset, int size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *buffer = NULL;
|
||||
|
||||
if (!validate_app_addr(buffer_offset, size))
|
||||
@ -88,8 +91,9 @@ wasm_post_request(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
void
|
||||
wasm_sub_event(wasm_module_inst_t module_inst, int32 url_offset)
|
||||
wasm_sub_event(wasm_exec_env_t exec_env, int32 url_offset)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *url = NULL;
|
||||
|
||||
if (!validate_app_str_addr(url_offset))
|
||||
37
core/app-framework/base/native/timer_api.h
Normal file
37
core/app-framework/base/native/timer_api.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#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_destroy(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_ */
|
||||
|
||||
@ -149,34 +149,38 @@ timer_ctx_t get_wasm_timer_ctx(wasm_module_inst_t module_inst)
|
||||
}
|
||||
|
||||
timer_id_t
|
||||
wasm_create_timer(wasm_module_inst_t module_inst,
|
||||
wasm_create_timer(wasm_exec_env_t exec_env,
|
||||
int interval, bool is_period, bool auto_start)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
|
||||
bh_assert(timer_ctx);
|
||||
return sys_create_timer(timer_ctx, interval, is_period, auto_start);
|
||||
}
|
||||
|
||||
void
|
||||
wasm_timer_destroy(wasm_module_inst_t module_inst, timer_id_t timer_id)
|
||||
wasm_timer_destroy(wasm_exec_env_t exec_env, timer_id_t timer_id)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
|
||||
bh_assert(timer_ctx);
|
||||
sys_timer_destroy(timer_ctx, timer_id);
|
||||
}
|
||||
|
||||
void
|
||||
wasm_timer_cancel(wasm_module_inst_t module_inst, timer_id_t timer_id)
|
||||
wasm_timer_cancel(wasm_exec_env_t exec_env, timer_id_t timer_id)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
|
||||
bh_assert(timer_ctx);
|
||||
sys_timer_cancel(timer_ctx, timer_id);
|
||||
}
|
||||
|
||||
void
|
||||
wasm_timer_restart(wasm_module_inst_t module_inst,
|
||||
wasm_timer_restart(wasm_exec_env_t exec_env,
|
||||
timer_id_t timer_id, int interval)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
|
||||
bh_assert(timer_ctx);
|
||||
sys_timer_restart(timer_ctx, timer_id, interval);
|
||||
@ -185,7 +189,7 @@ wasm_timer_restart(wasm_module_inst_t module_inst,
|
||||
extern uint32 get_sys_tick_ms();
|
||||
|
||||
uint32
|
||||
wasm_get_sys_tick_ms(wasm_module_inst_t module_inst)
|
||||
wasm_get_sys_tick_ms(wasm_exec_env_t exec_env)
|
||||
{
|
||||
return (uint32) bh_get_tick_ms();
|
||||
}
|
||||
@ -3,10 +3,11 @@
|
||||
|
||||
set (WASM_LIB_BASE_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(${WASM_LIB_BASE_DIR})
|
||||
add_definitions (-DWASM_ENABLE_BASE_LIB)
|
||||
|
||||
include_directories(${WASM_LIB_BASE_DIR})
|
||||
|
||||
file (GLOB_RECURSE source_all ${WASM_LIB_BASE_DIR}/*.c)
|
||||
|
||||
set (WASM_LIB_BASE_SOURCE ${source_all})
|
||||
set (WASM_APP_LIB_CURRENT_SOURCE ${source_all})
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "connection.h"
|
||||
#include "wa-inc/connection.h"
|
||||
#include "connection_api.h"
|
||||
|
||||
/* Raw connection structure */
|
||||
@ -6,7 +6,7 @@
|
||||
#ifndef _CONNECTION_H_
|
||||
#define _CONNECTION_H_
|
||||
|
||||
#include "attr_container.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
11
core/app-framework/connection/app/wasm_app.cmake
Normal file
11
core/app-framework/connection/app/wasm_app.cmake
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_APP_CONN_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(${WASM_APP_CONN_DIR})
|
||||
|
||||
|
||||
file (GLOB source_all ${WASM_APP_CONN_DIR}/*.c)
|
||||
|
||||
set (WASM_APP_CURRENT_SOURCE ${source_all})
|
||||
32
core/app-framework/connection/native/connection_api.h
Normal file
32
core/app-framework/connection/native/connection_api.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#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_buf_offset, uint32 args_buf_len);
|
||||
|
||||
void
|
||||
wasm_close_connection(uint32 handle);
|
||||
|
||||
int
|
||||
wasm_send_on_connection(uint32 handle, int32 data_offset, uint32 data_len);
|
||||
|
||||
bool
|
||||
wasm_config_connection(uint32 handle, int32 cfg_buf_offset, uint32 cfg_buf_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* end of CONNECTION_API_H_ */
|
||||
@ -6,7 +6,7 @@
|
||||
#ifndef CONNECTION_LIB_H_
|
||||
#define CONNECTION_LIB_H_
|
||||
|
||||
#include "attr_container.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -13,9 +13,10 @@
|
||||
*/
|
||||
|
||||
uint32
|
||||
wasm_open_connection(wasm_module_inst_t module_inst,
|
||||
wasm_open_connection(wasm_exec_env_t exec_env,
|
||||
int32 name_offset, int32 args_offset, uint32 len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
attr_container_t *args;
|
||||
char *name, *args_buf;
|
||||
|
||||
@ -34,16 +35,17 @@ wasm_open_connection(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
void
|
||||
wasm_close_connection(wasm_module_inst_t module_inst, uint32 handle)
|
||||
wasm_close_connection(wasm_exec_env_t exec_env, uint32 handle)
|
||||
{
|
||||
if (connection_impl._close != NULL)
|
||||
connection_impl._close(handle);
|
||||
}
|
||||
|
||||
int
|
||||
wasm_send_on_connection(wasm_module_inst_t module_inst,
|
||||
wasm_send_on_connection(wasm_exec_env_t exec_env,
|
||||
uint32 handle, int32 data_offset, uint32 len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *data;
|
||||
|
||||
if (!validate_app_addr(data_offset, len) ||
|
||||
@ -57,9 +59,10 @@ wasm_send_on_connection(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_config_connection(wasm_module_inst_t module_inst,
|
||||
wasm_config_connection(wasm_exec_env_t exec_env,
|
||||
uint32 handle, int32 cfg_offset, uint32 len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *cfg_buf;
|
||||
attr_container_t *cfg;
|
||||
|
||||
@ -480,7 +480,7 @@ void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
|
||||
uint32 argv[3];
|
||||
wasm_function_inst_t func_on_conn_data;
|
||||
bh_assert(CONNECTION_EVENT_WASM == bh_message_type(msg));
|
||||
wasm_data *wasm_app_data = (wasm_data*) m_data->internal_data;
|
||||
wasm_data *wasm_app_data = (wasm_data*)m_data->internal_data;
|
||||
wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
|
||||
connection_event_t *conn_event
|
||||
= (connection_event_t *)bh_message_payload(msg);
|
||||
@ -490,9 +490,12 @@ void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
|
||||
return;
|
||||
|
||||
func_on_conn_data = wasm_runtime_lookup_function(inst, "_on_connection_data",
|
||||
"(i32i32i32)");
|
||||
"(i32i32i32)");
|
||||
if (!func_on_conn_data)
|
||||
func_on_conn_data = wasm_runtime_lookup_function(inst, "on_connection_data",
|
||||
"(i32i32i32)");
|
||||
if (!func_on_conn_data) {
|
||||
printf("Cannot find function _on_connection_data\n");
|
||||
printf("Cannot find function on_connection_data\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -501,7 +504,8 @@ void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
|
||||
argv[0] = conn_event->handle;
|
||||
argv[1] = 0;
|
||||
argv[2] = 0;
|
||||
if (!wasm_runtime_call_wasm(inst, NULL, func_on_conn_data, 3, argv)) {
|
||||
if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_on_conn_data,
|
||||
3, argv)) {
|
||||
const char *exception = wasm_runtime_get_exception(inst);
|
||||
bh_assert(exception);
|
||||
printf(":Got exception running wasm code: %s\n",
|
||||
@ -526,7 +530,8 @@ void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
|
||||
argv[0] = conn_event->handle;
|
||||
argv[1] = (uint32) data_offset;
|
||||
argv[2] = conn_event->len;
|
||||
if (!wasm_runtime_call_wasm(inst, NULL, func_on_conn_data, 3, argv)) {
|
||||
if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_on_conn_data,
|
||||
3, argv)) {
|
||||
const char *exception = wasm_runtime_get_exception(inst);
|
||||
bh_assert(exception);
|
||||
printf(":Got exception running wasm code: %s\n",
|
||||
@ -5,8 +5,11 @@ set (WASM_LIB_CONN_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(${WASM_LIB_CONN_DIR})
|
||||
|
||||
include (${CMAKE_CURRENT_LIST_DIR}/${WAMR_BUILD_PLATFORM}/connection_mgr.cmake)
|
||||
|
||||
file (GLOB source_all ${WASM_LIB_CONN_DIR}/*.c)
|
||||
|
||||
set (WASM_LIB_CONN_SOURCE ${source_all})
|
||||
file (GLOB source_all
|
||||
${WASM_LIB_CONN_MGR_SOURCE}
|
||||
${WASM_LIB_CONN_DIR}/*.c
|
||||
)
|
||||
|
||||
set (WASM_APP_LIB_CURRENT_SOURCE ${source_all})
|
||||
@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "sensor.h"
|
||||
#include "wa-inc/sensor.h"
|
||||
#include "sensor_api.h"
|
||||
|
||||
typedef struct _sensor {
|
||||
@ -6,7 +6,7 @@
|
||||
#ifndef _AEE_SENSOR_H_
|
||||
#define _AEE_SENSOR_H_
|
||||
|
||||
#include "attr_container.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
11
core/app-framework/sensor/app/wasm_app.cmake
Normal file
11
core/app-framework/sensor/app/wasm_app.cmake
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_APP_SENSOR_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(${WASM_APP_SENSOR_DIR})
|
||||
|
||||
|
||||
file (GLOB_RECURSE source_all ${WASM_APP_SENSOR_DIR}/*.c)
|
||||
|
||||
set (WASM_APP_CURRENT_SOURCE ${source_all})
|
||||
@ -88,10 +88,11 @@ wasm_sensor_callback(void *client, uint32 sensor_id, void *user_data)
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_sensor_config(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_config(wasm_exec_env_t exec_env,
|
||||
uint32 sensor, int interval,
|
||||
int bit_cfg, int delay)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
attr_container_t * attr_cont;
|
||||
sensor_client_t * c;
|
||||
sensor_obj_t s = find_sys_sensor_id(sensor);
|
||||
@ -133,9 +134,10 @@ wasm_sensor_config(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
uint32
|
||||
wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_open(wasm_exec_env_t exec_env,
|
||||
int32 name_offset, int instance)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *name = NULL;
|
||||
|
||||
if (!validate_app_str_addr(name_offset))
|
||||
@ -189,10 +191,11 @@ wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_sensor_config_with_attr_container(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_config_with_attr_container(wasm_exec_env_t exec_env,
|
||||
uint32 sensor, int32 buffer_offset,
|
||||
int len)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *buffer = NULL;
|
||||
|
||||
if (!validate_app_addr(buffer_offset, len))
|
||||
@ -216,8 +219,9 @@ wasm_sensor_config_with_attr_container(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_sensor_close(wasm_module_inst_t module_inst, uint32 sensor)
|
||||
wasm_sensor_close(wasm_exec_env_t exec_env, uint32 sensor)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
unsigned int client_id = mod_id;
|
||||
@ -7,7 +7,7 @@
|
||||
#define LIB_EXTENSION_RUNTIME_SENSOR_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
#include "attr_container.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
struct _sys_sensor;
|
||||
@ -51,19 +51,19 @@ int check_sensor_timers();
|
||||
void reschedule_sensor_read();
|
||||
|
||||
uint32
|
||||
wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_open(wasm_exec_env_t exec_env,
|
||||
int32 name_offset, int instance);
|
||||
|
||||
bool
|
||||
wasm_sensor_config(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_config(wasm_exec_env_t exec_env,
|
||||
uint32 sensor, int interval, int bit_cfg, int delay);
|
||||
|
||||
bool
|
||||
wasm_sensor_config_with_attr_container(wasm_module_inst_t module_inst,
|
||||
wasm_sensor_config_with_attr_container(wasm_exec_env_t exec_env,
|
||||
uint32 sensor, int32 buffer_offset,
|
||||
int len);
|
||||
|
||||
bool
|
||||
wasm_sensor_close(wasm_module_inst_t module_inst, uint32 sensor);
|
||||
wasm_sensor_close(wasm_exec_env_t exec_env, uint32 sensor);
|
||||
|
||||
#endif /* LIB_EXTENSION_RUNTIME_SENSOR_H_ */
|
||||
32
core/app-framework/sensor/native/sensor_api.h
Normal file
32
core/app-framework/sensor/native/sensor_api.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _SENSOR_API_H_
|
||||
#define _SENSOR_API_H_
|
||||
|
||||
#include "bh_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint32
|
||||
wasm_sensor_open(int32 name_offset, int instance);
|
||||
|
||||
bool
|
||||
wasm_sensor_config(uint32 sensor, int interval, int bit_cfg, int delay);
|
||||
|
||||
bool
|
||||
wasm_sensor_config_with_attr_container(uint32 sensor, int32 buffer_offset, int len);
|
||||
|
||||
bool
|
||||
wasm_sensor_close(uint32 sensor);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _SENSOR_API_H_ */
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include "bh_queue.h"
|
||||
#include "bh_thread.h"
|
||||
#include "runtime_sensor.h"
|
||||
#include "attr_container.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
@ -27,7 +27,7 @@ void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
|
||||
wasm_function_inst_t func_onSensorEvent;
|
||||
|
||||
bh_assert(SENSOR_EVENT_WASM == bh_message_type(msg));
|
||||
wasm_data *wasm_app_data = (wasm_data*) m_data->internal_data;
|
||||
wasm_data *wasm_app_data = (wasm_data*)m_data->internal_data;
|
||||
wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
|
||||
|
||||
sensor_event_data_t *payload = (sensor_event_data_t*)
|
||||
@ -37,8 +37,11 @@ void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
|
||||
|
||||
func_onSensorEvent = wasm_runtime_lookup_function(inst, "_on_sensor_event",
|
||||
"(i32i32i32)");
|
||||
if (!func_onSensorEvent)
|
||||
func_onSensorEvent = wasm_runtime_lookup_function(inst, "on_sensor_event",
|
||||
"(i32i32i32)");
|
||||
if (!func_onSensorEvent) {
|
||||
printf("Cannot find function onRequest\n");
|
||||
printf("Cannot find function on_sensor_event\n");
|
||||
} else {
|
||||
int32 sensor_data_offset;
|
||||
uint32 sensor_data_len;
|
||||
@ -66,7 +69,8 @@ void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
|
||||
argv[1] = (uint32) sensor_data_offset;
|
||||
argv[2] = sensor_data_len;
|
||||
|
||||
if (!wasm_runtime_call_wasm(inst, NULL, func_onSensorEvent, 3, argv)) {
|
||||
if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_onSensorEvent,
|
||||
3, argv)) {
|
||||
const char *exception = wasm_runtime_get_exception(inst);
|
||||
bh_assert(exception);
|
||||
printf(":Got exception running wasm code: %s\n",
|
||||
@ -8,5 +8,5 @@ include_directories(${WASM_LIB_SENSOR_DIR})
|
||||
|
||||
file (GLOB_RECURSE source_all ${WASM_LIB_SENSOR_DIR}/*.c)
|
||||
|
||||
set (WASM_LIB_SENSOR_SOURCE ${source_all})
|
||||
set (WASM_APP_LIB_CURRENT_SOURCE ${source_all})
|
||||
|
||||
@ -3,10 +3,6 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
void print_line(char* str)
|
||||
{
|
||||
printf("%s\n", str);
|
||||
}
|
||||
/*
|
||||
header file for wasm application
|
||||
*/
|
||||
16
core/app-framework/template/app/wasm_app.cmake
Normal file
16
core/app-framework/template/app/wasm_app.cmake
Normal file
@ -0,0 +1,16 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_APP_CURRENT_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(
|
||||
${WASM_APP_CURRENT_DIR}
|
||||
# Add your include dir here
|
||||
)
|
||||
|
||||
file (GLOB_RECURSE source_all
|
||||
${WASM_APP_CURRENT_DIR}/*.c
|
||||
# Add your source file here
|
||||
)
|
||||
|
||||
set (WASM_APP_CURRENT_SOURCE ${source_all})
|
||||
@ -3,10 +3,4 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _WASM_CONFIG_H
|
||||
#define _WASM_CONFIG_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#endif /* end of _WASM_CONFIG_H */
|
||||
|
||||
/* EXPORT_WASM_API(your_api_here), */
|
||||
17
core/app-framework/template/native/wasm_lib.cmake
Normal file
17
core/app-framework/template/native/wasm_lib.cmake
Normal file
@ -0,0 +1,17 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_LIB_CURRENT_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(
|
||||
${WASM_LIB_CURRENT_DIR}
|
||||
# Add your include dir here
|
||||
)
|
||||
|
||||
file (GLOB_RECURSE source_all
|
||||
${WASM_LIB_CURRENT_DIR}/*.c
|
||||
# Add your source file here
|
||||
)
|
||||
|
||||
set (WASM_APP_LIB_CURRENT_SOURCE ${source_all})
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wgl.h"
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "bh_platform.h"
|
||||
#include "gui_api.h"
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wgl.h"
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "gui_api.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "wgl.h"
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "gui_api.h"
|
||||
#include <string.h>
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wgl.h"
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "gui_api.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wgl.h"
|
||||
#include "wa-inc/wgl.h"
|
||||
#include "gui_api.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -10,7 +10,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "wgl_shared_utils.h" /* shared types between app and native */
|
||||
#include "bi-inc/wgl_shared_utils.h" /* shared types between app and native */
|
||||
#include "lvgl-compatible/lv_types.h"
|
||||
#include "lvgl-compatible/lv_obj.h"
|
||||
#include "lvgl-compatible/lv_btn.h"
|
||||
@ -10,7 +10,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "wgl_shared_utils.h" /* shared types between app and native */
|
||||
#include "bi-inc/wgl_shared_utils.h" /* shared types between app and native */
|
||||
|
||||
#include "inc/wgl_types.h"
|
||||
#include "inc/wgl_obj.h"
|
||||
15
core/app-framework/wgl/app/wasm_app.cmake
Normal file
15
core/app-framework/wgl/app/wasm_app.cmake
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_APP_GUI_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
set (DEPS_DIR ${WASM_APP_GUI_DIR}/../../../deps)
|
||||
|
||||
include_directories(${WASM_APP_GUI_DIR}
|
||||
${DEPS_DIR}
|
||||
${DEPS_DIR}/lvgl
|
||||
${DEPS_DIR}/lvgl/src)
|
||||
|
||||
file (GLOB_RECURSE source_all ${WASM_APP_GUI_DIR}/src/*.c)
|
||||
|
||||
set (WASM_APP_CURRENT_SOURCE ${source_all})
|
||||
36
core/app-framework/wgl/native/gui_api.h
Normal file
36
core/app-framework/wgl/native/gui_api.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#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, int32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_btn_native_call(int32 func_id, int32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_label_native_call(int32 func_id, int32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_cb_native_call(int32 func_id, int32 argv_offset, uint32 argc);
|
||||
|
||||
void
|
||||
wasm_list_native_call(int32 func_id, int32 argv_offset, uint32 argc);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* end of _GUI_API_H_ */
|
||||
18
core/app-framework/wgl/native/wasm_lib.cmake
Normal file
18
core/app-framework/wgl/native/wasm_lib.cmake
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_LIB_GUI_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
set (DEPS_DIR ${WASM_LIB_GUI_DIR}/../../../deps)
|
||||
|
||||
add_definitions(-DLV_CONF_INCLUDE_SIMPLE)
|
||||
|
||||
include_directories(${WASM_LIB_GUI_DIR}
|
||||
${DEPS_DIR}
|
||||
${DEPS_DIR}/lvgl
|
||||
${DEPS_DIR}/lvgl/src)
|
||||
|
||||
file (GLOB_RECURSE lvgl_source ${DEPS_DIR}/lvgl/*.c)
|
||||
file (GLOB_RECURSE wrapper_source ${WASM_LIB_GUI_DIR}/*.c)
|
||||
|
||||
set (WASM_APP_LIB_CURRENT_SOURCE ${wrapper_source} ${lvgl_source})
|
||||
@ -125,9 +125,10 @@ static WGLNativeFuncDef btn_native_func_defs[] = {
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_btn_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_btn_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(btn_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
@ -72,9 +72,10 @@ static WGLNativeFuncDef cb_native_func_defs[] = {
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_cb_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_cb_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(cb_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
@ -63,9 +63,10 @@ static WGLNativeFuncDef label_native_func_defs[] = {
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_label_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_label_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(label_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
@ -48,9 +48,10 @@ static WGLNativeFuncDef list_native_func_defs[] = {
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_list_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_list_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(list_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
@ -13,6 +13,7 @@ extern "C" {
|
||||
#include "bh_platform.h"
|
||||
#include "lvgl.h"
|
||||
#include "wasm_export.h"
|
||||
#include "bi-inc/wgl_shared_utils.h"
|
||||
|
||||
#define OBJ_ARG_NUM_MAX 4
|
||||
#define PTR_ARG_NUM_MAX 4
|
||||
@ -44,7 +44,7 @@ static void app_mgr_object_event_callback(module_data *m_data, bh_message_t msg)
|
||||
uint32 argv[2];
|
||||
wasm_function_inst_t func_on_object_event;
|
||||
bh_assert(WIDGET_EVENT_WASM == bh_message_type(msg));
|
||||
wasm_data *wasm_app_data = (wasm_data*) m_data->internal_data;
|
||||
wasm_data *wasm_app_data = (wasm_data*)m_data->internal_data;
|
||||
wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
|
||||
object_event_t *object_event
|
||||
= (object_event_t *)bh_message_payload(msg);
|
||||
@ -58,13 +58,14 @@ static void app_mgr_object_event_callback(module_data *m_data, bh_message_t msg)
|
||||
func_on_object_event = wasm_runtime_lookup_function(inst, "on_widget_event",
|
||||
"(i32i32)");
|
||||
if (!func_on_object_event) {
|
||||
printf("Cannot find function _on_object_event\n");
|
||||
printf("Cannot find function on_widget_event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
argv[0] = object_event->obj_id;
|
||||
argv[1] = object_event->event;
|
||||
if (!wasm_runtime_call_wasm(inst, NULL, func_on_object_event, 2, argv)) {
|
||||
if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_on_object_event,
|
||||
2, argv)) {
|
||||
const char *exception = wasm_runtime_get_exception(inst);
|
||||
bh_assert(exception);
|
||||
printf(":Got exception running wasm code: %s\n",
|
||||
@ -373,9 +374,10 @@ static WGLNativeFuncDef obj_native_func_defs[] = {
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
void
|
||||
wasm_obj_native_call(wasm_module_inst_t module_inst,
|
||||
wasm_obj_native_call(wasm_exec_env_t exec_env,
|
||||
int32 func_id, uint32 argv_offset, uint32 argc)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 size = sizeof(obj_native_func_defs) / sizeof(WGLNativeFuncDef);
|
||||
|
||||
wgl_native_func_call(module_inst,
|
||||
@ -8,7 +8,7 @@
|
||||
#include "bh_queue.h"
|
||||
#include "bh_memory.h"
|
||||
#include "bh_thread.h"
|
||||
#include "attr_container.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "event.h"
|
||||
#include "watchdog.h"
|
||||
#include "coap_ext.h"
|
||||
@ -214,7 +214,7 @@ void applet_mgt_reqeust_handler(request_t *request, void *unused)
|
||||
static int get_module_type(char *kv_str)
|
||||
{
|
||||
int module_type = -1;
|
||||
char type_str[8] = { 0 };
|
||||
char type_str[16] = { 0 };
|
||||
|
||||
find_key_value(kv_str, strlen(kv_str), "type", type_str,
|
||||
sizeof(type_str) - 1, '&');
|
||||
|
||||
@ -12,17 +12,14 @@
|
||||
#include "bh_types.h"
|
||||
#include "app_manager_export.h"
|
||||
#include "native_interface.h"
|
||||
#include "shared_utils.h"
|
||||
#include "bi-inc/shared_utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef __ZEPHYR__
|
||||
#define app_manager_printf printf
|
||||
#else
|
||||
#define app_manager_printf printk
|
||||
#endif
|
||||
/* bh_printf is defined in each platform */
|
||||
#define app_manager_printf bh_printf
|
||||
|
||||
#define SEND_ERR_RESPONSE(mid, err_msg) do { \
|
||||
app_manager_printf("%s\n", err_msg); \
|
||||
@ -79,11 +76,6 @@ app_manager_signature_verify(const uint8_t *file, unsigned int file_len,
|
||||
|
||||
void targeted_app_request_handler(request_t *request, void *unused);
|
||||
|
||||
#if BEIHAI_ENABLE_TOOL_AGENT != 0
|
||||
void *
|
||||
app_manager_get_tool_agent_queue();
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end of extern "C" */
|
||||
#endif
|
||||
|
||||
@ -110,12 +110,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
p[ctx->size_in_phase++] = ch;
|
||||
|
||||
if (ctx->size_in_phase == sizeof(ctx->message.payload_size)) {
|
||||
#ifndef __ZEPHYR__
|
||||
ctx->message.payload_size = ntohl(ctx->message.payload_size);
|
||||
#else
|
||||
if (is_little_endian())
|
||||
exchange32((uint8*)&ctx->message.payload_size);
|
||||
#endif
|
||||
ctx->phase = Phase_Payload;
|
||||
|
||||
if (enable_log)
|
||||
@ -140,9 +135,9 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->message.message_type != INSTALL_WASM_BYTECODE_APP) {
|
||||
ctx->message.payload = (char *) bh_malloc(
|
||||
ctx->message.payload_size);
|
||||
if (ctx->message.message_type != INSTALL_WASM_APP) {
|
||||
ctx->message.payload =
|
||||
(char *) bh_malloc(ctx->message.payload_size);
|
||||
if (!ctx->message.payload) {
|
||||
ctx->phase = Phase_Non_Start;
|
||||
return 0;
|
||||
@ -155,7 +150,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
|
||||
return 0;
|
||||
} else if (ctx->phase == Phase_Payload) {
|
||||
if (ctx->message.message_type == INSTALL_WASM_BYTECODE_APP) {
|
||||
if (ctx->message.message_type == INSTALL_WASM_APP) {
|
||||
int received_size;
|
||||
module_on_install_request_byte_arrive_func module_on_install =
|
||||
g_module_interfaces[Module_WASM_App]->module_on_install;
|
||||
@ -164,7 +159,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
|
||||
if (module_on_install != NULL) {
|
||||
if (module_on_install(ch, ctx->message.payload_size,
|
||||
&received_size)) {
|
||||
&received_size)) {
|
||||
if (received_size == ctx->message.payload_size) {
|
||||
/* whole wasm app received */
|
||||
ctx->phase = Phase_Non_Start;
|
||||
@ -173,11 +168,13 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
} else {
|
||||
/* receive or handle fail */
|
||||
ctx->phase = Phase_Non_Start;
|
||||
ctx->size_in_phase = 0;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
ctx->phase = Phase_Non_Start;
|
||||
ctx->size_in_phase = 0;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
@ -186,9 +183,8 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
if (ctx->size_in_phase == ctx->message.payload_size) {
|
||||
ctx->phase = Phase_Non_Start;
|
||||
if (enable_log)
|
||||
app_manager_printf(
|
||||
"##On byte arrive: receive end, payload_size is %d.\n",
|
||||
ctx->message.payload_size);
|
||||
app_manager_printf("##On byte arrive: receive end, payload_size is %d.\n",
|
||||
ctx->message.payload_size);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@ -6,7 +6,12 @@ set (__APP_MGR_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
include_directories(${__APP_MGR_DIR})
|
||||
|
||||
|
||||
file (GLOB source_all ${__APP_MGR_DIR}/*.c ${__APP_MGR_DIR}/platform/${TARGET_PLATFORM}/*.c)
|
||||
file (GLOB source_all ${__APP_MGR_DIR}/*.c ${__APP_MGR_DIR}/platform/${WAMR_BUILD_PLATFORM}/*.c)
|
||||
|
||||
set (APP_MGR_SOURCE ${source_all})
|
||||
|
||||
file (GLOB header
|
||||
${__APP_MGR_DIR}/module_wasm_app.h
|
||||
)
|
||||
LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#include "app_manager.h"
|
||||
#include "app_manager_host.h"
|
||||
#include "event.h"
|
||||
#include "attr_container.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "bh_memory.h"
|
||||
#include "coap_ext.h"
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user