static void emit_exit_event(Job *job) { Event event; event.type = kEventJobExit; event.data.job = job; event_push(event); }
static int wmp_done( event_t *evt ) { char buf[6]; event_t wmp_evt; /* Failure. */ if (!evt->i2c.ok) { wmp_err(); event_setCallback( EVENT_TYPE_I2C, NULL ); return 1; } /* Get the data read. */ i2cm_read( buf, sizeof(buf) ); /* Convert to 16 bit ints. */ wmp_buf[ WMP_YAW ] = ((uint16_t)buf[3] << 6) + buf[0]; wmp_buf[ WMP_PITCH ] = ((uint16_t)buf[4] << 6) + buf[1]; wmp_buf[ WMP_ROLL ] = ((uint16_t)buf[5] << 6) + buf[2]; /* Disable callback. */ event_setCallback( EVENT_TYPE_I2C, NULL ); /* Generate event. */ wmp_evt.type = EVENT_TYPE_CUSTOM; wmp_evt.custom.id = WMP_EVENT_DATA; wmp_evt.custom.data = ((buf[3] & 0x02) << 2) + buf[4]; event_push( &wmp_evt ); /* Destroy the event. */ return 1; }
int l_event_quit(lua_State *L) { int status = luaL_optnumber(L, 1, 0); event_t e; e.type = EVENT_QUIT; e.quit.status = status; event_push(&e); return 0; }
/** * @brief Generate an error event. */ static void wmp_err (void) { event_t evt; evt.type = EVENT_TYPE_CUSTOM; evt.custom.id = WMP_EVENT_ERR; evt.custom.data = 0x00; event_push( &evt ); }
static void KEYBRD_Init (uint8_t coreID, uint16_t vid, uint16_t pid) { struct event e; e.type = evt_device_change; // do nothing but signals mouse initialized e.device.port = coreID; e.device.type = device_keyboard; event_push(e); // XXX change static devices type }
static void MOUSE_Init (uint8_t coreID, uint16_t vid, uint16_t pid) { // do nothing but signals mouse initialized struct event e; e.type = evt_device_change; // do nothing but signals mouse initialized e.device.port = coreID; e.device.type = device_mouse; event_push(e); }
static void post_flow_event(int x, int y, int z, const struct timeval *delay) { Event new_ev; tv_now(&new_ev.base.time); tv_add_tv(&new_ev.base.time, delay); new_ev.base.type = EVENT_TYPE_FLOW; new_ev.flow_event.x = x; new_ev.flow_event.y = y; new_ev.flow_event.z = z; event_push(&new_ev); }
static void post_grow_event(int x, int y, int z) { Event new_ev; tv_now(&new_ev.base.time); tv_add_s( &new_ev.base.time, GROW_DELAY_MIN_SEC + rand()%(GROW_DELAY_MAX_SEC - GROW_DELAY_MIN_SEC + 1) ); new_ev.base.type = EVENT_TYPE_GROW; new_ev.grow_event.x = x; new_ev.grow_event.y = y; new_ev.grow_event.z = z; event_push(&new_ev); }
static void GAMEPAD_Init (uint8_t coreID, uint16_t vid, uint16_t pid) { gamepad_descriptor[coreID] = GAMEPAD_FindDesc(vid,pid); if (gamepad_descriptor[coreID]->vid ==0) // not found in table gamepad_descriptor[coreID] = &gamepad_parsed_descriptor[coreID]; struct event e; e.type = evt_device_change; e.device.port = coreID; e.device.type = device_gamepad; event_push(e); }
static void MOUSE_Decode(uint8_t coreID, uint8_t *data) { static uint8_t old_buttons; struct event e; if (data[1] || data[2]) { // mouse moved e.type = evt_mouse_move; e.mov.port = coreID; e.mov.x = data[1]; e.mov.y = data[2]; event_push(e); } for (int i=0;i<8;i++) { if ((data[0]&~old_buttons) & 1<<i ) // new and not old { e.type=evt_mouse_click; e.button.port = coreID; e.button.id = i; event_push(e); } if ((old_buttons & ~data[0]) & 1<<i ) // new and not old { e.type=evt_mouse_release; e.button.port = coreID; e.button.id = i; event_push(e); } } old_buttons = data[0]; // user process, no clip data_mouse_x += (int8_t) data[1]; data_mouse_y += (int8_t) data[2]; data_mouse_buttons = data[0]; }
static void emit_read_event(RStream *rstream, bool eof) { if (rstream->async) { Event event; event.type = kEventRStreamData; event.data.rstream.ptr = rstream; event.data.rstream.eof = eof; event_push(event); } else { // Invoke the callback passing in the number of bytes available and data // associated with the stream rstream->cb(rstream, rstream->data, eof); } }
static void signal_cb(uv_signal_t *handle, int signum) { if (rejecting_deadly) { if (signum == SIGINT) { got_int = true; } return; } Event event = { .type = kEventSignal, .data = { .signum = signum } }; event_push(event); }
static int wmp_on( event_t *evt ) { event_t wmp_evt; /* Failure. */ if (!evt->i2c.ok) { wmp_err(); event_setCallback( EVENT_TYPE_I2C, NULL ); return 1; } /* Generate the on event. */ wmp_evt.type = EVENT_TYPE_CUSTOM; wmp_evt.custom.id = WMP_EVENT_ON; wmp_evt.custom.data = 0x00; event_push( &wmp_evt ); return 1; }
int recv_rtnl_msg(struct event_handler *h, int sknl) { int bytes; char buf[2048]; struct nlmsghdr *nlh; memset(buf, 0, 2048); bytes = recv(sknl, buf, 2048, 0); if (bytes <= 0) { return -1; } nlh = (struct nlmsghdr *) buf; if (NLMSG_OK(nlh, bytes)) { event_push(h, nlh, bytes); //parse_rt_event(nlh, bytes); } return 0; }
/* Add event to the client's queue */ static void add_event (struct client *cli, const int event, void *data) { LOCK (cli->events_mtx); event_push (&cli->events, event, data); UNLOCK (cli->events_mtx); }
static void KEYBRD_Decode(uint8_t coreID, uint8_t *pbuf) { static uint8_t nb_last; static uint8_t keys_last[KBR_MAX_NBR_PRESSED]; // list of 0-nb_last codes of last pressed keys static uint8_t mod_last; int j; struct event e; // keyboard boot protocol : modifiers bits(Ctrl, Shift, Alt, Win L then R), reserved, char[6] // calculates New-Last & send keypresses for (int i = 2; i < 2 + KBR_MAX_NBR_PRESSED; i++) { if (pbuf[i]==0) continue; // break? // tests for errors (code 1,2 or 3) if ((unsigned)(pbuf[i]-1) <= 2) return; for (j=0; j<nb_last;j++) if (pbuf[i]==keys_last[j]) break; // not found ? if (j==nb_last) { e.type=evt_keyboard_press; e.kbd.mod=pbuf[0]; e.kbd.key=pbuf[i]; event_push(e); } } // now calculates old-new and send key released events. for (int i=0;i<nb_last;i++) { for (j=0;j<KBR_MAX_NBR_PRESSED;j++) if (pbuf[2+j]==keys_last[i]) break; // not found if (j==KBR_MAX_NBR_PRESSED) { e.type=evt_keyboard_release; e.kbd.mod=pbuf[0]; e.kbd.key=keys_last[i]; event_push(e); } } // special case : modifier keys as keypresses if (pbuf[0] != mod_last) for (int i=0;i<8;i++) { if ((pbuf[0] & ~mod_last) & (1<<i)) // new ones { e.type=evt_keyboard_press; e.kbd.key=0xE0 + i; // codes are in the same order as bits event_push(e); } if ((mod_last & ~pbuf[0]) & (1<<i)) // released ones { e.type=evt_keyboard_release; e.kbd.key=0xE0 + i; // codes are in the same order as bits event_push(e); } } // fills old keys with current nb_last=0; for (int i=0;i<KBR_MAX_NBR_PRESSED;i++) { if (pbuf[2+i]) keys_last[nb_last++]=pbuf[2+i]; } mod_last=pbuf[0]; }