/* DBusTimeoutToggledFunction callback for pa mainloop */ static void toggle_timeout(DBusTimeout *timeout, void *data) { struct timeout_data *d = data; pa_time_event *ev; struct timeval tv; pa_assert(d); pa_assert(d->connection); pa_assert(timeout); pa_assert_se(ev = dbus_timeout_get_data(timeout)); if (dbus_timeout_get_enabled(timeout)) d->connection->mainloop->time_restart(ev, pa_timeval_rtstore(&tv, pa_rtclock_now() + dbus_timeout_get_interval(timeout) * PA_USEC_PER_MSEC, d->connection->use_rtclock)); else d->connection->mainloop->time_restart(ev, pa_timeval_rtstore(&tv, PA_USEC_INVALID, d->connection->use_rtclock)); }
void pa_core_rttime_restart(pa_core *c, pa_time_event *e, pa_usec_t usec) { struct timeval tv; pa_assert(c); pa_assert(c->mainloop); c->mainloop->time_restart(e, pa_timeval_rtstore(&tv, usec, true)); }
pa_time_event* pa_core_rttime_new(pa_core *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata) { struct timeval tv; pa_assert(c); pa_assert(c->mainloop); return c->mainloop->time_new(c->mainloop, pa_timeval_rtstore(&tv, usec, true), cb, userdata); }
int main(int argc, char *argv[]) { pa_mainloop_api *a; pa_io_event *ioe; pa_time_event *te; struct timeval tv; #ifdef GLIB_MAIN_LOOP pa_glib_mainloop *g; glib_main_loop = g_main_loop_new(NULL, FALSE); assert(glib_main_loop); g = pa_glib_mainloop_new(NULL); assert(g); a = pa_glib_mainloop_get_api(g); assert(a); #else /* GLIB_MAIN_LOOP */ pa_mainloop *m; m = pa_mainloop_new(); assert(m); a = pa_mainloop_get_api(m); assert(a); #endif /* GLIB_MAIN_LOOP */ ioe = a->io_new(a, 0, PA_IO_EVENT_INPUT, iocb, NULL); assert(ioe); de = a->defer_new(a, dcb, NULL); assert(de); te = a->time_new(a, pa_timeval_rtstore(&tv, pa_rtclock_now() + 2 * PA_USEC_PER_SEC, TRUE), tcb, NULL); #if defined(GLIB_MAIN_LOOP) g_main_loop_run(glib_main_loop); #else pa_mainloop_run(m, NULL); #endif a->time_free(te); a->defer_free(de); a->io_free(ioe); #ifdef GLIB_MAIN_LOOP pa_glib_mainloop_free(g); g_main_loop_unref(glib_main_loop); #else pa_mainloop_free(m); #endif return 0; }
pa_time_event* pa_context_rttime_new(pa_context *c, pa_usec_t usec, pa_time_event_cb_t cb, void *userdata) { struct timeval tv; pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); pa_assert(c->mainloop); if (usec == PA_USEC_INVALID) return c->mainloop->time_new(c->mainloop, NULL, cb, userdata); pa_timeval_rtstore(&tv, usec, c->use_rtclock); return c->mainloop->time_new(c->mainloop, &tv, cb, userdata); }
void pa_context_rttime_restart(pa_context *c, pa_time_event *e, pa_usec_t usec) { struct timeval tv; pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); pa_assert(c->mainloop); if (usec == PA_USEC_INVALID) c->mainloop->time_restart(e, NULL); else { pa_timeval_rtstore(&tv, usec, c->use_rtclock); c->mainloop->time_restart(e, &tv); } }
/* pa_time_event_cb_t timer event handler */ static void handle_time_event(pa_mainloop_api *ea, pa_time_event* e, const struct timeval *t, void *userdata) { struct timeval tv; struct timeout_data *d = userdata; pa_assert(d); pa_assert(d->connection); if (dbus_timeout_get_enabled(d->timeout)) { /* Restart it for the next scheduled time. We do this before * calling dbus_timeout_handle() to make sure that the time * event is still around. */ ea->time_restart(e, pa_timeval_rtstore(&tv, pa_timeval_load(t) + dbus_timeout_get_interval(d->timeout) * PA_USEC_PER_MSEC, d->connection->use_rtclock)); dbus_timeout_handle(d->timeout); } }
/* DBusAddTimeoutFunction callback for pa mainloop */ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) { pa_dbus_wrap_connection *c = data; pa_time_event *ev; struct timeval tv; struct timeout_data *d; pa_assert(timeout); pa_assert(c); if (!dbus_timeout_get_enabled(timeout)) return FALSE; d = pa_xnew(struct timeout_data, 1); d->connection = c; d->timeout = timeout; ev = c->mainloop->time_new(c->mainloop, pa_timeval_rtstore(&tv, pa_rtclock_now() + dbus_timeout_get_interval(timeout) * PA_USEC_PER_MSEC, c->use_rtclock), handle_time_event, d); c->mainloop->time_set_destroy(ev, time_event_destroy_cb); dbus_timeout_set_data(timeout, ev, NULL); return TRUE; }