1/*** 2 This file is part of PulseAudio. 3 4 Copyright 2004-2006 Lennart Poettering 5 6 PulseAudio is free software; you can redistribute it and/or modify 7 it under the terms of the GNU Lesser General Public License as 8 published by the Free Software Foundation; either version 2.1 of the 9 License, or (at your option) any later version. 10 11 PulseAudio is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 18***/ 19 20#ifdef HAVE_CONFIG_H 21#include <config.h> 22#endif 23 24#include <stdlib.h> 25 26#include <pulse/xmalloc.h> 27 28#include <pulsecore/i18n.h> 29#include <pulsecore/macro.h> 30 31#include "mainloop-api.h" 32 33struct once_info { 34 void (*callback)(pa_mainloop_api*m, void *userdata); 35 void *userdata; 36}; 37 38static void once_callback(pa_mainloop_api *m, pa_defer_event *e, void *userdata) { 39 struct once_info *i = userdata; 40 41 pa_assert(m); 42 pa_assert(i); 43 44 pa_assert(i->callback); 45 i->callback(m, i->userdata); 46 47 pa_assert(m->defer_free); 48 m->defer_free(e); 49} 50 51static void free_callback(pa_mainloop_api *m, pa_defer_event *e, void *userdata) { 52 struct once_info *i = userdata; 53 54 pa_assert(m); 55 pa_assert(i); 56 pa_xfree(i); 57} 58 59void pa_mainloop_api_once(pa_mainloop_api* m, void (*callback)(pa_mainloop_api *m, void *userdata), void *userdata) { 60 struct once_info *i; 61 pa_defer_event *e; 62 63 pa_assert(m); 64 pa_assert(callback); 65 66 pa_init_i18n(); 67 68 i = pa_xnew(struct once_info, 1); 69 i->callback = callback; 70 i->userdata = userdata; 71 72 pa_assert(m->defer_new); 73 pa_assert_se(e = m->defer_new(m, once_callback, i)); 74 m->defer_set_destroy(e, free_callback); 75} 76