static void event_sdl_remove_watch(struct event_watch *ew) { dbg(lvl_debug, "enter %p\n", ew); event_sdl_watch_stopthread(); g_ptr_array_remove(sdl_watch_list, ew); g_free(ew->pfd); g_free(ew); if (sdl_watch_list->len > 0) event_sdl_watch_startthread(sdl_watch_list); }
static struct event_watch * event_sdl_add_watch(int fd, enum event_watch_cond cond, struct callback *cb) { dbg(lvl_debug,"fd(%d) cond(%x) cb(%x)\n", fd, cond, cb); event_sdl_watch_stopthread(); if (!sdl_watch_list) sdl_watch_list = g_ptr_array_new(); struct event_watch *new_ew = g_new0 (struct event_watch, 1); struct pollfd *pfd = g_new0 (struct pollfd, 1); pfd->fd = fd; /* Modify watchlist here */ switch (cond) { case event_watch_cond_read: pfd->events = POLLIN; break; case event_watch_cond_write: pfd->events = POLLOUT; break; case event_watch_cond_except: pfd->events = POLLERR|POLLHUP; break; } new_ew->pfd = (struct pollfd*) pfd; new_ew->cb = cb; g_ptr_array_add (sdl_watch_list, (gpointer)new_ew); event_sdl_watch_startthread(sdl_watch_list); return new_ew; }