2 This file is part of PulseAudio.
4 Copyright 2006 Lennart Poettering
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.
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
26 #include <pulse/xmalloc.h>
28 #include <pulsecore/macro.h>
30 #include "hook-list.h"
32 void pa_hook_init(pa_hook
*hook
, void *data
) {
35 PA_LLIST_HEAD_INIT(pa_hook_slot
, hook
->slots
);
36 hook
->n_dead
= hook
->n_firing
= 0;
40 static void slot_free(pa_hook
*hook
, pa_hook_slot
*slot
) {
44 PA_LLIST_REMOVE(pa_hook_slot
, hook
->slots
, slot
);
49 void pa_hook_done(pa_hook
*hook
) {
51 pa_assert(hook
->n_firing
== 0);
54 slot_free(hook
, hook
->slots
);
56 pa_hook_init(hook
, NULL
);
59 pa_hook_slot
* pa_hook_connect(pa_hook
*hook
, pa_hook_priority_t prio
, pa_hook_cb_t cb
, void *data
) {
60 pa_hook_slot
*slot
, *where
, *prev
;
64 slot
= pa_xnew(pa_hook_slot
, 1);
69 slot
->priority
= prio
;
72 for (where
= hook
->slots
; where
; where
= where
->next
) {
73 if (prio
< where
->priority
)
78 PA_LLIST_INSERT_AFTER(pa_hook_slot
, hook
->slots
, prev
, slot
);
83 void pa_hook_slot_free(pa_hook_slot
*slot
) {
85 pa_assert(!slot
->dead
);
87 if (slot
->hook
->n_firing
> 0) {
91 slot_free(slot
->hook
, slot
);
94 pa_hook_result_t
pa_hook_fire(pa_hook
*hook
, void *data
) {
95 pa_hook_slot
*slot
, *next
;
96 pa_hook_result_t result
= PA_HOOK_OK
;
102 PA_LLIST_FOREACH(slot
, hook
->slots
) {
106 if ((result
= slot
->callback(hook
->data
, data
, slot
->data
)) != PA_HOOK_OK
)
111 pa_assert(hook
->n_firing
>= 0);
113 for (slot
= hook
->slots
; hook
->n_dead
> 0 && slot
; slot
= next
) {
117 slot_free(hook
, slot
);
122 pa_assert(hook
->n_dead
== 0);
127 pa_bool_t
pa_hook_is_firing(pa_hook
*hook
) {
130 return hook
->n_firing
> 0;