/* get_num_buttons: * return the number of buttons */ static int get_num_buttons(int fd) { if (has_event(fd, EV_KEY, BTN_MIDDLE)) return 3; if (has_event(fd, EV_KEY, BTN_RIGHT)) return 2; if (has_event(fd, EV_KEY, BTN_MOUSE)) return 1; return 0; /* Not a mouse */ }
static void check_epoll_ctl(int opt, int exp_num) { int res; unsigned int events; char write_buf[] = "test"; char read_buf[sizeof(write_buf)]; struct epoll_event res_evs[2]; events = EPOLLIN; if (exp_num == 2) events |= EPOLLOUT; SAFE_WRITE(1, fd[1], write_buf, sizeof(write_buf)); while (events) { int events_matched = 0; bzero(res_evs, sizeof(res_evs)); res = epoll_wait(epfd, res_evs, 2, -1); if (res <= 0) { tst_res(TFAIL | TERRNO, "epoll_wait() returned %i", res); goto end; } if ((events & EPOLLIN) && has_event(res_evs, 2, fd[0], EPOLLIN)) { events_matched++; events &= ~EPOLLIN; } if ((events & EPOLLOUT) && has_event(res_evs, 2, fd[1], EPOLLOUT)) { events_matched++; events &= ~EPOLLOUT; } if (res != events_matched) { tst_res(TFAIL, "epoll_wait() returned unexpected events"); goto end; } } tst_res(TPASS, "epoll_ctl() succeeds with op %i", opt); end: SAFE_READ(1, fd[0], read_buf, sizeof(write_buf)); }
void USkookumScriptListener::deinitialize() { // Kill any events that are still around while (has_event()) { free_event(pop_event(), true); } // Forget the coroutine we keep track of m_coro_p.null(); // Unregister from delegate list if any if (m_unregister_callback_p && m_obj_p.IsValid()) { (*m_unregister_callback_p)(m_obj_p.Get(), this); } }
/* open_mouse_device: * Open the specified device file and check that it is a mouse device. * Returns the file descriptor if successful or a negative number on error. */ static int open_mouse_device (const char *device_file) { int fd; fd = open (device_file, O_RDONLY | O_NONBLOCK); if (fd >= 0) { TRACE(PREFIX_I "Opened device %s\n", device_file); /* The device is a mouse if it has a BTN_MOUSE */ if (has_event(fd, EV_KEY, BTN_MOUSE)) { TRACE(PREFIX_I "Device %s was a mouse.\n", device_file); } else { TRACE(PREFIX_I "Device %s was not mouse, closing.\n", device_file); close(fd); fd = -1; } } return fd; }
int main(void) { fd_set fdset; glob_t gb; size_t i; int max_fd = -2; struct fd_list *l = fdl_new(); struct fd_list *p = l; FD_ZERO(&fdset); glob("/dev/input/event*", 0, NULL, &gb); for (i = 0; i < gb.gl_pathc; i++) { char *fn = gb.gl_pathv[i]; int fd = open(fn, O_RDONLY|O_NONBLOCK); if (fd == -1) { fprintf(stderr, "pd: open %s: %s", fn, strerror(errno)); fdl_free(l); return 1; } if (!has_event(fd)) { close(fd); continue; } fdl_add(p, fd); FD_SET(fd, &fdset); max_fd = max(max_fd, fd); } for (;;) { fd_set fdset_copy = fdset; if (select(max_fd + 1, &fdset_copy, NULL, NULL, NULL) <= 0) { break; } for (p = l; p->next != NULL; p = p->next) { if (FD_ISSET(p->fd, &fdset_copy)) { process_event(p->fd); } } } fdl_free(l); return 0; }