X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fblackbox%2Fcommon%2Fmesh_event_handler.c;h=17b5abaf750ef3f7a33fddf21ca177babf547bd1;hb=fbcf08931e531fc2bd4a7e42d0ab03fed26fb9fc;hp=1b7ebe92aec61dd15eee952320313591d7b9f33c;hpb=1c04402a6d2f3a85d0cb4a5b4a6db5b1f3a79511;p=meshlink diff --git a/test/blackbox/common/mesh_event_handler.c b/test/blackbox/common/mesh_event_handler.c index 1b7ebe92..17b5abaf 100644 --- a/test/blackbox/common/mesh_event_handler.c +++ b/test/blackbox/common/mesh_event_handler.c @@ -16,6 +16,11 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + +#ifdef NDEBUG +#undef NDEBUG +#endif + #include #include #include @@ -38,6 +43,16 @@ #define SERVER_LISTEN_PORT "9000" /* Port number that is binded with mesh event server socket */ #define UDP_BUFF_MAX 2000 +const char *event_status[] = { + [NODE_STARTED] = "Node Started", + [NODE_JOINED] = "Node Joined", + [ERR_NETWORK] = "Network Error", + [CHANNEL_OPENED] = "Channel Opened", + [CHANNEL_DATA_RECIEVED] = "Channel Data Received", + [SIG_ABORT] = "SIG_ABORT Received", + [MESH_EVENT_COMPLETED] = "MESH_EVENT_COMPLETED Received" +}; + // TODO: Implement mesh event handling with reentrancy . static struct sockaddr_in server_addr; static int client_fd = -1; @@ -73,6 +88,7 @@ static bool wait_cond_flag(struct cond_flag *s, int seconds) { // event_receive_handler running in a separate thread queues all the events received from the UDP port static void *event_receive_handler(void *arg) { + (void)arg; size_t recv_ret; char udp_buff[UDP_BUFF_MAX]; struct sockaddr client; @@ -110,7 +126,7 @@ static void *event_handler(void *argv) { bool callback_return = false; void *data; mesh_event_payload_t mesh_event_rec_packet; - mesh_event_callback_t callback = (mesh_event_callback_t)argv; + mesh_event_callback_t callback = *(mesh_event_callback_t *)argv; while(event_handle_thread_running) { @@ -163,7 +179,7 @@ char *mesh_event_sock_create(const char *if_name) { server.sin_port = htons(atoi(SERVER_LISTEN_PORT)); assert(bind(server_fd, (struct sockaddr *) &server, sizeof(struct sockaddr)) != -1); - assert(ip = malloc(30)); + assert((ip = malloc(30))); strncpy(ip, inet_ntoa(resp_if_addr->sin_addr), 20); strcat(ip, ":"); strcat(ip, SERVER_LISTEN_PORT); @@ -245,7 +261,7 @@ bool wait_for_event(mesh_event_callback_t callback, int seconds) { } set_cond_flag(&sync_event, false); - assert(!pthread_create(&event_handle_thread, NULL, event_handler, (void *)callback)); + assert(!pthread_create(&event_handle_thread, NULL, event_handler, (void *)&callback)); bool wait_ret = wait_cond_flag(&sync_event, seconds); event_handle_thread_running = false; pthread_cancel(event_handle_thread); @@ -270,4 +286,3 @@ void mesh_event_destroy(void) { event_receive_thread_running = false; pthread_cancel(event_receive_thread); } -