]>
code.delx.au - pulseaudio/blob - src/pulsecore/hook-list.c
4 This file is part of PulseAudio.
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 of the
9 License, or (at your option) any later version.
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 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 #include <pulsecore/hook-list.h>
24 void pa_hook_init(pa_hook
*hook
, void *data
) {
27 PA_LLIST_HEAD_INIT(pa_hook_slot
, hook
->slots
);
29 hook
->n_dead
= hook
->firing
= 0;
33 static void slot_free(pa_hook
*hook
, pa_hook_slot
*slot
) {
37 if (hook
->last
== slot
)
38 hook
->last
= slot
->prev
;
40 PA_LLIST_REMOVE(pa_hook_slot
, hook
->slots
, slot
);
45 void pa_hook_free(pa_hook
*hook
) {
47 assert(!hook
->firing
);
50 slot_free(hook
, hook
->slots
);
52 pa_hook_init(hook
, NULL
);
55 pa_hook_slot
* pa_hook_connect(pa_hook
*hook
, pa_hook_cb_t cb
, void *data
) {
60 slot
= pa_xnew(pa_hook_slot
, 1);
66 PA_LLIST_INSERT_AFTER(pa_hook_slot
, hook
->slots
, hook
->last
, slot
);
72 void pa_hook_slot_free(pa_hook_slot
*slot
) {
76 if (slot
->hook
->firing
> 0) {
80 slot_free(slot
->hook
, slot
);
83 pa_hook_result_t
pa_hook_fire(pa_hook
*hook
, void *data
) {
84 pa_hook_slot
*slot
, *next
;
85 pa_hook_result_t result
= PA_HOOK_OK
;
91 for (slot
= hook
->slots
; slot
; slot
= slot
->next
) {
95 if ((result
= slot
->callback(hook
->data
, data
, slot
->data
)) != PA_HOOK_OK
)
101 for (slot
= hook
->slots
; hook
->n_dead
> 0 && slot
; slot
= next
) {
105 slot_free(hook
, slot
);