int App::message_loop() { MSG msg; long prev_time = timeGetTime(), time; while(true) { time = timeGetTime(); if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if(! GetMessage(&msg, NULL, 0, 0)) break; dispatch_msg(msg); } else if(time - prev_time > 20) { idle(); prev_time = time; } } return msg.wParam; }
void msg_loop(msgdisp_t disp,uint32_t ms) { uint64_t nowtick = GetSystemMs64(); uint64_t timeout = nowtick+(uint64_t)ms; do{ msg_t _msg = NULL; uint32_t sleeptime = (uint32_t)(timeout - nowtick); msgque_get(disp->mq,(lnode**)&_msg,sleeptime); if(_msg) dispatch_msg(disp,_msg); nowtick = GetSystemMs(); }while(nowtick < timeout); }
void ant_handle_msg(void) { uint8_t msg_n = 0;; uint8_t in_msg = FALSE; pop_value value; while(1) { value = rb_pop(&rx_ring); // Nothing to read and we're not waiting on a message if (value.success == 0 && in_msg == FALSE) return; // We must be waiting for a byte if (value.success == 0 && in_msg == TRUE) continue; if ((value.byte == MESG_TX_SYNC) && (in_msg == FALSE)) { msg_n = 0; // Always reset when we receive a sync header in_msg = TRUE; rx_buf[msg_n] = value.byte; msg_n++; } else if (msg_n == 1) { // Size rx_buf[msg_n] = value.byte; msg_n++; } else if (msg_n == 2) { // Type rx_buf[msg_n] = value.byte; msg_n++; } else if (msg_n < rx_buf[1] + 3) { rx_buf[msg_n] = value.byte; msg_n++; } else { in_msg = FALSE; rx_buf[msg_n] = value.byte; if (checksum(rx_buf, msg_n) == rx_buf[msg_n]) { dispatch_msg(msg_n); } else { printf("checksum failed\n"); } break; } } }
/** * @brief Wait for message received * * @param msg_handler Callback for message processing * @param msg_info Handler for epoll and listen socket */ void msg_run(struct msg_info *msg_info, msg_handler_fn_t msg_handler) { struct epoll_event events[MAXEVENTS]; struct epoll_event *event; int n, i; int fd; int ret = -1; int efd = msg_info->efd; int listen_fd = msg_info->listen_fd; while (1) { n = epoll_wait(efd, events, MAXEVENTS, -1); if (-1 == n) { DEBUG_ERROR("epoll wait error\n"); break; } for (i = 0; i < n; i++) { event = &events[i]; fd = event->data.fd; if (listen_fd == fd) { ret = new_connect(listen_fd, efd); if (0 != ret) { printf("accept error\n"); } } else { ret = dispatch_msg(efd, event, msg_handler); if (0 != ret) { printf("Dispatch message failed\n"); } } } } }
void widget_dispatch_event(widget_t* w, event_t* event) { switch (event->id) { case EVT_PAINT: break; case EVT_TOUCH_UP: case EVT_TOUCH_DOWN: dispatch_touch(w, (touch_event_t*)event); break; case EVT_MSG: dispatch_msg(w, (msg_event_t*)event); break; default: break; } }
/* dispatches buffered incoming messages to handlers, returns number of messages left to dispatch or negative on error */ int dbus_msg_queue_dispatch(dbus_msg_queue *q) { dbus_msg *msg = NULL; int rv = 0; if ( q->incoming_count == 0 ) { return 0; } msg = q->incoming[0]; rv = array_entry_remove( 0, sizeof(dbus_msg*), (void**)&q->incoming, &q->incoming_count ); if (rv < 0) { fprintf(stderr, "remove element failed\n"); return rv; } rv = dispatch_msg( q, msg ); if (rv < 0) { fprintf(stderr, "dispatch_msg failed\n"); dbus_msg_free( msg ); return rv; } dbus_msg_free( msg ); return q->incoming_count; }
void ws_onmessage(const char* p_msg) { log_debug("ws_onmessage"); log_trace("message received: %s", p_msg); dispatch_msg(p_msg); }