From 80d73dd21b0af1970ec3cedfe1490acc39f7c221 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 12 Aug 2006 23:35:44 +0000 Subject: implement typeafe hook chain git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1231 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/Makefile.am | 8 +++++++- src/pulsecore/llist.h | 2 ++ src/tests/hook-list-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/tests/hook-list-test.c diff --git a/src/Makefile.am b/src/Makefile.am index e0fae996..82175e42 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -196,7 +196,8 @@ noinst_PROGRAMS = \ thread-mainloop-test \ utf8-test \ get-binary-name-test \ - ipacl-test + ipacl-test \ + hook-list-test if HAVE_SIGXCPU noinst_PROGRAMS += \ @@ -236,6 +237,11 @@ ipacl_test_CFLAGS = $(AM_CFLAGS) ipacl_test_LDADD = $(AM_LDADD) libpulsecore.la ipacl_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) +hook_list_test_SOURCES = tests/hook-list-test.c +hook_list_test_CFLAGS = $(AM_CFLAGS) +hook_list_test_LDADD = $(AM_LDADD) libpulsecore.la +hook_list_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) + mcalign_test_SOURCES = tests/mcalign-test.c mcalign_test_CFLAGS = $(AM_CFLAGS) mcalign_test_LDADD = $(AM_LDADD) $(WINSOCK_LIBS) libpulsecore.la diff --git a/src/pulsecore/llist.h b/src/pulsecore/llist.h index 9ce24e74..c50b8a78 100644 --- a/src/pulsecore/llist.h +++ b/src/pulsecore/llist.h @@ -22,6 +22,8 @@ USA. ***/ +#include + /* Some macros for maintaining doubly linked lists */ /* The head of the linked list. Use this in the structure that shall diff --git a/src/tests/hook-list-test.c b/src/tests/hook-list-test.c new file mode 100644 index 00000000..ee0b54f9 --- /dev/null +++ b/src/tests/hook-list-test.c @@ -0,0 +1,38 @@ +/* $Id$ */ + +#include +#include + +PA_HOOK_DECLARE(test, const char *, const char*); +PA_HOOK_IMPLEMENT(test, const char *, const char *); + +static pa_hook_result_t func1(const char*a, const char*b, void *userdata) { + pa_log("#1 a=%s b=%s userdata=%s", a, b, (char*) userdata); + return PA_HOOK_OK; +} + +static pa_hook_result_t func2(const char*a, const char*b, void *userdata) { + pa_log("#2 a=%s b=%s userdata=%s", a, b, (char*) userdata); + return PA_HOOK_OK; +} + +int main(int argc, char *argv[]) { + void *u; + + PA_HOOK_HEAD(test, test); + + PA_HOOK_HEAD_INIT(test, test); + + PA_HOOK_APPEND(test, test, func1, (void*) "1-1"); + PA_HOOK_APPEND(test, test, func2, u = (void*) "2"); + PA_HOOK_APPEND(test, test, func1, (void*) "1-2"); + + + PA_HOOK_EXECUTE(test, test, "arg1", "arg2"); + + PA_HOOK_REMOVE(test, test, func2, u); + + PA_HOOK_FREE(test, test); + + return 0; +} -- cgit