]>
code.delx.au - pulseaudio/blob - src/pulsecore/hook-list.c
4 This file is part of PulseAudio.
6 Copyright 2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
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
);
37 hook
->n_dead
= hook
->firing
= 0;
41 static void slot_free(pa_hook
*hook
, pa_hook_slot
*slot
) {
45 if (hook
->last
== slot
)
46 hook
->last
= slot
->prev
;
48 PA_LLIST_REMOVE(pa_hook_slot
, hook
->slots
, slot
);
53 void pa_hook_free(pa_hook
*hook
) {
55 pa_assert(!hook
->firing
);
58 slot_free(hook
, hook
->slots
);
60 pa_hook_init(hook
, NULL
);
63 pa_hook_slot
* pa_hook_connect(pa_hook
*hook
, pa_hook_cb_t cb
, void *data
) {
68 slot
= pa_xnew(pa_hook_slot
, 1);
74 PA_LLIST_INSERT_AFTER(pa_hook_slot
, hook
->slots
, hook
->last
, slot
);
80 void pa_hook_slot_free(pa_hook_slot
*slot
) {
82 pa_assert(!slot
->dead
);
84 if (slot
->hook
->firing
> 0) {
88 slot_free(slot
->hook
, slot
);
91 pa_hook_result_t
pa_hook_fire(pa_hook
*hook
, void *data
) {
92 pa_hook_slot
*slot
, *next
;
93 pa_hook_result_t result
= PA_HOOK_OK
;
99 for (slot
= hook
->slots
; slot
; slot
= slot
->next
) {
103 if ((result
= slot
->callback(hook
->data
, data
, slot
->data
)) != PA_HOOK_OK
)
109 for (slot
= hook
->slots
; hook
->n_dead
> 0 && slot
; slot
= next
) {
113 slot_free(hook
, slot
);