2006-08-13 01:43:34 +00:00
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2006 Lennart Poettering
|
|
|
|
|
|
2006-08-13 01:43:34 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
2009-03-03 20:23:02 +00:00
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
2006-08-13 01:43:34 +00:00
|
|
|
License, or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 01:43:34 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 01:43:34 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with PulseAudio; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-06-13 15:04:33 +02:00
|
|
|
#include <pulse/xmalloc.h>
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
#include <pulsecore/macro.h>
|
|
|
|
|
|
|
|
|
|
#include "hook-list.h"
|
2006-08-13 01:43:34 +00:00
|
|
|
|
2006-08-13 16:13:36 +00:00
|
|
|
void pa_hook_init(pa_hook *hook, void *data) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(hook);
|
2006-08-13 01:43:34 +00:00
|
|
|
|
2006-08-17 20:03:38 +00:00
|
|
|
PA_LLIST_HEAD_INIT(pa_hook_slot, hook->slots);
|
2008-06-11 19:45:57 +00:00
|
|
|
hook->n_dead = hook->n_firing = 0;
|
2006-08-13 16:13:36 +00:00
|
|
|
hook->data = data;
|
2006-08-13 01:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void slot_free(pa_hook *hook, pa_hook_slot *slot) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(hook);
|
|
|
|
|
pa_assert(slot);
|
2006-08-13 01:43:34 +00:00
|
|
|
|
|
|
|
|
PA_LLIST_REMOVE(pa_hook_slot, hook->slots, slot);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 01:43:34 +00:00
|
|
|
pa_xfree(slot);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-03 16:21:08 +02:00
|
|
|
void pa_hook_done(pa_hook *hook) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(hook);
|
2008-06-11 19:45:57 +00:00
|
|
|
pa_assert(hook->n_firing == 0);
|
2006-08-13 01:43:34 +00:00
|
|
|
|
|
|
|
|
while (hook->slots)
|
|
|
|
|
slot_free(hook, hook->slots);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 16:13:36 +00:00
|
|
|
pa_hook_init(hook, NULL);
|
2006-08-13 01:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
2008-06-11 19:45:57 +00:00
|
|
|
pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_priority_t prio, pa_hook_cb_t cb, void *data) {
|
|
|
|
|
pa_hook_slot *slot, *where, *prev;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(cb);
|
2006-08-13 01:43:34 +00:00
|
|
|
|
|
|
|
|
slot = pa_xnew(pa_hook_slot, 1);
|
|
|
|
|
slot->hook = hook;
|
2013-06-27 19:28:09 +02:00
|
|
|
slot->dead = false;
|
2006-08-13 01:43:34 +00:00
|
|
|
slot->callback = cb;
|
2006-08-13 16:13:36 +00:00
|
|
|
slot->data = data;
|
2008-06-11 19:45:57 +00:00
|
|
|
slot->priority = prio;
|
|
|
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
|
for (where = hook->slots; where; where = where->next) {
|
|
|
|
|
if (prio < where->priority)
|
|
|
|
|
break;
|
|
|
|
|
prev = where;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-11 19:45:57 +00:00
|
|
|
PA_LLIST_INSERT_AFTER(pa_hook_slot, hook->slots, prev, slot);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 01:43:34 +00:00
|
|
|
return slot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa_hook_slot_free(pa_hook_slot *slot) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(slot);
|
|
|
|
|
pa_assert(!slot->dead);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-11 19:45:57 +00:00
|
|
|
if (slot->hook->n_firing > 0) {
|
2013-06-27 19:28:09 +02:00
|
|
|
slot->dead = true;
|
2006-08-13 01:43:34 +00:00
|
|
|
slot->hook->n_dead++;
|
|
|
|
|
} else
|
|
|
|
|
slot_free(slot->hook, slot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_hook_result_t pa_hook_fire(pa_hook *hook, void *data) {
|
|
|
|
|
pa_hook_slot *slot, *next;
|
|
|
|
|
pa_hook_result_t result = PA_HOOK_OK;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_assert(hook);
|
2006-08-13 01:43:34 +00:00
|
|
|
|
2008-06-11 19:45:57 +00:00
|
|
|
hook->n_firing ++;
|
2006-08-13 01:43:34 +00:00
|
|
|
|
2009-08-15 00:55:31 +02:00
|
|
|
PA_LLIST_FOREACH(slot, hook->slots) {
|
2006-08-13 01:43:34 +00:00
|
|
|
if (slot->dead)
|
|
|
|
|
continue;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 16:13:36 +00:00
|
|
|
if ((result = slot->callback(hook->data, data, slot->data)) != PA_HOOK_OK)
|
2006-08-13 01:43:34 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-11 19:45:57 +00:00
|
|
|
hook->n_firing --;
|
|
|
|
|
pa_assert(hook->n_firing >= 0);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 01:43:34 +00:00
|
|
|
for (slot = hook->slots; hook->n_dead > 0 && slot; slot = next) {
|
|
|
|
|
next = slot->next;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-08-13 01:43:34 +00:00
|
|
|
if (slot->dead) {
|
|
|
|
|
slot_free(hook, slot);
|
|
|
|
|
hook->n_dead--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-11 19:45:57 +00:00
|
|
|
pa_assert(hook->n_dead == 0);
|
|
|
|
|
|
2006-08-13 01:43:34 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
2009-03-21 01:18:48 +01:00
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
bool pa_hook_is_firing(pa_hook *hook) {
|
2009-03-21 01:18:48 +01:00
|
|
|
pa_assert(hook);
|
|
|
|
|
|
|
|
|
|
return hook->n_firing > 0;
|
|
|
|
|
}
|