/* add a fd based event return NULL on failure (memory allocation error) */ static struct fd_event *oop_event_add_fd(struct event_context *ev, TALLOC_CTX *mem_ctx, int fd, uint16_t flags, event_fd_handler_t handler, void *private_data) { struct fd_event *fde; oop_source_sys *oop_sys = ev->additional_data; oop_source *oop = oop_sys_source(oop_sys); fde = talloc(mem_ctx?mem_ctx:ev, struct fd_event); if (!fde) return NULL; fde->event_ctx = ev; fde->fd = fd; fde->flags = flags; fde->handler = handler; fde->private_data = private_data; fde->additional_flags = 0; fde->additional_data = NULL; if (fde->flags & EVENT_FD_READ) oop->on_fd(oop, fde->fd, OOP_READ, oop_event_fd_handler, fde); if (fde->flags & EVENT_FD_WRITE) oop->on_fd(oop, fde->fd, OOP_WRITE, oop_event_fd_handler, fde); talloc_set_destructor(fde, oop_event_fd_destructor); return fde; }
/* destroy a timed event */ static int oop_event_timed_destructor(struct timed_event *te) { struct event_context *ev = te->event_ctx; oop_source_sys *oop_sys = ev->additional_data; oop_source *oop = oop_sys_source(oop_sys); oop->cancel_time(oop, te->next_event, oop_event_timed_handler, te); return 0; }
/* destroy an fd_event */ static int oop_event_fd_destructor(struct fd_event *fde) { struct event_context *ev = fde->event_ctx; oop_source_sys *oop_sys = ev->additional_data; oop_source *oop = oop_sys_source(oop_sys); if (fde->flags & EVENT_FD_READ) oop->cancel_fd(oop, fde->fd, OOP_READ); if (fde->flags & EVENT_FD_WRITE) oop->cancel_fd(oop, fde->fd, OOP_WRITE); return 0; }
static void create_oop_source(oop_source_sys **source_sys, oop_source **source) { /* Create the system event source */ *source_sys = oop_sys_new(); if (!*source_sys) { fprintf(stderr, "%s: can't create system event source: oop_sys_new() failed\n", prog_name); exit(1); } /* Get the system event registration interface */ *source = oop_sys_source(*source_sys); if (!*source) { fprintf(stderr, "%s: can't get registration interface: oop_sys_source() failed\n", prog_name); exit(1); } }
/* set the fd event flags */ static void oop_event_set_fd_flags(struct fd_event *fde, uint16_t flags) { oop_source_sys *oop_sys; oop_source *oop; oop_sys = fde->event_ctx->additional_data; oop = oop_sys_source(oop_sys); if ((fde->flags & EVENT_FD_READ)&&(!(flags & EVENT_FD_READ))) oop->cancel_fd(oop, fde->fd, OOP_READ); if ((!(fde->flags & EVENT_FD_READ))&&(flags & EVENT_FD_READ)) oop->on_fd(oop, fde->fd, OOP_READ, oop_event_fd_handler, fde); if ((fde->flags & EVENT_FD_WRITE)&&(!(flags & EVENT_FD_WRITE))) oop->cancel_fd(oop, fde->fd, OOP_WRITE); if ((!(fde->flags & EVENT_FD_WRITE))&&(flags & EVENT_FD_WRITE)) oop->on_fd(oop, fde->fd, OOP_WRITE, oop_event_fd_handler, fde); fde->flags = flags; }
/* add a timed event return NULL on failure (memory allocation error) */ static struct timed_event *oop_event_add_timed(struct event_context *ev, TALLOC_CTX *mem_ctx, struct timeval next_event, event_timed_handler_t handler, void *private_data) { oop_source_sys *oop_sys = ev->additional_data; oop_source *oop = oop_sys_source(oop_sys); struct timed_event *te; te = talloc(mem_ctx?mem_ctx:ev, struct timed_event); if (te == NULL) return NULL; te->event_ctx = ev; te->next_event = next_event; te->handler = handler; te->private_data = private_data; te->additional_data = NULL; oop->on_time(oop, te->next_event, oop_event_timed_handler, te); talloc_set_destructor(te, oop_event_timed_destructor); return te; }