Apply clang-format for more source files (#795)
Apply clang-format for C source files in folder core/app-mgr, core/app-framework, and test-tools. And rename folder component_test to component-test, update zephyr build document. Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
@ -14,13 +14,14 @@
|
||||
/* Queue of app manager */
|
||||
static bh_queue *g_app_mgr_queue;
|
||||
|
||||
void*
|
||||
void *
|
||||
get_app_manager_queue()
|
||||
{
|
||||
return g_app_mgr_queue;
|
||||
}
|
||||
|
||||
void app_manager_post_applets_update_event()
|
||||
void
|
||||
app_manager_post_applets_update_event()
|
||||
{
|
||||
module_data *m_data;
|
||||
attr_container_t *attr_cont;
|
||||
@ -56,7 +57,8 @@ void app_manager_post_applets_update_event()
|
||||
char buf[32];
|
||||
i++;
|
||||
snprintf(buf, sizeof(buf), "%s%d", "applet", i);
|
||||
if (!(attr_container_set_string(&attr_cont, buf, m_data->module_name))) {
|
||||
if (!(attr_container_set_string(&attr_cont, buf,
|
||||
m_data->module_name))) {
|
||||
app_manager_printf("Post applets update event failed: "
|
||||
"set attr applet name key failed.");
|
||||
goto fail;
|
||||
@ -73,7 +75,7 @@ void app_manager_post_applets_update_event()
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.url = url;
|
||||
msg.action = COAP_EVENT;
|
||||
msg.payload = (char*) attr_cont;
|
||||
msg.payload = (char *)attr_cont;
|
||||
send_request_to_host(&msg);
|
||||
|
||||
app_manager_printf("Post applets update event success!\n");
|
||||
@ -84,7 +86,8 @@ fail:
|
||||
attr_container_destroy(attr_cont);
|
||||
}
|
||||
|
||||
static int get_applets_count()
|
||||
static int
|
||||
get_applets_count()
|
||||
{
|
||||
module_data *m_data;
|
||||
int num = 0;
|
||||
@ -103,7 +106,8 @@ static int get_applets_count()
|
||||
}
|
||||
|
||||
/* Query fw apps info if name = NULL, otherwise query specify app */
|
||||
static bool app_manager_query_applets(request_t *msg, const char *name)
|
||||
static bool
|
||||
app_manager_query_applets(request_t *msg, const char *name)
|
||||
{
|
||||
module_data *m_data;
|
||||
attr_container_t *attr_cont;
|
||||
@ -127,8 +131,8 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
|
||||
}
|
||||
|
||||
if (name == NULL && !(attr_container_set_int(&attr_cont, "num", num))) {
|
||||
SEND_ERR_RESPONSE(msg->mid,
|
||||
"Query Applets failed: set attr container key failed.");
|
||||
SEND_ERR_RESPONSE(
|
||||
msg->mid, "Query Applets failed: set attr container key failed.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -140,10 +144,9 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
|
||||
i++;
|
||||
snprintf(buf, sizeof(buf), "%s%d", "applet", i);
|
||||
if (!(attr_container_set_string(&attr_cont, buf,
|
||||
m_data->module_name))) {
|
||||
SEND_ERR_RESPONSE(msg->mid,
|
||||
"Query Applets failed: "
|
||||
"set attr container key failed.");
|
||||
m_data->module_name))) {
|
||||
SEND_ERR_RESPONSE(msg->mid, "Query Applets failed: "
|
||||
"set attr container key failed.");
|
||||
goto fail;
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "%s%d", "heap", i);
|
||||
@ -157,13 +160,13 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
|
||||
else if (!strcmp(name, m_data->module_name)) {
|
||||
found = true;
|
||||
if (!(attr_container_set_string(&attr_cont, "name",
|
||||
m_data->module_name))) {
|
||||
SEND_ERR_RESPONSE(msg->mid,
|
||||
"Query Applet failed: "
|
||||
"set attr container key failed.");
|
||||
m_data->module_name))) {
|
||||
SEND_ERR_RESPONSE(msg->mid, "Query Applet failed: "
|
||||
"set attr container key failed.");
|
||||
goto fail;
|
||||
}
|
||||
if (!(attr_container_set_int(&attr_cont, "heap", m_data->heap_size))) {
|
||||
if (!(attr_container_set_int(&attr_cont, "heap",
|
||||
m_data->heap_size))) {
|
||||
SEND_ERR_RESPONSE(msg->mid,
|
||||
"Query Applet failed: "
|
||||
"set attr container heap key failed.");
|
||||
@ -176,15 +179,15 @@ static bool app_manager_query_applets(request_t *msg, const char *name)
|
||||
|
||||
if (name != NULL && !found) {
|
||||
SEND_ERR_RESPONSE(msg->mid,
|
||||
"Query Applet failed: the app is not found.");
|
||||
"Query Applet failed: the app is not found.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
len = attr_container_get_serialize_length(attr_cont);
|
||||
|
||||
make_response_for_request(msg, response);
|
||||
set_response(response, CONTENT_2_05,
|
||||
FMT_ATTR_CONTAINER, (char*) attr_cont, len);
|
||||
set_response(response, CONTENT_2_05, FMT_ATTR_CONTAINER, (char *)attr_cont,
|
||||
len);
|
||||
send_response_to_host(response);
|
||||
|
||||
ret = true;
|
||||
@ -197,7 +200,8 @@ fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void applet_mgt_reqeust_handler(request_t *request, void *unused)
|
||||
void
|
||||
applet_mgt_reqeust_handler(request_t *request, void *unused)
|
||||
{
|
||||
bh_message_t msg;
|
||||
/* deep copy, but not use app self heap, but use global heap */
|
||||
@ -216,13 +220,14 @@ void applet_mgt_reqeust_handler(request_t *request, void *unused)
|
||||
}
|
||||
|
||||
/* return -1 for error */
|
||||
static int get_module_type(char *kv_str)
|
||||
static int
|
||||
get_module_type(char *kv_str)
|
||||
{
|
||||
int module_type = -1;
|
||||
char type_str[16] = { 0 };
|
||||
|
||||
find_key_value(kv_str, strlen(kv_str), "type", type_str,
|
||||
sizeof(type_str) - 1, '&');
|
||||
sizeof(type_str) - 1, '&');
|
||||
|
||||
if (strlen(type_str) == 0)
|
||||
module_type = Module_WASM_App;
|
||||
@ -240,34 +245,37 @@ static int get_module_type(char *kv_str)
|
||||
|
||||
/* Queue callback of App Manager */
|
||||
|
||||
static void app_manager_queue_callback(void *message, void *arg)
|
||||
static void
|
||||
app_manager_queue_callback(void *message, void *arg)
|
||||
{
|
||||
request_t *request = (request_t *) bh_message_payload((bh_message_t)message);
|
||||
request_t *request = (request_t *)bh_message_payload((bh_message_t)message);
|
||||
int mid = request->mid, module_type, offset;
|
||||
|
||||
(void)arg;
|
||||
|
||||
if ((offset = check_url_start(request->url, strlen(request->url), "/applet"))
|
||||
> 0) {
|
||||
if ((offset =
|
||||
check_url_start(request->url, strlen(request->url), "/applet"))
|
||||
> 0) {
|
||||
module_type = get_module_type(request->url + offset);
|
||||
|
||||
if (module_type == -1) {
|
||||
SEND_ERR_RESPONSE(mid,
|
||||
"Applet Management failed: invalid module type.");
|
||||
"Applet Management failed: invalid module type.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Install Applet */
|
||||
if (request->action == COAP_PUT) {
|
||||
if (get_applets_count() >= MAX_APP_INSTALLATIONS) {
|
||||
SEND_ERR_RESPONSE(mid,
|
||||
"Install Applet failed: exceed max app installations.");
|
||||
SEND_ERR_RESPONSE(
|
||||
mid,
|
||||
"Install Applet failed: exceed max app installations.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!request->payload) {
|
||||
SEND_ERR_RESPONSE(mid,
|
||||
"Install Applet failed: invalid payload.");
|
||||
"Install Applet failed: invalid payload.");
|
||||
goto fail;
|
||||
}
|
||||
if (g_module_interfaces[module_type]
|
||||
@ -280,14 +288,15 @@ static void app_manager_queue_callback(void *message, void *arg)
|
||||
else if (request->action == COAP_DELETE) {
|
||||
module_type = get_module_type(request->url + offset);
|
||||
if (module_type == -1) {
|
||||
SEND_ERR_RESPONSE(mid,
|
||||
"Uninstall Applet failed: invalid module type.");
|
||||
SEND_ERR_RESPONSE(
|
||||
mid, "Uninstall Applet failed: invalid module type.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (g_module_interfaces[module_type]
|
||||
&& g_module_interfaces[module_type]->module_uninstall) {
|
||||
if (!g_module_interfaces[module_type]->module_uninstall(request))
|
||||
&& g_module_interfaces[module_type]->module_uninstall) {
|
||||
if (!g_module_interfaces[module_type]->module_uninstall(
|
||||
request))
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
@ -308,7 +317,8 @@ static void app_manager_queue_callback(void *message, void *arg)
|
||||
}
|
||||
/* Event Register/Unregister */
|
||||
else if ((offset = check_url_start(request->url, strlen(request->url),
|
||||
"/event/")) > 0) {
|
||||
"/event/"))
|
||||
> 0) {
|
||||
char url_buf[256] = { 0 };
|
||||
|
||||
strncpy(url_buf, request->url + offset, sizeof(url_buf) - 1);
|
||||
@ -328,14 +338,14 @@ static void app_manager_queue_callback(void *message, void *arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fail:
|
||||
return;
|
||||
}
|
||||
|
||||
static void module_interfaces_init()
|
||||
static void
|
||||
module_interfaces_init()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < Module_Max; i++) {
|
||||
@ -344,7 +354,8 @@ static void module_interfaces_init()
|
||||
}
|
||||
}
|
||||
|
||||
void app_manager_startup(host_interface *interface)
|
||||
void
|
||||
app_manager_startup(host_interface *interface)
|
||||
{
|
||||
module_interfaces_init();
|
||||
|
||||
@ -390,21 +401,20 @@ fail1:
|
||||
|
||||
module_interface *g_module_interfaces[Module_Max] = {
|
||||
#if ENABLE_MODULE_JEFF != 0
|
||||
&jeff_module_interface,
|
||||
&jeff_module_interface,
|
||||
#else
|
||||
NULL,
|
||||
NULL,
|
||||
#endif
|
||||
|
||||
#if ENABLE_MODULE_WASM_APP != 0
|
||||
&wasm_app_module_interface,
|
||||
&wasm_app_module_interface,
|
||||
#else
|
||||
NULL,
|
||||
NULL,
|
||||
#endif
|
||||
|
||||
#if ENABLE_MODULE_WASM_LIB != 0
|
||||
&wasm_lib_module_interface
|
||||
&wasm_lib_module_interface
|
||||
#else
|
||||
NULL
|
||||
NULL
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@ -21,10 +21,11 @@ extern "C" {
|
||||
/* os_printf is defined in each platform */
|
||||
#define app_manager_printf os_printf
|
||||
|
||||
#define SEND_ERR_RESPONSE(mid, err_msg) do { \
|
||||
app_manager_printf("%s\n", err_msg); \
|
||||
send_error_response_to_host(mid, INTERNAL_SERVER_ERROR_5_00, err_msg); \
|
||||
} while (0)
|
||||
#define SEND_ERR_RESPONSE(mid, err_msg) \
|
||||
do { \
|
||||
app_manager_printf("%s\n", err_msg); \
|
||||
send_error_response_to_host(mid, INTERNAL_SERVER_ERROR_5_00, err_msg); \
|
||||
} while (0)
|
||||
|
||||
extern module_interface *g_module_interfaces[Module_Max];
|
||||
|
||||
@ -49,14 +50,15 @@ module_data_list_destroy();
|
||||
bool
|
||||
app_manager_is_interrupting_module(uint32 module_type, void *module_inst);
|
||||
|
||||
void release_module(module_data *m_data);
|
||||
void
|
||||
release_module(module_data *m_data);
|
||||
|
||||
void
|
||||
module_data_list_remove(module_data *m_data);
|
||||
|
||||
void*
|
||||
app_manager_timer_create(void (*timer_callback)(void*),
|
||||
watchdog_timer *wd_timer);
|
||||
void *
|
||||
app_manager_timer_create(void (*timer_callback)(void *),
|
||||
watchdog_timer *wd_timer);
|
||||
|
||||
void
|
||||
app_manager_timer_destroy(void *timer);
|
||||
@ -67,18 +69,18 @@ app_manager_timer_start(void *timer, int timeout);
|
||||
void
|
||||
app_manager_timer_stop(void *timer);
|
||||
|
||||
watchdog_timer*
|
||||
watchdog_timer *
|
||||
app_manager_get_wd_timer_from_timer_handle(void *timer);
|
||||
|
||||
int
|
||||
app_manager_signature_verify(const uint8_t *file, unsigned int file_len,
|
||||
const uint8_t *signature, unsigned int sig_size);
|
||||
const uint8_t *signature, unsigned int sig_size);
|
||||
|
||||
void targeted_app_request_handler(request_t *request, void *unused);
|
||||
void
|
||||
targeted_app_request_handler(request_t *request, void *unused);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end of extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -13,10 +13,7 @@
|
||||
static host_interface host_commu;
|
||||
|
||||
/* IMRTLink Two leading bytes */
|
||||
static unsigned char leadings[] = {
|
||||
(unsigned char)0x12,
|
||||
(unsigned char)0x34
|
||||
};
|
||||
static unsigned char leadings[] = { (unsigned char)0x12, (unsigned char)0x34 };
|
||||
|
||||
/* IMRTLink Receiving Phase */
|
||||
typedef enum recv_phase_t {
|
||||
@ -43,14 +40,16 @@ static korp_mutex host_lock;
|
||||
|
||||
static bool enable_log = false;
|
||||
|
||||
static bool is_little_endian()
|
||||
static bool
|
||||
is_little_endian()
|
||||
{
|
||||
long i = 0x01020304;
|
||||
unsigned char* c = (unsigned char*) &i;
|
||||
unsigned char *c = (unsigned char *)&i;
|
||||
return (*c == 0x04) ? true : false;
|
||||
}
|
||||
|
||||
static void exchange32(uint8* pData)
|
||||
static void
|
||||
exchange32(uint8 *pData)
|
||||
{
|
||||
uint8 value = *pData;
|
||||
*pData = *(pData + 3);
|
||||
@ -65,7 +64,8 @@ static void exchange32(uint8* pData)
|
||||
* 1: complete message received
|
||||
* 0: incomplete message received
|
||||
*/
|
||||
static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
static int
|
||||
on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
{
|
||||
if (ctx->phase == Phase_Non_Start) {
|
||||
ctx->message.payload_size = 0;
|
||||
@ -88,7 +88,8 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
if (enable_log)
|
||||
app_manager_printf("##On byte arrive: got leading 1\n");
|
||||
ctx->phase = Phase_Type;
|
||||
} else
|
||||
}
|
||||
else
|
||||
ctx->phase = Phase_Non_Start;
|
||||
|
||||
return 0;
|
||||
@ -111,7 +112,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
return 0;
|
||||
}
|
||||
else if (ctx->phase == Phase_Size) {
|
||||
unsigned char *p = (unsigned char *) &ctx->message.payload_size;
|
||||
unsigned char *p = (unsigned char *)&ctx->message.payload_size;
|
||||
|
||||
if (enable_log)
|
||||
app_manager_printf("##On byte arrive: got payload_size, byte %d\n",
|
||||
@ -141,7 +142,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
|
||||
if (ctx->message.message_type != INSTALL_WASM_APP) {
|
||||
ctx->message.payload =
|
||||
(char *) APP_MGR_MALLOC(ctx->message.payload_size);
|
||||
(char *)APP_MGR_MALLOC(ctx->message.payload_size);
|
||||
if (!ctx->message.payload) {
|
||||
ctx->phase = Phase_Non_Start;
|
||||
return 0;
|
||||
@ -158,7 +159,7 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
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;
|
||||
g_module_interfaces[Module_WASM_App]->module_on_install;
|
||||
|
||||
ctx->size_in_phase++;
|
||||
|
||||
@ -216,7 +217,8 @@ static int on_imrt_link_byte_arrive(unsigned char ch, recv_context_t *ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int aee_host_msg_callback(void *msg, uint32_t msg_len)
|
||||
int
|
||||
aee_host_msg_callback(void *msg, uint32_t msg_len)
|
||||
{
|
||||
unsigned char *p = msg, *p_end = p + msg_len;
|
||||
|
||||
@ -234,7 +236,8 @@ int aee_host_msg_callback(void *msg, uint32_t msg_len)
|
||||
memset(&request, 0, sizeof(request));
|
||||
|
||||
if (!unpack_request(recv_ctx.message.payload,
|
||||
recv_ctx.message.payload_size, &request))
|
||||
recv_ctx.message.payload_size,
|
||||
&request))
|
||||
continue;
|
||||
|
||||
request.sender = ID_HOST;
|
||||
@ -242,7 +245,8 @@ int aee_host_msg_callback(void *msg, uint32_t msg_len)
|
||||
am_dispatch_request(&request);
|
||||
}
|
||||
else {
|
||||
app_manager_printf("unexpected host msg type: %d\n", msg_type);
|
||||
app_manager_printf("unexpected host msg type: %d\n",
|
||||
msg_type);
|
||||
}
|
||||
|
||||
APP_MGR_FREE(recv_ctx.message.payload);
|
||||
@ -257,7 +261,8 @@ int aee_host_msg_callback(void *msg, uint32_t msg_len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool app_manager_host_init(host_interface *interface)
|
||||
bool
|
||||
app_manager_host_init(host_interface *interface)
|
||||
{
|
||||
os_mutex_init(&host_lock);
|
||||
memset(&recv_ctx, 0, sizeof(recv_ctx));
|
||||
@ -267,12 +272,13 @@ bool app_manager_host_init(host_interface *interface)
|
||||
host_commu.destroy = interface->destroy;
|
||||
|
||||
if (host_commu.init != NULL)
|
||||
return host_commu.init();
|
||||
return host_commu.init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int app_manager_host_send_msg(int msg_type, const char *buf, int size)
|
||||
int
|
||||
app_manager_host_send_msg(int msg_type, const char *buf, int size)
|
||||
{
|
||||
/* send an IMRT LINK message contains the buf as payload */
|
||||
if (host_commu.send != NULL) {
|
||||
@ -285,11 +291,11 @@ int app_manager_host_send_msg(int msg_type, const char *buf, int size)
|
||||
|
||||
/* message type */
|
||||
/* TODO: check if use network byte order!!! */
|
||||
*((uint16*)(header + 2)) = htons(msg_type);
|
||||
*((uint16 *)(header + 2)) = htons(msg_type);
|
||||
|
||||
/* payload length */
|
||||
if (is_little_endian())
|
||||
exchange32((uint8*) &size_s);
|
||||
exchange32((uint8 *)&size_s);
|
||||
|
||||
bh_memcpy_s(header + 4, 4, &size_s, 4);
|
||||
n = host_commu.send(NULL, header, 8);
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HOST_MODE_AON 1
|
||||
#define HOST_MODE_AON 1
|
||||
#define HOST_MODE_UART 2
|
||||
#define HOST_MODE_TEST 3
|
||||
|
||||
@ -21,4 +21,3 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
#if 0
|
||||
|
||||
#define BLUETOOTH_INTERFACE_ADVERTISMENT_DATA_LENGTH 31
|
||||
#define BLUETOOTH_INTERFACE_ADVERTISMENT_DATA_LENGTH 31
|
||||
/* ble_device_info */
|
||||
typedef struct ble_device_info {
|
||||
|
||||
|
||||
@ -11,25 +11,26 @@
|
||||
#include "coap_ext.h"
|
||||
|
||||
typedef struct _subscribe {
|
||||
struct _subscribe * next;
|
||||
struct _subscribe *next;
|
||||
uint32 subscriber_id;
|
||||
} subscribe_t;
|
||||
|
||||
typedef struct _event {
|
||||
struct _event *next;
|
||||
int subscriber_size;
|
||||
subscribe_t * subscribers;
|
||||
subscribe_t *subscribers;
|
||||
char url[1]; /* event url */
|
||||
} event_reg_t;
|
||||
|
||||
event_reg_t *g_events = NULL;
|
||||
|
||||
static bool find_subscriber(event_reg_t * reg, uint32 id, bool remove_found)
|
||||
static bool
|
||||
find_subscriber(event_reg_t *reg, uint32 id, bool remove_found)
|
||||
{
|
||||
subscribe_t* c = reg->subscribers;
|
||||
subscribe_t * prev = NULL;
|
||||
subscribe_t *c = reg->subscribers;
|
||||
subscribe_t *prev = NULL;
|
||||
while (c) {
|
||||
subscribe_t * next = c->next;
|
||||
subscribe_t *next = c->next;
|
||||
if (c->subscriber_id == id) {
|
||||
if (remove_found) {
|
||||
if (prev)
|
||||
@ -41,7 +42,8 @@ static bool find_subscriber(event_reg_t * reg, uint32 id, bool remove_found)
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
prev = c;
|
||||
c = next;
|
||||
}
|
||||
@ -50,7 +52,8 @@ static bool find_subscriber(event_reg_t * reg, uint32 id, bool remove_found)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool check_url(const char *url)
|
||||
static bool
|
||||
check_url(const char *url)
|
||||
{
|
||||
if (*url == 0)
|
||||
return false;
|
||||
@ -58,7 +61,8 @@ static bool check_url(const char *url)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool am_register_event(const char *url, uint32_t reg_client)
|
||||
bool
|
||||
am_register_event(const char *url, uint32_t reg_client)
|
||||
{
|
||||
event_reg_t *current = g_events;
|
||||
|
||||
@ -76,8 +80,8 @@ bool am_register_event(const char *url, uint32_t reg_client)
|
||||
|
||||
if (current == NULL) {
|
||||
if (NULL
|
||||
== (current = (event_reg_t *) APP_MGR_MALLOC(
|
||||
offsetof(event_reg_t, url) + strlen(url) + 1))) {
|
||||
== (current = (event_reg_t *)APP_MGR_MALLOC(
|
||||
offsetof(event_reg_t, url) + strlen(url) + 1))) {
|
||||
app_manager_printf("am_register_event: malloc fail\n");
|
||||
return false;
|
||||
}
|
||||
@ -90,8 +94,9 @@ bool am_register_event(const char *url, uint32_t reg_client)
|
||||
|
||||
if (find_subscriber(current, reg_client, false)) {
|
||||
return true;
|
||||
} else {
|
||||
subscribe_t * s = (subscribe_t*) APP_MGR_MALLOC(sizeof(subscribe_t));
|
||||
}
|
||||
else {
|
||||
subscribe_t *s = (subscribe_t *)APP_MGR_MALLOC(sizeof(subscribe_t));
|
||||
if (s == NULL)
|
||||
return false;
|
||||
|
||||
@ -100,29 +105,30 @@ bool am_register_event(const char *url, uint32_t reg_client)
|
||||
s->next = current->subscribers;
|
||||
current->subscribers = s;
|
||||
app_manager_printf("client: %d registered event (%s)\n", reg_client,
|
||||
url);
|
||||
url);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// @url: NULL means the client wants to unregister all its subscribed items
|
||||
bool am_unregister_event(const char *url, uint32_t reg_client)
|
||||
bool
|
||||
am_unregister_event(const char *url, uint32_t reg_client)
|
||||
{
|
||||
event_reg_t *current = g_events, *pre = NULL;
|
||||
|
||||
while (current != NULL) {
|
||||
if (url == NULL || strcmp(current->url, url) == 0) {
|
||||
event_reg_t * next = current->next;
|
||||
event_reg_t *next = current->next;
|
||||
if (find_subscriber(current, reg_client, true)) {
|
||||
app_manager_printf("client: %d deregistered event (%s)\n",
|
||||
reg_client, current->url);
|
||||
reg_client, current->url);
|
||||
}
|
||||
|
||||
// remove the registration if no client subscribe it
|
||||
if (current->subscribers == NULL) {
|
||||
app_manager_printf("unregister for event deleted url:(%s)\n",
|
||||
current->url);
|
||||
current->url);
|
||||
if (pre)
|
||||
pre->next = next;
|
||||
else
|
||||
@ -139,33 +145,38 @@ bool am_unregister_event(const char *url, uint32_t reg_client)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool event_handle_event_request(uint8_t code, const char *event_url,
|
||||
uint32_t reg_client)
|
||||
bool
|
||||
event_handle_event_request(uint8_t code, const char *event_url,
|
||||
uint32_t reg_client)
|
||||
{
|
||||
if (code == COAP_PUT) { /* register */
|
||||
return am_register_event(event_url, reg_client);
|
||||
} else if (code == COAP_DELETE) { /* unregister */
|
||||
}
|
||||
else if (code == COAP_DELETE) { /* unregister */
|
||||
return am_unregister_event(event_url, reg_client);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* invalid request */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void am_publish_event(request_t * event)
|
||||
void
|
||||
am_publish_event(request_t *event)
|
||||
{
|
||||
bh_assert(event->action == COAP_EVENT);
|
||||
|
||||
event_reg_t *current = g_events;
|
||||
while (current) {
|
||||
if (0 == strcmp(event->url, current->url)) {
|
||||
subscribe_t* c = current->subscribers;
|
||||
subscribe_t *c = current->subscribers;
|
||||
while (c) {
|
||||
if (c->subscriber_id == ID_HOST) {
|
||||
send_request_to_host(event);
|
||||
} else {
|
||||
module_request_handler
|
||||
(event, (void *)(uintptr_t)c->subscriber_id);
|
||||
}
|
||||
else {
|
||||
module_request_handler(event,
|
||||
(void *)(uintptr_t)c->subscriber_id);
|
||||
}
|
||||
c = c->next;
|
||||
}
|
||||
@ -177,7 +188,8 @@ void am_publish_event(request_t * event)
|
||||
}
|
||||
}
|
||||
|
||||
bool event_is_registered(const char *event_url)
|
||||
bool
|
||||
event_is_registered(const char *event_url)
|
||||
{
|
||||
event_reg_t *current = g_events;
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ extern "C" {
|
||||
*/
|
||||
bool
|
||||
event_handle_event_request(uint8_t code, const char *event_url,
|
||||
uint32_t register);
|
||||
uint32_t register);
|
||||
|
||||
/**
|
||||
* Test whether the event is registered
|
||||
|
||||
@ -26,7 +26,8 @@ bool send_coap_packet_to_host(coap_packet_t * packet)
|
||||
}
|
||||
#endif
|
||||
|
||||
bool send_request_to_host(request_t *msg)
|
||||
bool
|
||||
send_request_to_host(request_t *msg)
|
||||
{
|
||||
if (COAP_EVENT == msg->action && !event_is_registered(msg->url)) {
|
||||
app_manager_printf("Event is not registered\n");
|
||||
@ -34,7 +35,7 @@ bool send_request_to_host(request_t *msg)
|
||||
}
|
||||
|
||||
int size;
|
||||
char * packet = pack_request(msg, &size);
|
||||
char *packet = pack_request(msg, &size);
|
||||
if (packet == NULL)
|
||||
return false;
|
||||
|
||||
@ -45,10 +46,11 @@ bool send_request_to_host(request_t *msg)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool send_response_to_host(response_t *response)
|
||||
bool
|
||||
send_response_to_host(response_t *response)
|
||||
{
|
||||
int size;
|
||||
char * packet = pack_response(response, &size);
|
||||
char *packet = pack_response(response, &size);
|
||||
if (packet == NULL)
|
||||
return false;
|
||||
|
||||
@ -59,7 +61,8 @@ bool send_response_to_host(response_t *response)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool send_error_response_to_host(int mid, int status, const char *msg)
|
||||
bool
|
||||
send_error_response_to_host(int mid, int status, const char *msg)
|
||||
{
|
||||
int payload_len = 0;
|
||||
attr_container_t *payload = NULL;
|
||||
@ -73,8 +76,8 @@ bool send_error_response_to_host(int mid, int status, const char *msg)
|
||||
}
|
||||
}
|
||||
|
||||
set_response(response, status, FMT_ATTR_CONTAINER,
|
||||
(const char *)payload, payload_len);
|
||||
set_response(response, status, FMT_ATTR_CONTAINER, (const char *)payload,
|
||||
payload_len);
|
||||
response->mid = mid;
|
||||
|
||||
send_response_to_host(response);
|
||||
@ -83,4 +86,3 @@ bool send_error_response_to_host(int mid, int status, const char *msg)
|
||||
attr_container_destroy(payload);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -17,13 +17,15 @@ korp_mutex module_data_list_lock;
|
||||
/* Module data list */
|
||||
module_data *module_data_list;
|
||||
|
||||
bool module_data_list_init()
|
||||
bool
|
||||
module_data_list_init()
|
||||
{
|
||||
module_data_list = NULL;
|
||||
return !os_mutex_init(&module_data_list_lock) ? true : false;
|
||||
}
|
||||
|
||||
void module_data_list_destroy()
|
||||
void
|
||||
module_data_list_destroy()
|
||||
{
|
||||
|
||||
os_mutex_lock(&module_data_list_lock);
|
||||
@ -38,7 +40,8 @@ void module_data_list_destroy()
|
||||
os_mutex_destroy(&module_data_list_lock);
|
||||
}
|
||||
|
||||
static void module_data_list_add(module_data *m_data)
|
||||
static void
|
||||
module_data_list_add(module_data *m_data)
|
||||
{
|
||||
static uint32 module_id_max = 1;
|
||||
os_mutex_lock(&module_data_list_lock);
|
||||
@ -49,7 +52,8 @@ static void module_data_list_add(module_data *m_data)
|
||||
m_data->id = module_id_max++;
|
||||
if (!module_data_list) {
|
||||
module_data_list = m_data;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* Set as head */
|
||||
m_data->next = module_data_list;
|
||||
module_data_list = m_data;
|
||||
@ -57,7 +61,8 @@ static void module_data_list_add(module_data *m_data)
|
||||
os_mutex_unlock(&module_data_list_lock);
|
||||
}
|
||||
|
||||
void module_data_list_remove(module_data *m_data)
|
||||
void
|
||||
module_data_list_remove(module_data *m_data)
|
||||
{
|
||||
os_mutex_lock(&module_data_list_lock);
|
||||
if (module_data_list) {
|
||||
@ -76,7 +81,7 @@ void module_data_list_remove(module_data *m_data)
|
||||
os_mutex_unlock(&module_data_list_lock);
|
||||
}
|
||||
|
||||
module_data*
|
||||
module_data *
|
||||
module_data_list_lookup(const char *module_name)
|
||||
{
|
||||
os_mutex_lock(&module_data_list_lock);
|
||||
@ -96,7 +101,7 @@ module_data_list_lookup(const char *module_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
module_data*
|
||||
module_data *
|
||||
module_data_list_lookup_id(unsigned int module_id)
|
||||
{
|
||||
os_mutex_lock(&module_data_list_lock);
|
||||
@ -119,72 +124,78 @@ module_data_list_lookup_id(unsigned int module_id)
|
||||
module_data *
|
||||
app_manager_get_module_data(uint32 module_type, void *module_inst)
|
||||
{
|
||||
if (module_type < Module_Max
|
||||
&& g_module_interfaces[module_type]
|
||||
if (module_type < Module_Max && g_module_interfaces[module_type]
|
||||
&& g_module_interfaces[module_type]->module_get_module_data)
|
||||
return g_module_interfaces[module_type]->module_get_module_data(module_inst);
|
||||
return g_module_interfaces[module_type]->module_get_module_data(
|
||||
module_inst);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void*
|
||||
void *
|
||||
app_manager_get_module_queue(uint32 module_type, void *module_inst)
|
||||
{
|
||||
module_data *m_data = app_manager_get_module_data(module_type, module_inst);
|
||||
return m_data ? m_data->queue : NULL;
|
||||
}
|
||||
|
||||
const char*
|
||||
const char *
|
||||
app_manager_get_module_name(uint32 module_type, void *module_inst)
|
||||
{
|
||||
module_data *m_data = app_manager_get_module_data(module_type, module_inst);
|
||||
return m_data ? m_data->module_name : NULL;
|
||||
}
|
||||
|
||||
unsigned int app_manager_get_module_id(uint32 module_type, void *module_inst)
|
||||
unsigned int
|
||||
app_manager_get_module_id(uint32 module_type, void *module_inst)
|
||||
{
|
||||
module_data *m_data = app_manager_get_module_data(module_type, module_inst);
|
||||
return m_data ? m_data->id : ID_NONE;
|
||||
}
|
||||
|
||||
void*
|
||||
void *
|
||||
app_manager_get_module_heap(uint32 module_type, void *module_inst)
|
||||
{
|
||||
module_data *m_data = app_manager_get_module_data(module_type, module_inst);
|
||||
return m_data ? m_data->heap : NULL;
|
||||
}
|
||||
|
||||
module_data*
|
||||
module_data *
|
||||
app_manager_lookup_module_data(const char *name)
|
||||
{
|
||||
return module_data_list_lookup(name);
|
||||
}
|
||||
|
||||
void app_manager_add_module_data(module_data *m_data)
|
||||
void
|
||||
app_manager_add_module_data(module_data *m_data)
|
||||
{
|
||||
module_data_list_add(m_data);
|
||||
}
|
||||
|
||||
void app_manager_del_module_data(module_data *m_data)
|
||||
void
|
||||
app_manager_del_module_data(module_data *m_data)
|
||||
{
|
||||
module_data_list_remove(m_data);
|
||||
|
||||
release_module(m_data);
|
||||
}
|
||||
|
||||
bool app_manager_is_interrupting_module(uint32 module_type, void *module_inst)
|
||||
bool
|
||||
app_manager_is_interrupting_module(uint32 module_type, void *module_inst)
|
||||
{
|
||||
module_data *m_data = app_manager_get_module_data(module_type, module_inst);
|
||||
return m_data ? m_data->wd_timer.is_interrupting : false;
|
||||
}
|
||||
|
||||
extern void destroy_module_timer_ctx(unsigned int module_id);
|
||||
extern void
|
||||
destroy_module_timer_ctx(unsigned int module_id);
|
||||
|
||||
void release_module(module_data *m_data)
|
||||
void
|
||||
release_module(module_data *m_data)
|
||||
{
|
||||
watchdog_timer_destroy(&m_data->wd_timer);
|
||||
|
||||
#ifdef HEAP_ENABLED /* TODO */
|
||||
if(m_data->heap)
|
||||
if (m_data->heap)
|
||||
gc_destroy_for_instance(m_data->heap);
|
||||
#endif
|
||||
|
||||
@ -198,7 +209,8 @@ void release_module(module_data *m_data)
|
||||
APP_MGR_FREE(m_data);
|
||||
}
|
||||
|
||||
uint32 check_modules_timer_expiry()
|
||||
uint32
|
||||
check_modules_timer_expiry()
|
||||
{
|
||||
os_mutex_lock(&module_data_list_lock);
|
||||
module_data *p = module_data_list;
|
||||
@ -216,4 +228,3 @@ uint32 check_modules_timer_expiry()
|
||||
os_mutex_unlock(&module_data_list_lock);
|
||||
return ms_to_expiry;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -56,7 +56,7 @@ typedef struct wasm_data {
|
||||
/* thread list mapped with this WASM module */
|
||||
korp_tid thread_id;
|
||||
/* for easily access the containing module data */
|
||||
module_data* m_data;
|
||||
module_data *m_data;
|
||||
/* is bytecode or aot */
|
||||
bool is_bytecode;
|
||||
/* sections of wasm bytecode or aot file */
|
||||
@ -109,16 +109,18 @@ typedef struct wasm_app_file_t {
|
||||
extern module_interface wasm_app_module_interface;
|
||||
|
||||
typedef void (*message_type_handler_t)(module_data *m_data, bh_message_t msg);
|
||||
extern bool wasm_register_msg_callback(int msg_type,
|
||||
message_type_handler_t message_handler);
|
||||
extern bool
|
||||
wasm_register_msg_callback(int msg_type,
|
||||
message_type_handler_t message_handler);
|
||||
|
||||
typedef void (*resource_cleanup_handler_t)(uint32 module_id);
|
||||
extern bool wasm_register_cleanup_callback(resource_cleanup_handler_t handler);
|
||||
extern bool
|
||||
wasm_register_cleanup_callback(resource_cleanup_handler_t handler);
|
||||
|
||||
/**
|
||||
* Set WASI root dir for modules. On each wasm app installation, a sub dir named
|
||||
* with the app's name will be created autamically. That wasm app can only access
|
||||
* this sub dir.
|
||||
* with the app's name will be created autamically. That wasm app can only
|
||||
* access this sub dir.
|
||||
*
|
||||
* @param root_dir the root dir to set
|
||||
* @return true for success, false otherwise
|
||||
|
||||
@ -3,47 +3,56 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
|
||||
#include "module_wasm_lib.h"
|
||||
|
||||
static bool wasm_lib_module_init(void)
|
||||
static bool
|
||||
wasm_lib_module_init(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool wasm_lib_module_install(request_t *msg)
|
||||
static bool
|
||||
wasm_lib_module_install(request_t *msg)
|
||||
{
|
||||
(void) msg;
|
||||
(void)msg;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool wasm_lib_module_uninstall(request_t *msg)
|
||||
static bool
|
||||
wasm_lib_module_uninstall(request_t *msg)
|
||||
{
|
||||
(void) msg;
|
||||
(void)msg;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void wasm_lib_module_watchdog_kill(module_data *m_data)
|
||||
static void
|
||||
wasm_lib_module_watchdog_kill(module_data *m_data)
|
||||
{
|
||||
(void) m_data;
|
||||
(void)m_data;
|
||||
}
|
||||
|
||||
static bool wasm_lib_module_handle_host_url(void *queue_msg)
|
||||
static bool
|
||||
wasm_lib_module_handle_host_url(void *queue_msg)
|
||||
{
|
||||
(void) queue_msg;
|
||||
(void)queue_msg;
|
||||
return false;
|
||||
}
|
||||
|
||||
static module_data*
|
||||
static module_data *
|
||||
wasm_lib_module_get_module_data(void *inst)
|
||||
{
|
||||
(void) inst;
|
||||
(void)inst;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
module_interface wasm_lib_module_interface = { wasm_lib_module_init,
|
||||
wasm_lib_module_install, wasm_lib_module_uninstall,
|
||||
wasm_lib_module_watchdog_kill, wasm_lib_module_handle_host_url,
|
||||
wasm_lib_module_get_module_data,
|
||||
NULL };
|
||||
|
||||
/* clang-format off */
|
||||
module_interface wasm_lib_module_interface = {
|
||||
wasm_lib_module_init,
|
||||
wasm_lib_module_install,
|
||||
wasm_lib_module_uninstall,
|
||||
wasm_lib_module_watchdog_kill,
|
||||
wasm_lib_module_handle_host_url,
|
||||
wasm_lib_module_get_module_data,
|
||||
NULL
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
@ -5,25 +5,28 @@
|
||||
|
||||
#include "app_manager.h"
|
||||
|
||||
void*
|
||||
app_manager_timer_create(void (*timer_callback)(void*),
|
||||
watchdog_timer *wd_timer)
|
||||
void *
|
||||
app_manager_timer_create(void (*timer_callback)(void *),
|
||||
watchdog_timer *wd_timer)
|
||||
{
|
||||
/* TODO */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void app_manager_timer_destroy(void *timer)
|
||||
void
|
||||
app_manager_timer_destroy(void *timer)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
void app_manager_timer_start(void *timer, int timeout)
|
||||
void
|
||||
app_manager_timer_start(void *timer, int timeout)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
void app_manager_timer_stop(void *timer)
|
||||
void
|
||||
app_manager_timer_stop(void *timer)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
@ -35,9 +38,9 @@ app_manager_get_wd_timer_from_timer_handle(void *timer)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int app_manager_signature_verify(const uint8_t *file, unsigned int file_len,
|
||||
const uint8_t *signature, unsigned int sig_size)
|
||||
int
|
||||
app_manager_signature_verify(const uint8_t *file, unsigned int file_len,
|
||||
const uint8_t *signature, unsigned int sig_size)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -16,32 +16,36 @@ typedef struct k_timer_watchdog {
|
||||
watchdog_timer *wd_timer;
|
||||
} k_timer_watchdog;
|
||||
|
||||
void*
|
||||
app_manager_timer_create(void (*timer_callback)(void*),
|
||||
watchdog_timer *wd_timer)
|
||||
void *
|
||||
app_manager_timer_create(void (*timer_callback)(void *),
|
||||
watchdog_timer *wd_timer)
|
||||
{
|
||||
struct k_timer_watchdog *timer = APP_MGR_MALLOC(sizeof(struct k_timer_watchdog));
|
||||
struct k_timer_watchdog *timer =
|
||||
APP_MGR_MALLOC(sizeof(struct k_timer_watchdog));
|
||||
|
||||
if (timer) {
|
||||
k_timer_init(&timer->timer, (void (*)(struct k_timer*)) timer_callback,
|
||||
NULL);
|
||||
k_timer_init(&timer->timer, (void (*)(struct k_timer *))timer_callback,
|
||||
NULL);
|
||||
timer->wd_timer = wd_timer;
|
||||
}
|
||||
|
||||
return timer;
|
||||
}
|
||||
|
||||
void app_manager_timer_destroy(void *timer)
|
||||
void
|
||||
app_manager_timer_destroy(void *timer)
|
||||
{
|
||||
APP_MGR_FREE(timer);
|
||||
}
|
||||
|
||||
void app_manager_timer_start(void *timer, int timeout)
|
||||
void
|
||||
app_manager_timer_start(void *timer, int timeout)
|
||||
{
|
||||
k_timer_start(timer, Z_TIMEOUT_MS(timeout), Z_TIMEOUT_MS(0));
|
||||
}
|
||||
|
||||
void app_manager_timer_stop(void *timer)
|
||||
void
|
||||
app_manager_timer_stop(void *timer)
|
||||
{
|
||||
k_timer_stop(timer);
|
||||
}
|
||||
@ -49,7 +53,7 @@ void app_manager_timer_stop(void *timer)
|
||||
watchdog_timer *
|
||||
app_manager_get_wd_timer_from_timer_handle(void *timer)
|
||||
{
|
||||
return ((k_timer_watchdog*) timer)->wd_timer;
|
||||
return ((k_timer_watchdog *)timer)->wd_timer;
|
||||
}
|
||||
#if 0
|
||||
int app_manager_signature_verify(const uint8_t *file, unsigned int file_len,
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
|
||||
#include "native_interface.h"
|
||||
#include "app_manager.h"
|
||||
#include "app_manager_export.h"
|
||||
@ -13,14 +12,15 @@
|
||||
|
||||
typedef struct _app_res_register {
|
||||
struct _app_res_register *next;
|
||||
char * url;
|
||||
char *url;
|
||||
void (*request_handler)(request_t *, void *);
|
||||
uint32 register_id;
|
||||
} app_res_register_t;
|
||||
|
||||
static app_res_register_t * g_resources = NULL;
|
||||
static app_res_register_t *g_resources = NULL;
|
||||
|
||||
void module_request_handler(request_t *request, void *user_data)
|
||||
void
|
||||
module_request_handler(request_t *request, void *user_data)
|
||||
{
|
||||
unsigned int mod_id = (unsigned int)(uintptr_t)user_data;
|
||||
bh_message_t msg;
|
||||
@ -54,10 +54,11 @@ void module_request_handler(request_t *request, void *user_data)
|
||||
}
|
||||
|
||||
app_manager_printf("Send request to app %s success.\n",
|
||||
m_data->module_name);
|
||||
m_data->module_name);
|
||||
}
|
||||
|
||||
void targeted_app_request_handler(request_t *request, void *unused)
|
||||
void
|
||||
targeted_app_request_handler(request_t *request, void *unused)
|
||||
{
|
||||
char applet_name[128] = { 0 };
|
||||
int offset;
|
||||
@ -74,7 +75,8 @@ void targeted_app_request_handler(request_t *request, void *unused)
|
||||
char *p = strchr(applet_name, '/');
|
||||
if (p) {
|
||||
*p = 0;
|
||||
} else
|
||||
}
|
||||
else
|
||||
return;
|
||||
app_manager_printf("Send request to applet: %s\n", applet_name);
|
||||
|
||||
@ -84,16 +86,17 @@ void targeted_app_request_handler(request_t *request, void *unused)
|
||||
m_data = module_data_list_lookup(applet_name);
|
||||
if (!m_data) {
|
||||
SEND_ERR_RESPONSE(request->mid,
|
||||
"Send request to applet failed: invalid applet name");
|
||||
"Send request to applet failed: invalid applet name");
|
||||
goto end;
|
||||
}
|
||||
|
||||
module_request_handler(request, (void *)(uintptr_t)m_data->id);
|
||||
end: request->url = url;
|
||||
|
||||
end:
|
||||
request->url = url;
|
||||
}
|
||||
|
||||
void am_send_response(response_t *response)
|
||||
void
|
||||
am_send_response(response_t *response)
|
||||
{
|
||||
module_data *m_data;
|
||||
|
||||
@ -101,15 +104,15 @@ void am_send_response(response_t *response)
|
||||
m_data = module_data_list_lookup_id(response->reciever);
|
||||
if (!m_data) {
|
||||
send_response_to_host(response);
|
||||
|
||||
} else {
|
||||
response_t * resp_for_send = clone_response(response);
|
||||
}
|
||||
else {
|
||||
response_t *resp_for_send = clone_response(response);
|
||||
if (!resp_for_send) {
|
||||
return;
|
||||
}
|
||||
|
||||
bh_message_t msg = bh_new_msg(RESTFUL_RESPONSE, resp_for_send,
|
||||
sizeof(*resp_for_send), response_cleaner);
|
||||
sizeof(*resp_for_send), response_cleaner);
|
||||
if (!msg) {
|
||||
response_cleaner(resp_for_send);
|
||||
return;
|
||||
@ -121,7 +124,8 @@ void am_send_response(response_t *response)
|
||||
}
|
||||
}
|
||||
|
||||
void * am_dispatch_request(request_t *request)
|
||||
void *
|
||||
am_dispatch_request(request_t *request)
|
||||
{
|
||||
app_res_register_t *r = g_resources;
|
||||
|
||||
@ -135,11 +139,12 @@ void * am_dispatch_request(request_t *request)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool am_register_resource(const char *url,
|
||||
void (*request_handler)(request_t *, void *),
|
||||
uint32 register_id)
|
||||
bool
|
||||
am_register_resource(const char *url,
|
||||
void (*request_handler)(request_t *, void *),
|
||||
uint32 register_id)
|
||||
{
|
||||
app_res_register_t * r = g_resources;
|
||||
app_res_register_t *r = g_resources;
|
||||
int register_num = 0;
|
||||
|
||||
while (r) {
|
||||
@ -178,10 +183,11 @@ bool am_register_resource(const char *url,
|
||||
return true;
|
||||
}
|
||||
|
||||
void am_cleanup_registeration(uint32 register_id)
|
||||
void
|
||||
am_cleanup_registeration(uint32 register_id)
|
||||
{
|
||||
app_res_register_t * r = g_resources;
|
||||
app_res_register_t * prev = NULL;
|
||||
app_res_register_t *r = g_resources;
|
||||
app_res_register_t *prev = NULL;
|
||||
|
||||
while (r) {
|
||||
app_res_register_t *next = r->next;
|
||||
@ -194,7 +200,8 @@ void am_cleanup_registeration(uint32 register_id)
|
||||
|
||||
APP_MGR_FREE(r->url);
|
||||
APP_MGR_FREE(r);
|
||||
} else
|
||||
}
|
||||
else
|
||||
/* if r is freed, should not change prev. Only set prev to r
|
||||
when r isn't freed. */
|
||||
prev = r;
|
||||
|
||||
@ -12,10 +12,11 @@
|
||||
static bh_queue *watchdog_queue;
|
||||
|
||||
#ifdef WATCHDOG_ENABLED /* TODO */
|
||||
static void watchdog_timer_callback(void *timer)
|
||||
static void
|
||||
watchdog_timer_callback(void *timer)
|
||||
{
|
||||
watchdog_timer *wd_timer = app_manager_get_wd_timer_from_timer_handle(
|
||||
timer);
|
||||
watchdog_timer *wd_timer =
|
||||
app_manager_get_wd_timer_from_timer_handle(timer);
|
||||
|
||||
watchdog_timer_stop(wd_timer);
|
||||
|
||||
@ -26,14 +27,15 @@ static void watchdog_timer_callback(void *timer)
|
||||
wd_timer->is_interrupting = true;
|
||||
|
||||
bh_post_msg(watchdog_queue, WD_TIMEOUT, wd_timer->module_data,
|
||||
sizeof(module_data));
|
||||
sizeof(module_data));
|
||||
}
|
||||
|
||||
os_mutex_unlock(&wd_timer->lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool watchdog_timer_init(module_data *m_data)
|
||||
bool
|
||||
watchdog_timer_init(module_data *m_data)
|
||||
{
|
||||
#ifdef WATCHDOG_ENABLED /* TODO */
|
||||
watchdog_timer *wd_timer = &m_data->wd_timer;
|
||||
@ -42,7 +44,7 @@ bool watchdog_timer_init(module_data *m_data)
|
||||
return false;
|
||||
|
||||
if (!(wd_timer->timer_handle =
|
||||
app_manager_timer_create(watchdog_timer_callback, wd_timer))) {
|
||||
app_manager_timer_create(watchdog_timer_callback, wd_timer))) {
|
||||
os_mutex_destroy(&wd_timer->lock);
|
||||
return false;
|
||||
}
|
||||
@ -54,7 +56,8 @@ bool watchdog_timer_init(module_data *m_data)
|
||||
return true;
|
||||
}
|
||||
|
||||
void watchdog_timer_destroy(watchdog_timer *wd_timer)
|
||||
void
|
||||
watchdog_timer_destroy(watchdog_timer *wd_timer)
|
||||
{
|
||||
#ifdef WATCHDOG_ENABLED /* TODO */
|
||||
app_manager_timer_destroy(wd_timer->timer_handle);
|
||||
@ -62,32 +65,35 @@ void watchdog_timer_destroy(watchdog_timer *wd_timer)
|
||||
#endif
|
||||
}
|
||||
|
||||
void watchdog_timer_start(watchdog_timer *wd_timer)
|
||||
void
|
||||
watchdog_timer_start(watchdog_timer *wd_timer)
|
||||
{
|
||||
os_mutex_lock(&wd_timer->lock);
|
||||
|
||||
wd_timer->is_interrupting = false;
|
||||
wd_timer->is_stopped = false;
|
||||
app_manager_timer_start(wd_timer->timer_handle,
|
||||
wd_timer->module_data->timeout);
|
||||
wd_timer->module_data->timeout);
|
||||
|
||||
os_mutex_unlock(&wd_timer->lock);
|
||||
}
|
||||
|
||||
void watchdog_timer_stop(watchdog_timer *wd_timer)
|
||||
void
|
||||
watchdog_timer_stop(watchdog_timer *wd_timer)
|
||||
{
|
||||
app_manager_timer_stop(wd_timer->timer_handle);
|
||||
}
|
||||
|
||||
#ifdef WATCHDOG_ENABLED /* TODO */
|
||||
static void watchdog_queue_callback(void *queue_msg)
|
||||
static void
|
||||
watchdog_queue_callback(void *queue_msg)
|
||||
{
|
||||
if (bh_message_type(queue_msg) == WD_TIMEOUT) {
|
||||
module_data *m_data = (module_data *) bh_message_payload(queue_msg);
|
||||
module_data *m_data = (module_data *)bh_message_payload(queue_msg);
|
||||
if (g_module_interfaces[m_data->module_type]
|
||||
&& g_module_interfaces[m_data->module_type]->module_watchdog_kill) {
|
||||
&& g_module_interfaces[m_data->module_type]->module_watchdog_kill) {
|
||||
g_module_interfaces[m_data->module_type]->module_watchdog_kill(
|
||||
m_data);
|
||||
m_data);
|
||||
app_manager_post_applets_update_event();
|
||||
}
|
||||
}
|
||||
@ -95,22 +101,23 @@ static void watchdog_queue_callback(void *queue_msg)
|
||||
#endif
|
||||
|
||||
#ifdef WATCHDOG_ENABLED /* TODO */
|
||||
static void*
|
||||
static void *
|
||||
watchdog_thread_routine(void *arg)
|
||||
{
|
||||
/* Enter loop run */
|
||||
bh_queue_enter_loop_run(watchdog_queue, watchdog_queue_callback);
|
||||
|
||||
(void) arg;
|
||||
(void)arg;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool watchdog_startup()
|
||||
bool
|
||||
watchdog_startup()
|
||||
{
|
||||
if (!(watchdog_queue = bh_queue_create())) {
|
||||
app_manager_printf(
|
||||
"App Manager start failed: create watchdog queue failed.\n");
|
||||
"App Manager start failed: create watchdog queue failed.\n");
|
||||
return false;
|
||||
}
|
||||
#if 0
|
||||
@ -125,7 +132,8 @@ bool watchdog_startup()
|
||||
return true;
|
||||
}
|
||||
|
||||
void watchdog_destroy()
|
||||
void
|
||||
watchdog_destroy()
|
||||
{
|
||||
bh_queue_exit_loop_run(watchdog_queue);
|
||||
bh_queue_destroy(watchdog_queue);
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _WATCHDOG_H_
|
||||
#define _WATCHDOG_H_
|
||||
|
||||
@ -25,7 +24,7 @@ watchdog_timer_start(watchdog_timer *wd_timer);
|
||||
void
|
||||
watchdog_timer_stop(watchdog_timer *wd_timer);
|
||||
|
||||
watchdog_timer*
|
||||
watchdog_timer *
|
||||
app_manager_get_watchdog_timer(void *timer);
|
||||
|
||||
bool
|
||||
|
||||
@ -20,7 +20,7 @@ extern "C" {
|
||||
#define ID_HOST -3
|
||||
#define ID_APP_MGR -2
|
||||
/* Invalid module ID */
|
||||
#define ID_NONE (uint32)-1
|
||||
#define ID_NONE ((uint32)-1)
|
||||
|
||||
struct attr_container_t;
|
||||
|
||||
@ -40,7 +40,10 @@ typedef enum QUEUE_MSG_TYPE {
|
||||
} QUEUE_MSG_TYPE;
|
||||
|
||||
typedef enum {
|
||||
Module_Jeff, Module_WASM_App, Module_WASM_Lib, Module_Max
|
||||
Module_Jeff,
|
||||
Module_WASM_App,
|
||||
Module_WASM_Lib,
|
||||
Module_Max
|
||||
} Module_Type;
|
||||
|
||||
struct module_data;
|
||||
@ -111,12 +114,13 @@ typedef module_data *(*module_get_module_data_func)(void *inst);
|
||||
*
|
||||
* @param ch the byte to be received and handled
|
||||
* @param total_size total size of the request
|
||||
* @param received_total_size currently received total size when the function return
|
||||
* @param received_total_size currently received total size when
|
||||
* the function return
|
||||
*
|
||||
* @return true if success, false otherwise
|
||||
*/
|
||||
typedef bool (*module_on_install_request_byte_arrive_func) (
|
||||
uint8 ch, int total_size, int *received_total_size);
|
||||
typedef bool (*module_on_install_request_byte_arrive_func)(
|
||||
uint8 ch, int total_size, int *received_total_size);
|
||||
|
||||
/* Interfaces of each module */
|
||||
typedef struct module_interface {
|
||||
@ -148,7 +152,7 @@ typedef bool (*host_init_func)(void);
|
||||
*
|
||||
* @return size of the data sent in bytes
|
||||
*/
|
||||
typedef int (*host_send_fun)(void * ctx, const char *buf, int size);
|
||||
typedef int (*host_send_fun)(void *ctx, const char *buf, int size);
|
||||
|
||||
/**
|
||||
* @typedef host_destroy_fun
|
||||
@ -191,22 +195,22 @@ app_manager_get_module_name(uint32 module_type, void *module_inst);
|
||||
void *
|
||||
app_manager_get_module_heap(uint32 module_type, void *module_inst);
|
||||
|
||||
void*
|
||||
void *
|
||||
get_app_manager_queue();
|
||||
|
||||
module_data*
|
||||
module_data *
|
||||
app_manager_get_module_data(uint32 module_type, void *module_inst);
|
||||
|
||||
unsigned int
|
||||
app_manager_get_module_id(uint32 module_type, void *module_inst);
|
||||
|
||||
module_data*
|
||||
module_data *
|
||||
app_manager_lookup_module_data(const char *name);
|
||||
|
||||
module_data*
|
||||
module_data *
|
||||
module_data_list_lookup(const char *module_name);
|
||||
|
||||
module_data*
|
||||
module_data *
|
||||
module_data_list_lookup_id(unsigned int module_id);
|
||||
|
||||
void
|
||||
@ -214,9 +218,11 @@ app_manager_post_applets_update_event();
|
||||
|
||||
bool
|
||||
am_register_resource(const char *url,
|
||||
void (*request_handler)(request_t *, void *), uint32 register_id);
|
||||
void (*request_handler)(request_t *, void *),
|
||||
uint32 register_id);
|
||||
|
||||
void am_cleanup_registeration(uint32 register_id);
|
||||
void
|
||||
am_cleanup_registeration(uint32 register_id);
|
||||
|
||||
bool
|
||||
am_register_event(const char *url, uint32_t reg_client);
|
||||
@ -224,13 +230,17 @@ am_register_event(const char *url, uint32_t reg_client);
|
||||
bool
|
||||
am_unregister_event(const char *url, uint32_t reg_client);
|
||||
|
||||
void am_publish_event(request_t * event);
|
||||
void
|
||||
am_publish_event(request_t *event);
|
||||
|
||||
void * am_dispatch_request(request_t *request);
|
||||
void *
|
||||
am_dispatch_request(request_t *request);
|
||||
|
||||
void am_send_response(response_t *response);
|
||||
void
|
||||
am_send_response(response_t *response);
|
||||
|
||||
void module_request_handler(request_t *request, void *user_data);
|
||||
void
|
||||
module_request_handler(request_t *request, void *user_data);
|
||||
|
||||
/**
|
||||
* Send request message to host
|
||||
@ -291,4 +301,3 @@ app_manager_host_send_msg(int msg_type, const char *buf, int size);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user