From 57e473b61cf373f8d9befb03d359b999eca4262b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 4 Sep 2004 00:27:36 +0000 Subject: add support for automatic termination of the daemon after the last client quit remove all gcc warnings add boolean types for tagstruct and modargs git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@178 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/core.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'polyp/core.c') diff --git a/polyp/core.c b/polyp/core.c index da6ace6a..4362f0cb 100644 --- a/polyp/core.c +++ b/polyp/core.c @@ -71,6 +71,9 @@ struct pa_core* pa_core_new(struct pa_mainloop_api *m) { c->memblock_stat = pa_memblock_stat_new(); c->disallow_module_loading = 0; + + c->quit_event = NULL; + c->quit_after_last_client_time = -1; pa_check_for_sigpipe(); @@ -102,6 +105,11 @@ void pa_core_free(struct pa_core *c) { pa_namereg_free(c); pa_autoload_free(c); pa_subscription_free_all(c); + + if (c->quit_event) { + c->mainloop->time_free(c->quit_event); + c->quit_event = NULL; + } pa_xfree(c->default_source_name); pa_xfree(c->default_sink_name); @@ -111,3 +119,23 @@ void pa_core_free(struct pa_core *c) { pa_xfree(c); } +static void quit_callback(struct pa_mainloop_api*m, struct pa_time_event *e, const struct timeval *tv, void *userdata) { + struct pa_core *c = userdata; + assert(c->quit_event = e); + + m->quit(m, 0); +} + +void pa_core_check_quit(struct pa_core *c) { + assert(c); + + if (!c->quit_event && c->quit_after_last_client_time >= 0 && pa_idxset_ncontents(c->clients) == 0) { + struct timeval tv; + gettimeofday(&tv, NULL); + tv.tv_sec+= c->quit_after_last_client_time; + c->quit_event = c->mainloop->time_new(c->mainloop, &tv, quit_callback, c); + } else if (c->quit_event && pa_idxset_ncontents(c->clients) > 0) { + c->mainloop->time_free(c->quit_event); + c->quit_event = NULL; + } +} -- cgit