From 140e8e19c8e871a80800405a9c8439a647245028 Mon Sep 17 00:00:00 2001 From: lyon Date: Sun, 18 Dec 2022 19:22:43 +0800 Subject: [PATCH] save cb to a new object --- .../PikaStdDevice/PikaStdDevice_BaseDev.c | 4 +- .../TemplateDevice/TemplateDevice.c | 2 +- .../TemplateDevice/TemplateDevice_GPIO.c | 4 +- .../pikascript-lib/mqtt/_mqtt__MQTT.c | 194 +++++++++--------- src/PikaObj.c | 20 +- src/PikaObj.h | 16 +- src/PikaVM.c | 2 +- test/event-test.cpp | 16 +- 8 files changed, 133 insertions(+), 125 deletions(-) diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_BaseDev.c b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_BaseDev.c index a9cdbdec1..1f1084dd0 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_BaseDev.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_BaseDev.c @@ -15,7 +15,7 @@ void PikaStdDevice_BaseDev_addEventCallBack(PikaObj* self, Arg* eventCallBack) { obj_setArg(self, "eventCallBack", eventCallBack); /* init event_listener for the first time */ if (NULL == g_pika_device_event_listener) { - pks_eventLisener_init(&g_pika_device_event_listener); + pks_eventListener_init(&g_pika_device_event_listener); } if (PIKA_RES_OK != obj_runNativeMethod(self, "platformGetEventId", NULL)) { obj_setErrorCode(self, 1); @@ -23,7 +23,7 @@ void PikaStdDevice_BaseDev_addEventCallBack(PikaObj* self, Arg* eventCallBack) { "platformGetEventId"); } uint32_t eventId = obj_getInt(self, "eventId"); - pks_eventLicener_registEvent(g_pika_device_event_listener, eventId, self); + pks_eventListener_registEvent(g_pika_device_event_listener, eventId, self); #else obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] PIKA_EVENT_ENABLE is disabled."); diff --git a/port/linux/package/pikascript/pikascript-lib/TemplateDevice/TemplateDevice.c b/port/linux/package/pikascript/pikascript-lib/TemplateDevice/TemplateDevice.c index edf673f21..4a5388bd1 100644 --- a/port/linux/package/pikascript/pikascript-lib/TemplateDevice/TemplateDevice.c +++ b/port/linux/package/pikascript/pikascript-lib/TemplateDevice/TemplateDevice.c @@ -3,5 +3,5 @@ extern PikaEventListener* g_pika_device_event_listener; void TemplateDevice___del__(PikaObj *self){ - pks_eventLisener_deinit(&g_pika_device_event_listener); + pks_eventListener_deinit(&g_pika_device_event_listener); } diff --git a/port/linux/package/pikascript/pikascript-lib/TemplateDevice/TemplateDevice_GPIO.c b/port/linux/package/pikascript/pikascript-lib/TemplateDevice/TemplateDevice_GPIO.c index f7c398841..7d954f0f3 100644 --- a/port/linux/package/pikascript/pikascript-lib/TemplateDevice/TemplateDevice_GPIO.c +++ b/port/linux/package/pikascript/pikascript-lib/TemplateDevice/TemplateDevice_GPIO.c @@ -21,8 +21,8 @@ extern PikaEventListener* g_pika_device_event_listener; #define GPIO_PA8_EVENT_ID 0x08 void TemplateDevice_GPIO_eventTest(PikaObj* self) { - pks_eventLisener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID, + pks_eventListener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID, EVENT_SIGNAL_IO_FALLING_EDGE); - pks_eventLisener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID, + pks_eventListener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID, EVENT_SIGNAL_IO_RISING_EDGE); } diff --git a/port/linux/package/pikascript/pikascript-lib/mqtt/_mqtt__MQTT.c b/port/linux/package/pikascript/pikascript-lib/mqtt/_mqtt__MQTT.c index 0ef5cd44f..33d012128 100644 --- a/port/linux/package/pikascript/pikascript-lib/mqtt/_mqtt__MQTT.c +++ b/port/linux/package/pikascript/pikascript-lib/mqtt/_mqtt__MQTT.c @@ -1,6 +1,7 @@ #include "_mqtt__MQTT.h" -#include "mqttclient.h" #include "PikaStdData_List.h" +#include "TinyObj.h" +#include "mqttclient.h" PikaEventListener* g_mqtt_event_listener = NULL; @@ -32,8 +33,7 @@ void _mqtt__MQTT___init__(PikaObj* self, if (strlen(ip) > 0) { obj_setStr(self, "host_str", ip); mqtt_set_host(_client, obj_getStr(self, "host_str")); - } - else { + } else { __platform_printf("mqtt_init input ip none\r\n"); } @@ -45,54 +45,48 @@ void _mqtt__MQTT___init__(PikaObj* self, if (strlen(clinetID) > 0) { obj_setStr(self, "id_str", clinetID); mqtt_set_client_id(_client, obj_getStr(self, "id_str")); - } - else { + } else { __platform_printf("mqtt_init input clinetID none\r\n"); } if (strlen(username) > 0) { obj_setStr(self, "username_str", username); mqtt_set_user_name(_client, obj_getStr(self, "username_str")); - } - else { + } else { __platform_printf("mqtt_init input username none\r\n"); } if (strlen(password) > 0) { obj_setStr(self, "password_str", password); mqtt_set_password(_client, obj_getStr(self, "password_str")); - } - else { + } else { __platform_printf("mqtt_init input password none\r\n"); } tmp = atoi(version); if (tmp > 0) { mqtt_set_version(_client, tmp); - } - else { + } else { __platform_printf("mqtt_init input version none\r\n"); } if (strlen(ca) > 0) { obj_setStr(self, "ca_str", ca); mqtt_set_ca(_client, obj_getStr(self, "ca_str")); - } - else { + } else { // __platform_printf("mqtt_init input ca none\r\n"); } if (keepalive > 0) { mqtt_set_keep_alive_interval(_client, keepalive); - } - else { + } else { __platform_printf("mqtt_init input keepalive none\r\n"); } mqtt_set_clean_session(_client, 1); obj_setPtr(self, "_client", - _client); //这里要再保存一次mqtt结构体的内容到python环境 + _client); // 这里要再保存一次mqtt结构体的内容到python环境 // __platform_printf("Mqtt_Lib buildtime:%s-%s\r\n", __DATE__, __TIME__); } @@ -169,8 +163,7 @@ PikaObj* _mqtt__MQTT_listSubscribeTopic(PikaObj* self) { message_handlers_t* msg_handler; PikaObj* list = NULL; - if (NULL == _client) - { + if (NULL == _client) { return NULL; } @@ -184,15 +177,16 @@ PikaObj* _mqtt__MQTT_listSubscribeTopic(PikaObj* self) { list = newNormalObj(New_PikaStdData_List); /* 初始化 list */ PikaStdData_List___init__(list); - + LIST_FOR_EACH_SAFE(curr, next, &_client->mqtt_msg_handler_list) { msg_handler = LIST_ENTRY(curr, message_handlers_t, list); /* determine whether a node already exists by mqtt topic, but wildcards * are not supported */ if (NULL != msg_handler->topic_filter) { // MQTT_LOG_I("%s:%d %s()...[%d] subscribe topic: %s", __FILE__, - // __LINE__, __FUNCTION__, ++i, msg_handler->topic_filter); - + // __LINE__, __FUNCTION__, ++i, + // msg_handler->topic_filter); + /* 用 arg_new 的 api 创建 arg */ Arg* str_arg1 = arg_newStr((char*)msg_handler->topic_filter); /* 添加到 list 对象 */ @@ -209,14 +203,14 @@ PikaObj* _mqtt__MQTT_listSubscribeTopic(PikaObj* self) { // 输入参数:主题名称,有效数据 // 返 回 值:0=成功;非0=错误码 /////////////////////////////////////////////////////////////////// -int _mqtt__MQTT_publish(PikaObj *self, char* topic, int qos, char* payload) { +int _mqtt__MQTT_publish(PikaObj* self, char* topic, int qos, char* payload) { int ret; mqtt_message_t msg; mqtt_client_t* _client = obj_getPtr(self, "_client"); memset(&msg, 0, sizeof(msg)); - if((qos < 0) || (qos > 2)) { + if ((qos < 0) || (qos > 2)) { __platform_printf("input qos error\r\n"); return -1; } @@ -232,12 +226,12 @@ int _mqtt__MQTT_publish(PikaObj *self, char* topic, int qos, char* payload) { msg.payload = (void*)payload; msg.qos = qos; - __platform_printf("msg.qos:%d\r\n",msg.qos);//这里为了防止被优化,导致运行异常 + __platform_printf("msg.qos:%d\r\n", + msg.qos); // 这里为了防止被优化,导致运行异常 ret = mqtt_publish(_client, topic, &msg); if (ret == 0) { // __platform_printf("MQTT_publish OK\r\n"); - } - else + } else __platform_printf("MQTT_publish ERROR\r\n"); return ret; } @@ -310,8 +304,12 @@ int _mqtt__MQTT_setHost(PikaObj* self, char* host_url) { return -2; } - obj_setStr(self, "host_str",host_url); // python 环境创建一个全局变量存放 host - mqtt_set_host(_client,obj_getStr(self,"host_str")); //从python环境中取出 host的指针 赋值给结构体 + obj_setStr(self, "host_str", + host_url); // python 环境创建一个全局变量存放 host + mqtt_set_host( + _client, + obj_getStr(self, + "host_str")); // 从python环境中取出 host的指针 赋值给结构体 // __platform_printf("MQTT_setHost :%s\r\n", host_url); return 0; @@ -323,7 +321,7 @@ int _mqtt__MQTT_setHost(PikaObj* self, char* host_url) { // 输入参数:字符串格式 // 返 回 值:0=成功;非0=错误码 /////////////////////////////////////////////////////////////////// -int _mqtt__MQTT_setKeepAlive(PikaObj *self, int time) { +int _mqtt__MQTT_setKeepAlive(PikaObj* self, int time) { mqtt_client_t* _client = obj_getPtr(self, "_client"); int tmp; @@ -424,14 +422,13 @@ int _mqtt__MQTT_setVersion(PikaObj* self, char* version) { mqtt_client_t* _client = obj_getPtr(self, "_client"); // int tmp; - if(version == NULL) { + if (version == NULL) { __platform_printf("input version str error\n"); return -1; } - if((strcmp(version,"3.1") == 0) || (strcmp(version,"3.1.1") == 0)) { + if ((strcmp(version, "3.1") == 0) || (strcmp(version, "3.1.1") == 0)) { mqtt_set_version(_client, 3); - } - else { + } else { __platform_printf("input version data error\n"); return -2; } @@ -446,18 +443,22 @@ int _mqtt__MQTT_setVersion(PikaObj* self, char* version) { // 输入参数: // 返 回 值:0=成功;非0=错误码 /////////////////////////////////////////////////////////////////// -int _mqtt__MQTT_setWill(PikaObj *self, char* topic, char* payload, int qos, int retain) { +int _mqtt__MQTT_setWill(PikaObj* self, + char* topic, + char* payload, + int qos, + int retain) { mqtt_client_t* _client = obj_getPtr(self, "_client"); int ret; char topic_str[MQTT_TOPIC_LEN_MAX]; // __platform_printf("\r\n"); - if(topic == NULL) { + if (topic == NULL) { __platform_printf("input topic error\r\n"); return -1; } - if (strlen(topic) <= 0) { + if (strlen(topic) <= 0) { __platform_printf("input topic error\r\n"); return -1; } @@ -467,11 +468,11 @@ int _mqtt__MQTT_setWill(PikaObj *self, char* topic, char* payload, int qos, int return -1; } - if(payload == NULL) { + if (payload == NULL) { __platform_printf("input payload error\r\n"); return -1; } - + if (strlen(payload) <= 0) { __platform_printf("input payload error\r\n"); return -1; @@ -479,13 +480,15 @@ int _mqtt__MQTT_setWill(PikaObj *self, char* topic, char* payload, int qos, int // __platform_printf("input retain :%d\r\n", (uint8_t)retain); - //必须转换成python环境的变量,否则函数退出后,topic里的是个空指针 - memset(topic_str,0,sizeof(topic_str)); - sprintf(topic_str,"%s",topic); + // 必须转换成python环境的变量,否则函数退出后,topic里的是个空指针 + memset(topic_str, 0, sizeof(topic_str)); + sprintf(topic_str, "%s", topic); obj_setStr(self, topic_str, topic); obj_setStr(self, "Will_payload", payload); - ret = mqtt_set_will_options(_client, obj_getStr(self, topic_str), qos, (uint8_t)retain, obj_getStr(self, "Will_payload")); + ret = mqtt_set_will_options(_client, obj_getStr(self, topic_str), qos, + (uint8_t)retain, + obj_getStr(self, "Will_payload")); if (ret == 0) { // __platform_printf("MQTT_setWill OK\r\n", topic); @@ -501,19 +504,20 @@ int _mqtt__MQTT_setWill(PikaObj *self, char* topic, char* payload, int qos, int // 输入参数: // 返 回 值:0=成功;非0=错误码 /////////////////////////////////////////////////////////////////// -int _mqtt__MQTT_subscribe(PikaObj *self, char* topic, int qos, Arg* cb) { +int _mqtt__MQTT_subscribe(PikaObj* self, char* topic, int qos, Arg* cb) { mqtt_client_t* _client = obj_getPtr(self, "_client"); int ret; - char topic_str[MQTT_TOPIC_LEN_MAX+24]; - + char topic_str[MQTT_TOPIC_LEN_MAX + 24]; + // __platform_printf("topic_str:%s \r\n",topic_str); - if(topic == NULL) { + if (topic == NULL) { __platform_printf("input topic error\r\n"); return -1; } - if ((strlen(topic) > MQTT_TOPIC_LEN_MAX)||(strlen(topic) <= 0)) { - __platform_printf("input topic data error strlen(topic):%d\r\n",strlen(topic)); + if ((strlen(topic) > MQTT_TOPIC_LEN_MAX) || (strlen(topic) <= 0)) { + __platform_printf("input topic data error strlen(topic):%d\r\n", + strlen(topic)); return -2; } @@ -521,34 +525,37 @@ int _mqtt__MQTT_subscribe(PikaObj *self, char* topic, int qos, Arg* cb) { __platform_printf("input qos error\r\n"); return -3; } - - //必须转换成python环境的变量,否则函数退出后,topic里的是个空指针 - memset(topic_str,0,sizeof(topic_str)); - sprintf(topic_str,"%s",topic); + + // 必须转换成python环境的变量,否则函数退出后,topic里的是个空指针 + memset(topic_str, 0, sizeof(topic_str)); + sprintf(topic_str, "%s", topic); obj_setStr(self, topic_str, topic); - ret = mqtt_subscribe(_client, obj_getStr(self, topic_str), qos, Subscribe_Handler); + ret = mqtt_subscribe(_client, obj_getStr(self, topic_str), qos, + Subscribe_Handler); if (ret == 0) { - // __platform_printf("MQTT_subscribe Topic :%s Qos:%d OK\r\n", topic,qos); - //注册mqtt订阅主题的 回调函数 - if(cb != NULL) { - memset(topic_str,0,sizeof(topic_str)); - // sprintf(topic_str,"eventCallBack_%s",topic); - sprintf(topic_str,"eventCallBack"); - // __platform_printf("topic_str:%s \r\n",topic_str); - obj_setArg(self, topic_str, cb); + // __platform_printf("MQTT_subscribe Topic :%s Qos:%d OK\r\n", + // topic,qos); + // 注册mqtt订阅主题的 回调函数 + if (cb != NULL) { + char hash_str[32] = {0}; + memset(hash_str, 0, sizeof(hash_str)); + sprintf(hash_str, "C%d", hash_time33(topic)); + obj_newDirectObj(self, hash_str, New_TinyObj); + PikaObj* eventHandler = obj_getPtr(self, hash_str); + obj_setArg(eventHandler, "eventCallBack", cb); /* init event_listener for the first time */ if (NULL == g_mqtt_event_listener) { - pks_eventLisener_init(&g_mqtt_event_listener); + pks_eventListener_init(&g_mqtt_event_listener); } uint32_t eventId = hash_time33(topic_str); - // __platform_printf("hash_time33(topic_str):%d \r\n",hash_time33(topic_str)); - pks_eventLicener_registEvent(g_mqtt_event_listener, eventId, self); + pks_eventListener_registEvent(g_mqtt_event_listener, eventId, + eventHandler); } } else __platform_printf("MQTT_subscribe Topic ERROR\r\n"); - + return ret; } @@ -583,33 +590,34 @@ int _mqtt__MQTT_unsubscribe(PikaObj* self, char* topic) { // 返 回 值:0=成功;非0=错误码 /////////////////////////////////////////////////////////////////// void Subscribe_Handler(void* client, message_data_t* msg) { - char topic_str[MQTT_TOPIC_LEN_MAX+24]; + char topic_str[MQTT_TOPIC_LEN_MAX + 24]; PikaObj* self = ((mqtt_client_t*)client)->user_data; char hash_str[32] = {0}; - //防止数组越界 - memset(topic_str,0,sizeof(topic_str)); - if(strlen(msg->topic_name) <= MQTT_TOPIC_LEN_MAX) + // 防止数组越界 + memset(topic_str, 0, sizeof(topic_str)); + if (strlen(msg->topic_name) <= MQTT_TOPIC_LEN_MAX) // sprintf(topic_str,"eventCallBack_%s",msg->topic_name); - sprintf(topic_str,"eventCallBack"); + sprintf(topic_str, "eventCallBack"); else { - sprintf(topic_str,"eventCallBack_"); - memcpy((topic_str+strlen("eventCallBack_")),msg->topic_name,MQTT_TOPIC_LEN_MAX); + sprintf(topic_str, "eventCallBack_"); + memcpy((topic_str + strlen("eventCallBack_")), msg->topic_name, + MQTT_TOPIC_LEN_MAX); } - - pks_eventLisener_sendSignal(g_mqtt_event_listener, - hash_time33(topic_str), hash_time33(msg->topic_name)); - - memset(hash_str,0,sizeof(hash_str)); - sprintf(hash_str,"M%d",hash_time33(msg->topic_name)); + + pks_eventListener_sendSignal(g_mqtt_event_listener, hash_time33(topic_str), + hash_time33(msg->topic_name)); + + memset(hash_str, 0, sizeof(hash_str)); + sprintf(hash_str, "M%d", hash_time33(msg->topic_name)); obj_setStr(self, hash_str, (char*)msg->message->payload); - memset(hash_str,0,sizeof(hash_str)); - sprintf(hash_str,"T%d",hash_time33(msg->topic_name)); + memset(hash_str, 0, sizeof(hash_str)); + sprintf(hash_str, "T%d", hash_time33(msg->topic_name)); obj_setStr(self, hash_str, (char*)msg->topic_name); - memset(hash_str,0,sizeof(hash_str)); - sprintf(hash_str,"Q%d",hash_time33(msg->topic_name)); + memset(hash_str, 0, sizeof(hash_str)); + sprintf(hash_str, "Q%d", hash_time33(msg->topic_name)); obj_setInt(self, hash_str, msg->message->qos); // MQTT_LOG_I("\n>>>------------------"); @@ -626,7 +634,7 @@ void Subscribe_Handler(void* client, message_data_t* msg) { /////////////////////////////////////////////////////////////////// void _mqtt___del__(PikaObj* self) { if (NULL != g_mqtt_event_listener) { - pks_eventLisener_deinit(&g_mqtt_event_listener); + pks_eventListener_deinit(&g_mqtt_event_listener); } } @@ -636,12 +644,12 @@ void _mqtt___del__(PikaObj* self) { // 输入参数: // 返 回 值: /////////////////////////////////////////////////////////////////// -char* _mqtt__MQTT_getMsg(PikaObj *self, int signal) { +char* _mqtt__MQTT_getMsg(PikaObj* self, int signal) { // mqtt_client_t* _client = obj_getPtr(self, "_client"); char hash_str[32]; - memset(hash_str,0,sizeof(hash_str)); - sprintf(hash_str,"M%d",signal); + memset(hash_str, 0, sizeof(hash_str)); + sprintf(hash_str, "M%d", signal); return (obj_getStr(self, hash_str)); } @@ -651,11 +659,11 @@ char* _mqtt__MQTT_getMsg(PikaObj *self, int signal) { // 输入参数: // 返 回 值: /////////////////////////////////////////////////////////////////// -char* _mqtt__MQTT_getTopic(PikaObj *self, int signal) { +char* _mqtt__MQTT_getTopic(PikaObj* self, int signal) { char hash_str[32]; - memset(hash_str,0,sizeof(hash_str)); - sprintf(hash_str,"T%d",signal); + memset(hash_str, 0, sizeof(hash_str)); + sprintf(hash_str, "T%d", signal); return (obj_getStr(self, hash_str)); } @@ -665,11 +673,11 @@ char* _mqtt__MQTT_getTopic(PikaObj *self, int signal) { // 输入参数: // 返 回 值: /////////////////////////////////////////////////////////////////// -int _mqtt__MQTT_getQos(PikaObj *self, int signal) { +int _mqtt__MQTT_getQos(PikaObj* self, int signal) { char hash_str[32]; - memset(hash_str,0,sizeof(hash_str)); - sprintf(hash_str,"Q%d",signal); + memset(hash_str, 0, sizeof(hash_str)); + sprintf(hash_str, "Q%d", signal); return (obj_getInt(self, hash_str)); } @@ -679,7 +687,7 @@ int _mqtt__MQTT_getQos(PikaObj *self, int signal) { // 输入参数: // 返 回 值: /////////////////////////////////////////////////////////////////// -int _mqtt__MQTT_setDisconnectHandler(PikaObj *self, Arg* cb) { +int _mqtt__MQTT_setDisconnectHandler(PikaObj* self, Arg* cb) { // mqtt_client_t* _client = obj_getPtr(self, "_client"); __platform_printf("_mqtt__MQTT_setDisconnectHandler\r\n"); diff --git a/src/PikaObj.c b/src/PikaObj.c index 9c833a8f1..7bb0399c3 100644 --- a/src/PikaObj.c +++ b/src/PikaObj.c @@ -1552,7 +1552,7 @@ char* obj_toStr(PikaObj* self) { return obj_getStr(self, "__res"); } -void pks_eventLicener_registEvent(PikaEventListener* self, +void pks_eventListener_registEvent(PikaEventListener* self, uint32_t eventId, PikaObj* eventHandleObj) { Args buffs = {0}; @@ -1564,7 +1564,7 @@ void pks_eventLicener_registEvent(PikaEventListener* self, strsDeinit(&buffs); } -void pks_eventLicener_removeEvent(PikaEventListener* self, uint32_t eventId) { +void pks_eventListener_removeEvent(PikaEventListener* self, uint32_t eventId) { Args buffs = {0}; char* event_name = strsFormat(&buffs, PIKA_SPRINTF_BUFF_SIZE, "%ld", eventId); @@ -1572,7 +1572,7 @@ void pks_eventLicener_removeEvent(PikaEventListener* self, uint32_t eventId) { strsDeinit(&buffs); } -PikaObj* pks_eventLisener_getEventHandleObj(PikaEventListener* self, +PikaObj* pks_eventListener_getEventHandleObj(PikaEventListener* self, uint32_t eventId) { Args buffs = {0}; char* event_name = @@ -1583,21 +1583,21 @@ PikaObj* pks_eventLisener_getEventHandleObj(PikaEventListener* self, return eventHandleObj; } -void pks_eventLisener_init(PikaEventListener** p_self) { +void pks_eventListener_init(PikaEventListener** p_self) { *p_self = newNormalObj(New_TinyObj); } -void pks_eventLisener_deinit(PikaEventListener** p_self) { +void pks_eventListener_deinit(PikaEventListener** p_self) { if (NULL != *p_self) { obj_deinit(*p_self); *p_self = NULL; } } -Arg* __eventLisener_runEvent(PikaEventListener* lisener, +Arg* __eventListener_runEvent(PikaEventListener* lisener, uint32_t eventId, int eventSignal) { - PikaObj* handler = pks_eventLisener_getEventHandleObj(lisener, eventId); + PikaObj* handler = pks_eventListener_getEventHandleObj(lisener, eventId); if (NULL == handler) { __platform_printf( "Error: can not find event handler by id: [0x%02x]\r\n", eventId); @@ -1625,7 +1625,7 @@ Arg* __eventLisener_runEvent(PikaEventListener* lisener, return res; } -void pks_eventLisener_sendSignal(PikaEventListener* self, +void pks_eventListener_sendSignal(PikaEventListener* self, uint32_t eventId, int eventSignal) { #if !PIKA_EVENT_ENABLE @@ -1648,7 +1648,7 @@ void pks_eventLisener_sendSignal(PikaEventListener* self, #endif } -Arg* pks_eventLisener_sendSignalAwaitResult(PikaEventListener* self, +Arg* pks_eventListener_sendSignalAwaitResult(PikaEventListener* self, uint32_t eventId, int eventSignal) { /* @@ -1661,7 +1661,7 @@ Arg* pks_eventLisener_sendSignalAwaitResult(PikaEventListener* self, #else extern volatile VMSignal PikaVMSignal; int tail = PikaVMSignal.cq.tail; - pks_eventLisener_sendSignal(self, eventId, eventSignal); + pks_eventListener_sendSignal(self, eventId, eventSignal); while (1) { Arg* res = PikaVMSignal.cq.res[tail]; __platform_thread_delay(); diff --git a/src/PikaObj.h b/src/PikaObj.h index 5d885d8e1..8e9bf1c24 100644 --- a/src/PikaObj.h +++ b/src/PikaObj.h @@ -342,21 +342,21 @@ enum shellCTRL obj_runChar(PikaObj* self, char inputChar); typedef PikaObj PikaEventListener; -void pks_eventLisener_sendSignal(PikaEventListener* self, +void pks_eventListener_sendSignal(PikaEventListener* self, uint32_t eventId, int eventSignal); -void pks_eventLicener_registEvent(PikaEventListener* self, +void pks_eventListener_registEvent(PikaEventListener* self, uint32_t eventId, PikaObj* eventHandleObj); -void pks_eventLicener_removeEvent(PikaEventListener* self, uint32_t eventId); +void pks_eventListener_removeEvent(PikaEventListener* self, uint32_t eventId); -PikaObj* pks_eventLisener_getEventHandleObj(PikaEventListener* self, +PikaObj* pks_eventListener_getEventHandleObj(PikaEventListener* self, uint32_t eventId); -void pks_eventLisener_init(PikaEventListener** p_self); -void pks_eventLisener_deinit(PikaEventListener** p_self); +void pks_eventListener_init(PikaEventListener** p_self); +void pks_eventListener_deinit(PikaEventListener** p_self); PikaObj* methodArg_getDefContext(Arg* method_arg); PikaObj* Obj_linkLibraryFile(PikaObj* self, char* input_file_name); NewFun obj_getClass(PikaObj* obj); @@ -499,10 +499,10 @@ void _obj_updateProxyFlag(PikaObj* self); _obj_updateProxyFlag((_self)) Arg* _obj_getProp(PikaObj* obj, char* name); -Arg* __eventLisener_runEvent(PikaEventListener* lisener, +Arg* __eventListener_runEvent(PikaEventListener* lisener, uint32_t eventId, int eventSignal); -Arg* pks_eventLisener_sendSignalAwaitResult(PikaEventListener* self, +Arg* pks_eventListener_sendSignalAwaitResult(PikaEventListener* self, uint32_t eventId, int eventSignal); diff --git a/src/PikaVM.c b/src/PikaVM.c index 66298280a..1eeb4ae4c 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -136,7 +136,7 @@ void VMSignale_pickupEvent(void) { if (PIKA_RES_OK == VMSignal_popEvent(&event_lisener, &event_id, &event_signal, &head)) { Arg* res = - __eventLisener_runEvent(event_lisener, event_id, event_signal); + __eventListener_runEvent(event_lisener, event_id, event_signal); PikaVMSignal.cq.res[head] = res; } #endif diff --git a/test/event-test.cpp b/test/event-test.cpp index 94b5fdbbe..e7a616538 100644 --- a/test/event-test.cpp +++ b/test/event-test.cpp @@ -14,9 +14,9 @@ TEST(event, gpio) { #define GPIO_PA8_EVENT_ID 0x08 /* simulate run in the call back */ - pks_eventLisener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID, + pks_eventListener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID, EVENT_SIGAL_IO_RISING_EDGE); - pks_eventLisener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID, + pks_eventListener_sendSignal(g_pika_device_event_listener, GPIO_PA8_EVENT_ID, EVENT_SIGAL_IO_FALLING_EDGE); /* assert */ @@ -32,9 +32,9 @@ TEST(event, gpio) { } /* simulate run in the call back */ - Arg* res_123 = pks_eventLisener_sendSignalAwaitResult( + Arg* res_123 = pks_eventListener_sendSignalAwaitResult( g_pika_device_event_listener, GPIO_PA8_EVENT_ID, 123); - Arg* res_456 = pks_eventLisener_sendSignalAwaitResult( + Arg* res_456 = pks_eventListener_sendSignalAwaitResult( g_pika_device_event_listener, GPIO_PA8_EVENT_ID, 456); EXPECT_EQ(arg_getInt(res_123), 123); @@ -50,16 +50,16 @@ TEST(event, remove_regist) { /* init */ PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain); /* run */ - pks_eventLisener_init(&g_pika_device_event_listener); + pks_eventListener_init(&g_pika_device_event_listener); PikaObj* testobj = newNormalObj(New_TinyObj); - pks_eventLicener_registEvent(g_pika_device_event_listener, 0, testobj); + pks_eventListener_registEvent(g_pika_device_event_listener, 0, testobj); EXPECT_EQ(testobj->refcnt, 2); - pks_eventLicener_removeEvent(g_pika_device_event_listener, 0); + pks_eventListener_removeEvent(g_pika_device_event_listener, 0); EXPECT_EQ(testobj->refcnt, 1); /* deinit */ obj_deinit(pikaMain); obj_deinit(testobj); - pks_eventLisener_deinit(&g_pika_device_event_listener); + pks_eventListener_deinit(&g_pika_device_event_listener); EXPECT_EQ(pikaMemNow(), 0); }