]> code.delx.au - pulseaudio/commitdiff
some updates for pa_hashmap
authorLennart Poettering <lennart@poettering.net>
Sat, 30 Oct 2004 01:55:16 +0000 (01:55 +0000)
committerLennart Poettering <lennart@poettering.net>
Sat, 30 Oct 2004 01:55:16 +0000 (01:55 +0000)
add property infrastructure
add module module-x11-publish
allow ldpreloading of all modules
abstract x11wrap from module-x11-bell

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@268 fefdeb5f-60dc-0310-8127-8f9354f1896f

36 files changed:
doc/todo
polyp/Makefile.am
polyp/cli-command.c
polyp/cli-text.c
polyp/core.c
polyp/core.h
polyp/hashmap.c
polyp/hashmap.h
polyp/main.c
polyp/module-alsa-sink.c
polyp/module-alsa-source.c
polyp/module-cli.c
polyp/module-combine.c
polyp/module-defs.h.m4 [new file with mode: 0644]
polyp/module-esound-compat-spawnfd.c
polyp/module-esound-compat-spawnpid.c
polyp/module-match.c
polyp/module-native-protocol-fd.c
polyp/module-null-sink.c
polyp/module-oss-mmap.c
polyp/module-oss.c
polyp/module-pipe-sink.c
polyp/module-pipe-source.c
polyp/module-protocol-stub.c
polyp/module-sine.c
polyp/module-tunnel.c
polyp/module-x11-bell.c
polyp/module-x11-publish.c [new file with mode: 0644]
polyp/module.h
polyp/namereg.c
polyp/polyplib-internal.h
polyp/props.c [new file with mode: 0644]
polyp/props.h [new file with mode: 0644]
polyp/protocol-native.c
polyp/x11wrap.c [new file with mode: 0644]
polyp/x11wrap.h [new file with mode: 0644]

index f2155b9956c2906aaa2fd02baaa3a73d8a79a050..8212ea89b133b51516c74cb6c33436986c96ea67 100644 (file)
--- a/doc/todo
+++ b/doc/todo
 - add sync API
 - make most buffer sizes dependant on the sample type
 
+- X11: support for the X11 synchronization extension
+- X11: save auth info in root window
+- pass meta info for hearing impaired
+- fall back to getpwnam if $HOME doesn't exist
+- module-match: look in $HOME for table
+- limit all resources
+- getaddrinfo
+- add LGPL blurb to all concerning files
+
 ** later ***
 - xmlrpc/http
 - dbus
index ae551a1bd9bb40938bbb79cad8e3be77fbd94bda..d90d32295f6e4270805fba0c8fbc3863b427aaee 100644 (file)
@@ -32,7 +32,7 @@ AM_CFLAGS+=-DPOLYPAUDIO_BINARY=\"$(bindir)/polypaudio\"
 AM_LDADD=$(PTHREAD_LIBS) -lm
 AM_LIBADD=$(PTHREAD_LIBS) -lm
 
-EXTRA_DIST = default.pa.in daemon.conf.in client.conf.in depmod.py esdcompat.sh.in
+EXTRA_DIST = default.pa.in daemon.conf.in client.conf.in depmod.py esdcompat.sh.in module-defs.h.m4
 bin_PROGRAMS = polypaudio pacat pactl paplay
 bin_SCRIPTS = esdcompat.sh
 noinst_PROGRAMS = \
@@ -112,6 +112,33 @@ modlib_LTLIBRARIES= \
                module-tunnel-source.la \
                module-null-sink.la
 
+SYMDEF_FILES= \
+               module-cli-symdef.h \
+               module-cli-protocol-tcp-symdef.h \
+               module-cli-protocol-unix-symdef.h \
+               module-pipe-sink-symdef.h \
+               module-pipe-source-symdef.h \
+               module-oss-symdef.h \
+               module-oss-mmap-symdef.h \
+               module-simple-protocol-tcp-symdef.h \
+               module-simple-protocol-unix-symdef.h \
+               module-esound-protocol-tcp-symdef.h \
+               module-esound-protocol-unix-symdef.h \
+               module-native-protocol-tcp-symdef.h \
+               module-native-protocol-unix-symdef.h \
+               module-native-protocol-fd-symdef.h \
+               module-sine-symdef.h \
+               module-combine-symdef.h \
+               module-esound-compat-spawnfd-symdef.h \
+               module-esound-compat-spawnpid-symdef.h \
+               module-match-symdef.h \
+               module-tunnel-sink-symdef.h \
+               module-tunnel-source-symdef.h \
+               module-null-sink-symdef.h
+
+EXTRA_DIST+=$(SYMDEF_FILES)
+BUILT_SOURCES+=$(SYMDEF_FILES)
+
 lib_LTLIBRARIES= \
                libpolyp-@PA_MAJORMINOR@.la \
                libpolyp-error-@PA_MAJORMINOR@.la \
@@ -167,12 +194,14 @@ polypaudio_SOURCES = idxset.c idxset.h \
                daemon-conf.c daemon-conf.h \
                dumpmodules.c dumpmodules.h \
                conf-parser.h conf-parser.c \
-               caps.h caps.c
+               caps.h caps.c \
+               props.h props.c
 
 polypaudio_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS) $(LIBSNDFILE_CFLAGS)
 polypaudio_INCLUDES = $(INCLTDL)
 polypaudio_LDADD = $(AM_LDADD) $(LIBLTDL) $(LIBSAMPLERATE_LIBS) $(LIBSNDFILE_LIBS) $(CAP_LIBS)
-polypaudio_LDFLAGS=-export-dynamic
+polypaudio_LDFLAGS= -export-dynamic -dlopen force
+#-static $(foreach f,$(modlib_LTLIBRARIES),-dlpreopen $(f))
 
 libprotocol_simple_la_SOURCES = protocol-simple.c protocol-simple.h
 libprotocol_simple_la_LDFLAGS = -avoid-version
@@ -430,12 +459,28 @@ cpulimit_test2_LDADD = $(AM_LDADD) libpolyp-mainloop-@PA_MAJORMINOR@.la
 
 if HAVE_X11
 modlib_LTLIBRARIES+= \
-               module-x11-bell.la
+               libx11wrap.la \
+               module-x11-bell.la \
+               module-x11-publish.la
+SYMDEF_FILES += \
+               module-x11-bell-symdef.h \
+               module-x11-publish-symdef.h
+
+libx11wrap_la_SOURCES = x11wrap.c x11wrap.h
+libx11wrap_la_LDFLAGS = -avoid-version
+libx11wrap_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS)
+libx11wrap_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIB)
 
 module_x11_bell_la_SOURCES = module-x11-bell.c
 module_x11_bell_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS)
 module_x11_bell_la_LDFLAGS = -module -avoid-version
-module_x11_bell_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIB)
+module_x11_bell_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIB) libx11wrap.la
+
+module_x11_publish_la_SOURCES = module-x11-publish.c
+module_x11_publish_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS)
+module_x11_publish_la_LDFLAGS = -module -avoid-version
+module_x11_publish_la_LIBADD = $(AM_LIBADD) $(X_PRE_LIBS) -lX11 $(X_LIBS) $(X_EXTRA_LIB) libx11wrap.la
+
 endif
 
 ### ALSA modules
@@ -445,6 +490,9 @@ modlib_LTLIBRARIES+= \
                libalsa-util.la \
                module-alsa-sink.la \
                module-alsa-source.la
+SYMDEF_FILES += \
+               module-alsa-sink-symdef.h \
+               module-alsa-source-symdef.h
 
 libalsa_util_la_SOURCES = alsa-util.c alsa-util.h
 libalsa_util_la_LDFLAGS = -avoid-version
@@ -597,3 +645,6 @@ daemon.conf: daemon.conf.in Makefile
 install-exec-hook:
        chown root:root $(DESTDIR)$(bindir)/polypaudio
        chmod u+s $(DESTDIR)$(bindir)/polypaudio
+
+$(SYMDEF_FILES): module-defs.h.m4
+       m4 -Dfname="$@" $< > $@
index 62981b4d9dc63ac6e2467102fd266412b04a24d2..d563a072784ee718338b4b5043134d6e41a56778 100644 (file)
@@ -47,6 +47,7 @@
 #include "autoload.h"
 #include "xmalloc.h"
 #include "sound-file-stream.h"
+#include "props.h"
 
 struct command {
     const char *name;
@@ -83,6 +84,7 @@ static int pa_cli_command_autoload_list(struct pa_core *c, struct pa_tokenizer *
 static int pa_cli_command_autoload_add(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
 static int pa_cli_command_autoload_remove(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
 static int pa_cli_command_dump(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
+static int pa_cli_command_list_props(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose);
 
 static const struct command commands[] = {
     { "exit",                    pa_cli_command_exit,               "Terminate the daemon",         1 },
@@ -118,6 +120,7 @@ static const struct command commands[] = {
     { "remove-autoload-sink",    pa_cli_command_autoload_remove,    "Remove autoload entry for a sink (args: name)", 2},
     { "remove-autoload-source",  pa_cli_command_autoload_remove,    "Remove autoload entry for a source (args: name)", 2},
     { "dump",                    pa_cli_command_dump,               "Dump daemon configuration", 1},
+    { "list-props",              pa_cli_command_list_props,         NULL, 1},
     { NULL, NULL, NULL, 0 }
 };
 
@@ -602,6 +605,12 @@ static int pa_cli_command_autoload_list(struct pa_core *c, struct pa_tokenizer *
     return 0;
 }
 
+static int pa_cli_command_list_props(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
+    assert(c && t);
+    pa_property_dump(c, buf);
+    return 0;
+}
+
 static int pa_cli_command_dump(struct pa_core *c, struct pa_tokenizer *t, struct pa_strbuf *buf, int *fail, int *verbose) {
     struct pa_module *m;
     struct pa_sink *s;
@@ -654,7 +663,7 @@ static int pa_cli_command_dump(struct pa_core *c, struct pa_tokenizer *t, struct
         nl = 0;
         
         i = NULL;
-        while ((a = pa_hashmap_iterate(c->autoload_hashmap, &i))) {
+        while ((a = pa_hashmap_iterate(c->autoload_hashmap, &i, NULL))) {
 
             if (!nl) {
                 pa_strbuf_puts(buf, "\n");
index c08b0d9cf3de95d27494128bd3711d8229af7d86..39f7b6edd2e52526ceed0abcac7ad2d294bcb8cb 100644 (file)
@@ -271,7 +271,7 @@ char *pa_autoload_list_to_string(struct pa_core *c) {
         struct pa_autoload_entry *e;
         void *state = NULL;
 
-        while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state))) {
+        while ((e = pa_hashmap_iterate(c->autoload_hashmap, &state, NULL))) {
             pa_strbuf_printf(
                 s, "    name: <%s>\n\ttype: <%s>\n\tindex: <%u>\n\tmodule_name: <%s>\n\targuments: <%s>\n",
                 e->name,
index c53d2e4ee38f0931df80b24e45bebbc8c9437ca5..6e155dda707f44c346727ada4b7cf84f12122230 100644 (file)
@@ -39,6 +39,7 @@
 #include "autoload.h"
 #include "xmalloc.h"
 #include "subscribe.h"
+#include "props.h"
 
 struct pa_core* pa_core_new(struct pa_mainloop_api *m) {
     struct pa_core* c;
@@ -82,6 +83,8 @@ struct pa_core* pa_core_new(struct pa_mainloop_api *m) {
     c->scache_idle_time = 20;
 
     c->resample_method = SRC_SINC_FASTEST;
+
+    pa_property_init(c);
     
     pa_check_signal_is_blocked(SIGPIPE);
     
@@ -121,6 +124,8 @@ void pa_core_free(struct pa_core *c) {
     pa_xfree(c->default_sink_name);
 
     pa_memblock_stat_unref(c->memblock_stat);
+
+    pa_property_cleanup(c);
     
     pa_xfree(c);    
 }
index c457c3fd6e6a50c17f7726d88ec2696d18be4b56..1438bf7209ae464ad8ce4e63ecf16611b303b846 100644 (file)
@@ -33,7 +33,7 @@ struct pa_core {
 
     struct pa_idxset *clients, *sinks, *sources, *sink_inputs, *source_outputs, *modules, *scache, *autoload_idxset;
 
-    struct pa_hashmap *namereg, *autoload_hashmap;
+    struct pa_hashmap *namereg, *autoload_hashmap, *properties;
 
     char *default_source_name, *default_sink_name;
 
index 2b9550fda0b45a0af04d4ab6b30e1da4099a46d8..10b148ddff637d8e7fc4f1d4c1286a31fc0f14af 100644 (file)
@@ -30,6 +30,7 @@
 #include "hashmap.h"
 #include "idxset.h"
 #include "xmalloc.h"
+#include "log.h"
 
 struct hashmap_entry {
     struct hashmap_entry *next, *previous, *bucket_next, *bucket_previous;
@@ -147,25 +148,27 @@ void* pa_hashmap_get(struct pa_hashmap *h, const void *key) {
     return e->value;
 }
 
-int pa_hashmap_remove(struct pa_hashmap *h, const void *key) {
+void* pa_hashmap_remove(struct pa_hashmap *h, const void *key) {
     struct hashmap_entry *e;
     unsigned hash;
+    void *data;
     assert(h && key);
 
     hash = h->hash_func(key) % h->size;
 
     if (!(e = get(h, hash, key)))
-        return 1;
+        return NULL;
 
+    data = e->value;
     remove(h, e);
-    return 0;
+    return data;
 }
 
 unsigned pa_hashmap_ncontents(struct pa_hashmap *h) {
     return h->n_entries;
 }
 
-void *pa_hashmap_iterate(struct pa_hashmap *h, void **state) {
+void *pa_hashmap_iterate(struct pa_hashmap *h, void **state, const void **key) {
     assert(h && state);
 
     if (!*state) {
@@ -173,8 +176,14 @@ void *pa_hashmap_iterate(struct pa_hashmap *h, void **state) {
     } else
         *state = ((struct hashmap_entry*) *state)->next;
 
-    if (!*state)
+    if (!*state) {
+        if (key)
+            *key = NULL;
         return NULL;
+    }
+
+    if (key)
+        *key = ((struct hashmap_entry*) *state)->key;
     
     return ((struct hashmap_entry*) *state)->value;
 }
index 3b79d7ae87bd8c3c46005649c28596db9578c68e..739f89477de0736d2be5be39de07466689ea2061 100644 (file)
@@ -30,13 +30,15 @@ void pa_hashmap_free(struct pa_hashmap*, void (*free_func)(void *p, void *userda
 int pa_hashmap_put(struct pa_hashmap *h, const void *key, void *value);
 void* pa_hashmap_get(struct pa_hashmap *h, const void *key);
 
-int pa_hashmap_remove(struct pa_hashmap *h, const void *key);
+void* pa_hashmap_remove(struct pa_hashmap *h, const void *key);
 
 unsigned pa_hashmap_ncontents(struct pa_hashmap *h);
 
-/* Maybe used to iterate through the hashmap. Initial state should
-   point to a NULL pointer. The hashmap may not be modified during
-   iteration */
-void *pa_hashmap_iterate(struct pa_hashmap *h, void **state);
+/* May be used to iterate through the hashmap. Initially the opaque
+   pointer *state has to be set to NULL. The hashmap may not be
+   modified during iteration. The key of the entry is returned in
+   *key, if key is non-NULL. After the last entry in the hashmap NULL
+   is returned. */
+void *pa_hashmap_iterate(struct pa_hashmap *h, void **state, const void**key);
 
 #endif
index 5be4118d897167393f152f308850c47fc324e61b..378cb8a066c5f8f5ae233f58235eddbe4df09a87 100644 (file)
@@ -152,9 +152,11 @@ int main(int argc, char *argv[]) {
         pa_drop_root();
     }
     
+    LTDL_SET_PRELOADED_SYMBOLS();
+    
     r = lt_dlinit();
     assert(r == 0);
-    
+
     pa_log_set_ident("polypaudio");
     
     conf = pa_daemon_conf_new();
index 528fe8d300e05c8d2795986dd1c804fbb73cd738..e319f6c168bc6b7b33a33ccd00cd93097377a97f 100644 (file)
@@ -39,6 +39,7 @@
 #include "alsa-util.h"
 #include "xmalloc.h"
 #include "log.h"
+#include "module-alsa-sink-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("ALSA Sink")
index c0a18d2b5ff21f21fadc74e34687d322a445fb20..34f08f95a0372d05edd3d746ff6b6f89e41c518e 100644 (file)
@@ -39,6 +39,7 @@
 #include "alsa-util.h"
 #include "xmalloc.h"
 #include "log.h"
+#include "module-alsa-source-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("ALSA Source")
index 6444194c149739a1f2a1c25ecfb93c48a426a23a..1ebc9b52e1e38da28f21c9cae84d10b34b74416e 100644 (file)
@@ -32,6 +32,7 @@
 #include "cli.h"
 #include "sioman.h"
 #include "log.h"
+#include "module-cli-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("Command line interface")
index 1a909087f973d9ef9e8ccf81c8397f4723ffbf37..5df3f1589bd80d79ec8c7289595ca701641d02dc 100644 (file)
@@ -36,6 +36,7 @@
 #include "xmalloc.h"
 #include "modargs.h"
 #include "namereg.h"
+#include "module-combine-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("Combine multiple sinks to one")
diff --git a/polyp/module-defs.h.m4 b/polyp/module-defs.h.m4
new file mode 100644 (file)
index 0000000..85eb64a
--- /dev/null
@@ -0,0 +1,21 @@
+dnl $Id$
+changecom(`/*', `*/')dnl
+define(`module', patsubst(patsubst(fname, `-symdef.h$'), `[^0-9a-zA-Z]', `_'))dnl
+define(`c_symbol', patsubst(module, `[^0-9a-zA-Z]', `_'))dnl
+define(`c_macro', patsubst(module, `[^0-9a-zA-Z]', `'))dnl
+define(`incmacro', `foo'c_macro`symdeffoo')dnl
+define(`gen_symbol', `#define $1 'module`_LTX_$1')dnl
+#ifndef incmacro
+#define incmacro
+
+gen_symbol(pa__init)
+gen_symbol(pa__done)
+gen_symbol(pa__get_author)
+gen_symbol(pa__get_description)
+gen_symbol(pa__get_usage)
+gen_symbol(pa__get_version)
+
+int pa__init(struct pa_core *c, struct pa_module*m);
+void pa__done(struct pa_core *c, struct pa_module*m);
+
+#endif
index 514159fcf77003cdcab7ce99d5ed90ab863b8bea..ae4f9095b1a1915df4a3b570d9812c2ed0b7418d 100644 (file)
@@ -32,6 +32,7 @@
 #include "util.h"
 #include "modargs.h"
 #include "log.h"
+#include "module-esound-compat-spawnfd-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("ESOUND compatibility module: -spawnfd emulation")
index 5583f071fde08ac93fe4f36545582bd2c69016cb..02756cdb69f704778397ff87e2f54d1d0101956c 100644 (file)
@@ -32,6 +32,7 @@
 #include "util.h"
 #include "modargs.h"
 #include "log.h"
+#include "module-esound-compat-spawnpid-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("ESOUND compatibility module: -spawnpid emulation")
index 380c6011a6b8a9c0c716d59818ccfd9bd5e1907a..6689cc59252e30aa798b19875b5aa86ad1cb692a 100644 (file)
@@ -39,6 +39,7 @@
 #include "subscribe.h"
 #include "xmalloc.h"
 #include "sink-input.h"
+#include "module-match-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("Sink input matching module")
index c1ea69756904dc9c28a3641c277f725d178ffb73..8f41db6417e954ca54ab3625e28c75f7225773ce 100644 (file)
@@ -32,6 +32,7 @@
 #include "modargs.h"
 #include "protocol-native.h"
 #include "log.h"
+#include "module-native-protocol-fd-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("Native protocol autospawn helper")
index 865420107e7b72cae50f4fd30dcc6791d7988e9f..4a41b74defcfa832414dc3524d09c776a7dbf4b5 100644 (file)
@@ -40,6 +40,7 @@
 #include "modargs.h"
 #include "xmalloc.h"
 #include "log.h"
+#include "module-null-sink-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("Clocked NULL sink")
index f7fcbd3ba2f2d629ff627308d6e9e3b17627df95..bc36d199176c55c459c2b3400a9e4f699c8983d7 100644 (file)
@@ -46,6 +46,7 @@
 #include "modargs.h"
 #include "xmalloc.h"
 #include "log.h"
+#include "module-oss-mmap-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("OSS Sink/Source (mmap)")
index c0c6be8ed38dc15352fb900f990d3ff4f2061935..969761f686b5af05b886a656e77b7f4bdfab2962 100644 (file)
@@ -45,6 +45,7 @@
 #include "modargs.h"
 #include "xmalloc.h"
 #include "log.h"
+#include "module-oss-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("OSS Sink/Source")
index 7c779f7d537ff76b0cddc2e9a502c362522e5b98..bc8abb41f1b492e4a17071181a7dfd9377256f54 100644 (file)
@@ -40,6 +40,7 @@
 #include "modargs.h"
 #include "xmalloc.h"
 #include "log.h"
+#include "module-pipe-sink-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("UNIX pipe sink")
index 3decc41596ec4c3e709e5aa3c5becd60efcc62cc..8bc4c4773d949a788207f098072124c3a63fa0a7 100644 (file)
@@ -40,6 +40,7 @@
 #include "modargs.h"
 #include "xmalloc.h"
 #include "log.h"
+#include "module-pipe-source-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("UNIX pipe source")
index 1ff70a1aed266f610a790120ea3211873c9ec8f2..8cef3bdb3a1c343dec78b1b0c32b5f7cb458e173 100644 (file)
@@ -39,9 +39,6 @@
 #include "log.h"
 #include "native-common.h"
 
-PA_MODULE_AUTHOR("Lennart Poettering")
-PA_MODULE_VERSION(PACKAGE_VERSION)
-
 #ifdef USE_TCP_SOCKETS
 #define SOCKET_DESCRIPTION "(TCP sockets)"
 #define SOCKET_USAGE "port=<TCP port number> loopback=<listen on loopback device only?>"
@@ -58,6 +55,11 @@ PA_MODULE_VERSION(PACKAGE_VERSION)
   #define IPV4_PORT 4711
   #define UNIX_SOCKET "/tmp/polypaudio/simple"
   #define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record",
+  #ifdef USE_TCP_SOCKETS
+    #include "module-simple-protocol-tcp-symdef.h"
+  #else
+    #include "module-simple-protocol-unix-symdef.h"
+  #endif
   PA_MODULE_DESCRIPTION("Simple protocol "SOCKET_DESCRIPTION)
   PA_MODULE_USAGE("rate=<sample rate> format=<sample format> channels=<number of channels> sink=<sink to connect to> source=<source to connect to> playback=<enable playback?> record=<enable record?> "SOCKET_USAGE)
 #elif defined(USE_PROTOCOL_CLI)
@@ -68,6 +70,11 @@ PA_MODULE_VERSION(PACKAGE_VERSION)
   #define IPV4_PORT 4712
   #define UNIX_SOCKET "/tmp/polypaudio/cli"
   #define MODULE_ARGUMENTS 
+  #ifdef USE_TCP_SOCKETS
+    #include "module-cli-protocol-tcp-symdef.h"
+  #else
+    #include "module-cli-protocol-unix-symdef.h"
+  #endif
   PA_MODULE_DESCRIPTION("Command line interface protocol "SOCKET_DESCRIPTION)
   PA_MODULE_USAGE(SOCKET_USAGE)
 #elif defined(USE_PROTOCOL_NATIVE)
@@ -78,6 +85,11 @@ PA_MODULE_VERSION(PACKAGE_VERSION)
   #define IPV4_PORT PA_NATIVE_DEFAULT_PORT
   #define UNIX_SOCKET "/tmp/polypaudio/native"
   #define MODULE_ARGUMENTS "public", "cookie",
+  #ifdef USE_TCP_SOCKETS
+    #include "module-native-protocol-tcp-symdef.h"
+  #else
+    #include "module-native-protocol-unix-symdef.h"
+  #endif
   PA_MODULE_DESCRIPTION("Native protocol "SOCKET_DESCRIPTION)
   PA_MODULE_USAGE("public=<don't check for cookies?> cookie=<path to cookie file> "SOCKET_USAGE)
 #elif defined(USE_PROTOCOL_ESOUND)
@@ -89,12 +101,20 @@ PA_MODULE_VERSION(PACKAGE_VERSION)
   #define IPV4_PORT ESD_DEFAULT_PORT
   #define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
   #define MODULE_ARGUMENTS "sink", "source", "public", "cookie",
+  #ifdef USE_TCP_SOCKETS
+    #include "module-esound-protocol-tcp-symdef.h"
+  #else
+    #include "module-esound-protocol-unix-symdef.h"
+  #endif
   PA_MODULE_DESCRIPTION("EsounD protocol "SOCKET_DESCRIPTION)
   PA_MODULE_USAGE("sink=<sink to connect to> source=<source to connect to> public=<don't check for cookies?> cookie=<path to cookie file> "SOCKET_USAGE)
 #else
   #error "Broken build system" 
 #endif
 
+PA_MODULE_AUTHOR("Lennart Poettering")
+PA_MODULE_VERSION(PACKAGE_VERSION)
+
 static const char* const valid_modargs[] = {
     MODULE_ARGUMENTS
 #ifdef USE_TCP_SOCKETS
index 458b87883258ae50b08a9284ebc9bca53ce6a7c4..393f929aa953684e7ce8f95d2d06b694d5ca33d0 100644 (file)
@@ -33,6 +33,7 @@
 #include "xmalloc.h"
 #include "namereg.h"
 #include "log.h"
+#include "module-sine-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("Sine wave generator")
index 1a720f3b5be1881f85c4df6d772d3d2f3807885a..2e22258ac43d662e5f272e30aca9bbe916ae1f71 100644 (file)
 #include "socket-client.h"
 #include "socket-util.h"
 
-PA_MODULE_AUTHOR("Lennart Poettering")
-PA_MODULE_VERSION(PACKAGE_VERSION)
-
 #ifdef TUNNEL_SINK
+#include "module-tunnel-sink-symdef.h"
 PA_MODULE_DESCRIPTION("Tunnel module for sinks")
 PA_MODULE_USAGE("server=<filename> sink=<remote sink name> cookie=<filename> format=<sample format> channels=<number of channels> rate=<sample rate> sink_name=<name for the local sink>")
 #else
+#include "module-tunnel-source-symdef.h"
 PA_MODULE_DESCRIPTION("Tunnel module for sources")
 PA_MODULE_USAGE("server=<filename> source=<remote source name> cookie=<filename> format=<sample format> channels=<number of channels> rate=<sample rate> source_name=<name for the local source>")
 #endif
 
+PA_MODULE_AUTHOR("Lennart Poettering")
+PA_MODULE_VERSION(PACKAGE_VERSION)
+
 #define DEFAULT_SINK_NAME "tunnel"
 #define DEFAULT_SOURCE_NAME "tunnel"
 
index ae69f9cb6190c5394095512755834afb6f5b07b9..23433c8f2bbaf3c558daa4869bff2989df41d846 100644 (file)
 #include "xmalloc.h"
 #include "namereg.h"
 #include "log.h"
+#include "x11wrap.h"
+#include "module-x11-bell-symdef.h"
 
 PA_MODULE_AUTHOR("Lennart Poettering")
 PA_MODULE_DESCRIPTION("X11 Bell interceptor")
 PA_MODULE_VERSION(PACKAGE_VERSION)
 PA_MODULE_USAGE("sink=<sink to connect to> sample=<sample name> display=<X11 display>")
 
-struct x11_source {
-    struct pa_io_event *io_event;
-    struct x11_source *next;
-};
-
 struct userdata {
     struct pa_core *core;
-    Display *display;
-    struct x11_source *x11_sources;
     int xkb_event_base;
-
     char *sink_name;
     char *scache_item;
+    Display *display;
+
+    struct pa_x11_wrapper *x11_wrapper;
+    struct pa_x11_client *x11_client;
 };
 
 static const char* const valid_modargs[] = {
@@ -79,35 +77,22 @@ static int ring_bell(struct userdata *u, int percent) {
     return 0;
 }
 
-static void io_callback(struct pa_mainloop_api*a, struct pa_io_event *e, int fd, enum pa_io_event_flags f, void *userdata) {
+static int x11_event_callback(struct pa_x11_wrapper *w, XEvent *e, void *userdata) {
+    XkbBellNotifyEvent *bne;
     struct userdata *u = userdata;
-    assert(u);
-    
-    while (XPending(u->display)) {
-        XEvent e;
-        XkbBellNotifyEvent *bne;
-        XNextEvent(u->display, &e);
-
-        if (((XkbEvent*) &e)->any.xkb_type != XkbBellNotify)
-            continue;
-
-        bne = ((XkbBellNotifyEvent*) &e);
-            
-        if (ring_bell(u, bne->percent) < 0) {
-            pa_log(__FILE__": Ringing bell failed, reverting to X11 device bell.\n");
-            XkbForceDeviceBell(u->display, bne->device, bne->bell_class, bne->bell_id, bne->percent);
-        }
-    }
-}
+    assert(w && e && u && u->x11_wrapper == w);
+
+    if (((XkbEvent*) e)->any.xkb_type != XkbBellNotify)
+        return 0;
+
+    bne = (XkbBellNotifyEvent*) e;
 
-static void new_io_source(struct userdata *u, int fd) {
-    struct x11_source *s;
+    if (ring_bell(u, bne->percent) < 0) {
+        pa_log(__FILE__": Ringing bell failed, reverting to X11 device bell.\n");
+        XkbForceDeviceBell(pa_x11_wrapper_get_display(w), bne->device, bne->bell_class, bne->bell_id, bne->percent);
+    }
 
-    s = pa_xmalloc(sizeof(struct x11_source));
-    s->io_event = u->core->mainloop->io_new(u->core->mainloop, fd, PA_IO_EVENT_INPUT, io_callback, u);
-    assert(s->io_event);
-    s->next = u->x11_sources;
-    u->x11_sources = s;
+    return 1;
 }
 
 int pa__init(struct pa_core *c, struct pa_module*m) {
@@ -124,18 +109,15 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
     
     m->userdata = u = pa_xmalloc(sizeof(struct userdata));
     u->core = c;
-    u->display = NULL;
-    u->x11_sources = NULL;
     u->scache_item = pa_xstrdup(pa_modargs_get_value(ma, "sample", "x11-bell"));
     u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
+    u->x11_client = NULL;
 
-    if (!(u->display = XOpenDisplay(pa_modargs_get_value(ma, "display", NULL)))) {
-        pa_log(__FILE__": XOpenDisplay() failed\n");
+    if (!(u->x11_wrapper = pa_x11_wrapper_get(c, pa_modargs_get_value(ma, "display", NULL)))) 
         goto fail;
-    }
-
-    new_io_source(u, ConnectionNumber(u->display));
 
+    u->display = pa_x11_wrapper_get_display(u->x11_wrapper);
+    
     major = XkbMajorVersion;
     minor = XkbMinorVersion;
     
@@ -147,6 +129,7 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
     major = XkbMajorVersion;
     minor = XkbMinorVersion;
 
+
     if (!XkbQueryExtension(u->display, NULL, &u->xkb_event_base, NULL, &major, &minor)) {
         pa_log(__FILE__": XkbQueryExtension() failed\n");
         goto fail;
@@ -157,6 +140,8 @@ int pa__init(struct pa_core *c, struct pa_module*m) {
     XkbSetAutoResetControls(u->display, XkbAudibleBellMask, &auto_ctrls, &auto_values);
     XkbChangeEnabledControls(u->display, XkbUseCoreKbd, XkbAudibleBellMask, 0);
 
+    u->x11_client = pa_x11_client_new(u->x11_wrapper, x11_event_callback, u);
+    
     pa_modargs_free(ma);
     
     return 0;
@@ -173,17 +158,14 @@ void pa__done(struct pa_core *c, struct pa_module*m) {
     struct userdata *u = m->userdata;
     assert(c && m && u);
 
-    while (u->x11_sources) {
-        struct x11_source *s = u->x11_sources;
-        u->x11_sources = u->x11_sources->next;
-        c->mainloop->io_free(s->io_event);
-        pa_xfree(s);
-    }
-
     pa_xfree(u->scache_item);
     pa_xfree(u->sink_name);
-    
-    if (u->display)
-        XCloseDisplay(u->display);
+
+    if (u->x11_client)
+        pa_x11_client_free(u->x11_client);
+
+    if (u->x11_wrapper)
+        pa_x11_wrapper_unref(u->x11_wrapper);
+
     pa_xfree(u);
 }
diff --git a/polyp/module-x11-publish.c b/polyp/module-x11-publish.c
new file mode 100644 (file)
index 0000000..fd4df4a
--- /dev/null
@@ -0,0 +1,167 @@
+/* $Id$ */
+
+/***
+  This file is part of polypaudio.
+  polypaudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published
+  by the Free Software Foundation; either version 2 of the License,
+  or (at your option) any later version.
+  polypaudio 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.
+  You should have received a copy of the GNU General Public License
+  along with polypaudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+#include "module.h"
+#include "sink.h"
+#include "scache.h"
+#include "modargs.h"
+#include "xmalloc.h"
+#include "namereg.h"
+#include "log.h"
+#include "x11wrap.h"
+#include "util.h"
+
+#include "module-x11-publish-symdef.h"
+
+PA_MODULE_AUTHOR("Lennart Poettering")
+PA_MODULE_DESCRIPTION("X11 Credential Publisher")
+PA_MODULE_VERSION(PACKAGE_VERSION)
+PA_MODULE_USAGE("display=<X11 display>")
+
+static const char* const valid_modargs[] = {
+    "display",
+    "sink",
+    "source",
+    NULL
+};
+
+struct userdata {
+    struct pa_core *core;
+    struct pa_x11_wrapper *x11_wrapper;
+    Display *display;
+    char *id;
+};
+
+static void set_x11_prop(Display *d, const char *name, const char *data) {
+    Atom a = XInternAtom(d, name, False);
+    XChangeProperty(d, RootWindow(d, 0), a, XA_STRING, 8, PropModeReplace, (unsigned char*) data, strlen(data)+1);
+}
+
+static void del_x11_prop(Display *d, const char *name) {
+    Atom a = XInternAtom(d, name, False);
+    XDeleteProperty(d, RootWindow(d, 0), a);
+}
+
+static char* get_x11_prop(Display *d, const char *name, char *p, size_t l) {
+    Atom actual_type;
+    int actual_format;
+    unsigned long nitems;
+    unsigned long nbytes_after;
+    unsigned char *prop;
+    
+    Atom a = XInternAtom(d, name, False);
+    if (XGetWindowProperty(d, RootWindow(d, 0), a, 0, (l+2)/4, False, XA_STRING, &actual_type, &actual_format, &nitems, &nbytes_after, &prop) != Success)
+        return NULL;
+
+    memcpy(p, prop, nitems);
+    p[nitems] = 0;
+
+    XFree(prop);
+    return p;
+}
+
+int pa__init(struct pa_core *c, struct pa_module*m) {
+    struct userdata *u;
+    struct pa_modargs *ma = NULL;
+    char hn[256], un[128];
+     const char *t;
+
+    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
+        pa_log(__FILE__": failed to parse module arguments\n");
+        goto fail;
+    }
+
+    m->userdata = u = pa_xmalloc(sizeof(struct userdata));
+    u->core = c;
+    u->id = NULL;
+
+    if (!(u->x11_wrapper = pa_x11_wrapper_get(c, pa_modargs_get_value(ma, "display", NULL)))) 
+        goto fail;
+
+    u->display = pa_x11_wrapper_get_display(u->x11_wrapper);
+
+    pa_get_host_name(hn, sizeof(hn));
+    pa_get_user_name(un, sizeof(un));
+    
+    u->id = pa_sprintf_malloc("%s@%s/%u", un, hn, (unsigned) getpid());
+
+    set_x11_prop(u->display, "POLYP_SERVER", hn);
+    set_x11_prop(u->display, "POLYP_ID", u->id);
+
+    if ((t = pa_modargs_get_value(ma, "source", NULL)))
+        set_x11_prop(u->display, "POLYP_SOURCE", t);
+
+    if ((t = pa_modargs_get_value(ma, "sink", NULL)))
+        set_x11_prop(u->display, "POLYP_SINK", t);
+    
+    pa_modargs_free(ma);
+    return 0;
+    
+fail:
+    if (ma)
+        pa_modargs_free(ma);
+
+    pa__done(c, m);
+    return -1;
+}
+
+void pa__done(struct pa_core *c, struct pa_module*m) {
+    struct userdata*u;
+    assert(c && m);
+
+    if (!(u = m->userdata))
+        return;
+    
+    if (u->x11_wrapper) {
+        char t[256];
+
+        /* Yes, here is a race condition */
+        if (!get_x11_prop(u->display, "POLYP_ID", t, sizeof(t)) || strcmp(t, u->id))
+            pa_log("WARNING: Polypaudio information vanished from X11!\n");
+        else {
+            del_x11_prop(u->display, "POLYP_ID");
+            del_x11_prop(u->display, "POLYP_SERVER");
+            del_x11_prop(u->display, "POLYP_SINK");
+            del_x11_prop(u->display, "POLYP_SOURCE");
+            XSync(u->display, False);
+        }
+    }
+    
+    if (u->x11_wrapper)
+        pa_x11_wrapper_unref(u->x11_wrapper);
+
+    pa_xfree(u->id);
+    pa_xfree(u);
+}
+
index f422132ad7e93456e53c80b3efb0c3ee903f7b6a..7380f795c2dcda2f51603fb1ea49bdf96f98e673 100644 (file)
@@ -58,14 +58,10 @@ void pa_module_unload_request(struct pa_module *m);
 
 void pa_module_set_used(struct pa_module*m, int used);
 
-/* prototypes for the module's entry points */
-int pa__init(struct pa_core *c, struct pa_module*m);
-void pa__done(struct pa_core *c, struct pa_module*m);
-
-#define PA_MODULE_AUTHOR(s) const char *pa__get_author(void) { return s; }
-#define PA_MODULE_DESCRIPTION(s) const char *pa__get_description(void) { return s; }
-#define PA_MODULE_USAGE(s) const char *pa__get_usage(void) { return s; }
-#define PA_MODULE_VERSION(s) const char *pa__get_version(void) { return s; }
+#define PA_MODULE_AUTHOR(s) const char * pa__get_author(void) { return s; }
+#define PA_MODULE_DESCRIPTION(s) const char * pa__get_description(void) { return s; }
+#define PA_MODULE_USAGE(s) const char * pa__get_usage(void) { return s; }
+#define PA_MODULE_VERSION(s) const char * pa__get_version(void) { return s; }
 
 struct pa_modinfo *pa_module_get_info(struct pa_module *m);
 
index e2f65efd31584227657ce74b250fa2d9386792d8..cc25ea2b6ec601e34bc9cc1781d45abd75760828 100644 (file)
@@ -100,15 +100,11 @@ const char *pa_namereg_register(struct pa_core *c, const char *name, enum pa_nam
 
 void pa_namereg_unregister(struct pa_core *c, const char *name) {
     struct namereg_entry *e;
-    int r;
     assert(c && name);
 
-    e = pa_hashmap_get(c->namereg, name);
+    e = pa_hashmap_remove(c->namereg, name);
     assert(e);
 
-    r = pa_hashmap_remove(c->namereg, name);
-    assert(r >= 0);
-
     pa_xfree(e->name);
     pa_xfree(e);
 }
index e49b25d40ad607fa92692d568aca9ea3de987b4c..623a89b33c63893277240e6e4e59ba6c0ae9c345 100644 (file)
@@ -43,8 +43,6 @@
 
 #define DEFAULT_TIMEOUT (10)
 
-#define ENV_AUTOSPAWNED "POLYP_AUTOSPAWNED"
-
 struct pa_context {
     int ref;
     
diff --git a/polyp/props.c b/polyp/props.c
new file mode 100644 (file)
index 0000000..014059e
--- /dev/null
@@ -0,0 +1,112 @@
+/* $Id$ */
+
+/***
+  This file is part of polypaudio.
+  polypaudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published
+  by the Free Software Foundation; either version 2 of the License,
+  or (at your option) any later version.
+  polypaudio 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.
+  You should have received a copy of the GNU General Public License
+  along with polypaudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <assert.h>
+
+#include "xmalloc.h"
+#include "props.h"
+#include "log.h"
+
+struct pa_property {
+    char *name;  /* Points to memory allocated by the property subsystem */
+    void *data;  /* Points to memory maintained by the caller */
+};
+
+/* Allocate a new property object */
+static struct pa_property* property_new(const char *name, void *data) {
+    struct pa_property* p;
+    assert(name && data);
+    
+    p = pa_xmalloc(sizeof(struct pa_property));
+    p->name = pa_xstrdup(name);
+    p->data = data;
+
+    return p;
+}
+
+/* Free a property object */
+static void property_free(struct pa_property *p) {
+    assert(p);
+
+    pa_xfree(p->name);
+    pa_xfree(p);
+}
+
+void* pa_property_get(struct pa_core *c, const char *name) {
+    struct pa_property *p;
+    assert(c && name && c->properties);
+
+    if (!(p = pa_hashmap_get(c->properties, name)))
+        return NULL;
+
+    return p->data;
+}
+
+int pa_property_set(struct pa_core *c, const char *name, void *data) {
+    struct pa_property *p;
+    assert(c && name && data && c->properties);
+
+    if (pa_hashmap_get(c->properties, name))
+        return -1;
+
+    p = property_new(name, data);
+    pa_hashmap_put(c->properties, p->name, p);
+    return 0;
+}
+
+int pa_property_remove(struct pa_core *c, const char *name) {
+    struct pa_property *p;
+    assert(c && name && c->properties);
+
+    if (!(p = pa_hashmap_remove(c->properties, name)))
+        return -1;
+    
+    property_free(p);
+    return 0;
+}
+
+void pa_property_init(struct pa_core *c) {
+    assert(c);
+
+    c->properties = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+}
+
+void pa_property_cleanup(struct pa_core *c) {
+    assert(c);
+
+    if (!c->properties)
+        return;
+
+    assert(!pa_hashmap_ncontents(c->properties));
+
+    pa_hashmap_free(c->properties, NULL, NULL);
+    c->properties = NULL;
+    
+}
+
+void pa_property_dump(struct pa_core *c, struct pa_strbuf *s) {
+    void *state = NULL;
+    struct pa_property *p;
+    assert(c && s);
+
+    while ((p = pa_hashmap_iterate(c->properties, &state, NULL)))
+        pa_strbuf_printf(s, "[%s] -> [%p]\n", p->name, p->data);
+}
diff --git a/polyp/props.h b/polyp/props.h
new file mode 100644 (file)
index 0000000..f19e926
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef foopropshfoo
+#define foopropshfoo
+
+/* $Id$ */
+
+/***
+  This file is part of polypaudio.
+  polypaudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published
+  by the Free Software Foundation; either version 2 of the License,
+  or (at your option) any later version.
+  polypaudio 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.
+  You should have received a copy of the GNU General Public License
+  along with polypaudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include "core.h"
+#include "strbuf.h"
+
+/* The property subsystem is to be used to share data between
+ * modules. Consider them to be kind of "global" variables for a
+ * core. Why not use the hashmap functions directly? The hashmap
+ * functions copy neither the key nor value, while this property
+ * system copies the key. Users of this system have to think about
+ * reference counting themselves. */
+
+/* Return a pointer to the value of the specified property. */
+void* pa_property_get(struct pa_core *c, const char *name);
+
+/* Set the property 'name' to 'data'. This function fails in case a
+ * property by this name already exists. The property data is not
+ * copied or reference counted. This is the caller's job. */
+int pa_property_set(struct pa_core *c, const char *name, void *data);
+
+/* Remove the specified property. Return non-zero on failure */
+int pa_property_remove(struct pa_core *c, const char *name);
+
+/* Free all memory used by the property system */
+void pa_property_cleanup(struct pa_core *c);
+
+/* Initialize the properties subsystem */
+void pa_property_init(struct pa_core *c);
+
+/* Dump the current set of properties */
+void pa_property_dump(struct pa_core *c, struct pa_strbuf *s);
+
+#endif
index 7af8bdda40051c41016e2c20d9e7cce666e54afe..6f3f82be5605bf7ef06570952fa6edcf0682b7e6 100644 (file)
@@ -1869,7 +1869,7 @@ static void command_get_autoload_info_list(struct pa_pdispatch *pd, uint32_t com
         struct pa_autoload_entry *a;
         void *state = NULL;
 
-        while ((a = pa_hashmap_iterate(c->protocol->core->autoload_hashmap, &state)))
+        while ((a = pa_hashmap_iterate(c->protocol->core->autoload_hashmap, &state, NULL)))
             autoload_fill_tagstruct(reply, a);
     }
     
diff --git a/polyp/x11wrap.c b/polyp/x11wrap.c
new file mode 100644 (file)
index 0000000..a1a9732
--- /dev/null
@@ -0,0 +1,235 @@
+/* $Id$ */
+
+/***
+  This file is part of polypaudio.
+  polypaudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published
+  by the Free Software Foundation; either version 2 of the License,
+  or (at your option) any later version.
+  polypaudio 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.
+  You should have received a copy of the GNU General Public License
+  along with polypaudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "llist.h"
+#include "x11wrap.h"
+#include "xmalloc.h"
+#include "log.h"
+#include "props.h"
+
+struct pa_x11_client;
+
+struct pa_x11_internal {
+    PA_LLIST_FIELDS(struct pa_x11_internal);
+    struct pa_x11_wrapper *wrapper;
+    struct pa_io_event* io_event;
+    int fd;
+};
+
+struct pa_x11_wrapper {
+    struct pa_core *core;
+    int ref;
+    
+    char *property_name;
+    Display *display;
+
+    struct pa_defer_event* defer_event;
+    struct pa_io_event* io_event;
+
+    PA_LLIST_HEAD(struct pa_x11_client, clients);
+    PA_LLIST_HEAD(struct pa_x11_internal, internals);
+};
+
+struct pa_x11_client {
+    PA_LLIST_FIELDS(struct pa_x11_client);
+    struct pa_x11_wrapper *wrapper;
+    int (*callback)(struct pa_x11_wrapper *w, XEvent *e, void *userdata);
+    void *userdata;
+};
+
+/* Dispatch all pending X11 events */
+static void work(struct pa_x11_wrapper *w) {
+    assert(w && w->ref >= 1);
+    
+    while (XPending(w->display)) {
+        struct pa_x11_client *c;
+        XEvent e;
+        XNextEvent(w->display, &e);
+
+        for (c = w->clients; c; c = c->next) {
+            assert(c->callback);
+            if (c->callback(w, &e, c->userdata) != 0)
+                break;
+        }
+    }
+}
+
+/* IO notification event for the X11 display connection */
+static void display_io_event(struct pa_mainloop_api *m, struct pa_io_event *e, int fd, enum pa_io_event_flags f, void *userdata) {
+    struct pa_x11_wrapper *w = userdata;
+    assert(m && e && fd >= 0 && w && w->ref >= 1);
+    work(w);
+}
+
+/* Deferred notification event. Called once each main loop iteration */
+static void defer_event(struct pa_mainloop_api *m, struct pa_defer_event *e, void *userdata) {
+    struct pa_x11_wrapper *w = userdata;
+    assert(m && e && w && w->ref >= 1);
+    work(w);
+}
+
+/* IO notification event for X11 internal connections */
+static void internal_io_event(struct pa_mainloop_api *m, struct pa_io_event *e, int fd, enum pa_io_event_flags f, void *userdata) {
+    struct pa_x11_wrapper *w = userdata;
+    assert(m && e && fd >= 0 && w && w->ref >= 1);
+
+    XProcessInternalConnection(w->display, fd);
+}
+
+/* Add a new IO source for the specified X11 internal connection */
+static struct pa_x11_internal* x11_internal_add(struct pa_x11_wrapper *w, int fd) {
+    struct pa_x11_internal *i;
+    assert(i && fd >= 0);
+
+    i = pa_xmalloc(sizeof(struct pa_x11_internal));
+    i->wrapper = w;
+    i->io_event = w->core->mainloop->io_new(w->core->mainloop, fd, PA_IO_EVENT_INPUT, internal_io_event, w);
+    i->fd = fd;
+
+    PA_LLIST_PREPEND(struct pa_x11_internal, w->internals, i);
+    return i;
+}
+
+/* Remove an IO source for an X11 internal connection */
+void x11_internal_remove(struct pa_x11_wrapper *w, struct pa_x11_internal *i) {
+    assert(i);
+
+    PA_LLIST_REMOVE(struct pa_x11_internal, w->internals, i);
+    w->core->mainloop->io_free(i->io_event);
+    pa_xfree(i);
+}
+
+/* Implementation of XConnectionWatchProc */
+static void x11_watch(Display *display, XPointer userdata, int fd, Bool opening, XPointer *watch_data) {
+    struct pa_x11_wrapper *w = (struct pa_x11_wrapper*) userdata;
+    assert(display && w && fd >= 0);
+
+    if (opening)
+        *watch_data = (XPointer) x11_internal_add(w, fd);
+    else
+        x11_internal_remove(w, (struct pa_x11_internal*) *watch_data);
+}
+
+static struct pa_x11_wrapper* x11_wrapper_new(struct pa_core *c, const char *name, const char *t) {
+    struct pa_x11_wrapper*w;
+    Display *d;
+    int r;
+
+    if (!(d = XOpenDisplay(name))) {
+        pa_log(__FILE__": XOpenDisplay() failed\n");
+        return NULL;
+    }
+
+    w = pa_xmalloc(sizeof(struct pa_x11_wrapper));
+    w->core = c;
+    w->ref = 1;
+    w->property_name = pa_xstrdup(t);
+    w->display = d;
+    
+    PA_LLIST_HEAD_INIT(struct pa_x11_client, w->clients);
+    PA_LLIST_HEAD_INIT(struct pa_x11_internal, w->internals);
+
+    w->defer_event = c->mainloop->defer_new(c->mainloop, defer_event, w);
+    w->io_event = c->mainloop->io_new(c->mainloop, ConnectionNumber(d), PA_IO_EVENT_INPUT, display_io_event, w);
+
+    XAddConnectionWatch(d, x11_watch, (XPointer) w);
+    
+    r = pa_property_set(c, w->property_name, w);
+    assert(r >= 0);
+    
+    return w;
+}
+
+static void x11_wrapper_free(struct pa_x11_wrapper*w) {
+    int r;
+    assert(w);
+
+    r = pa_property_remove(w->core, w->property_name);
+    assert(r >= 0);
+
+    assert(!w->clients);
+
+    XRemoveConnectionWatch(w->display, x11_watch, (XPointer) w);
+    XCloseDisplay(w->display);
+    
+    w->core->mainloop->io_free(w->io_event);
+    w->core->mainloop->defer_free(w->defer_event);
+
+    while (w->internals)
+        x11_internal_remove(w, w->internals);
+    
+    pa_xfree(w->property_name);
+    pa_xfree(w);
+}
+
+struct pa_x11_wrapper* pa_x11_wrapper_get(struct pa_core *c, const char *name) {
+    char t[256];
+    struct pa_x11_wrapper *w;
+    assert(c);
+        
+    snprintf(t, sizeof(t), "x11-wrapper%s%s", name ? "-" : "", name ? name : "");
+    if ((w = pa_property_get(c, t)))
+        return pa_x11_wrapper_ref(w);
+
+    return x11_wrapper_new(c, name, t);
+}
+
+struct pa_x11_wrapper* pa_x11_wrapper_ref(struct pa_x11_wrapper *w) {
+    assert(w && w->ref >= 1);
+    w->ref++;
+    return w;
+}
+
+void pa_x11_wrapper_unref(struct pa_x11_wrapper* w) {
+    assert(w && w->ref >= 1);
+
+    if (!(--w->ref))
+        x11_wrapper_free(w);
+}
+
+Display *pa_x11_wrapper_get_display(struct pa_x11_wrapper *w) {
+    assert(w && w->ref >= 1);
+    return w->display;
+}
+
+struct pa_x11_client* pa_x11_client_new(struct pa_x11_wrapper *w, int (*cb)(struct pa_x11_wrapper *w, XEvent *e, void *userdata), void *userdata) {
+    struct pa_x11_client *c;
+    assert(w && w->ref >= 1);
+
+    c = pa_xmalloc(sizeof(struct pa_x11_client));
+    c->wrapper = w;
+    c->callback = cb;
+    c->userdata = userdata;
+
+    PA_LLIST_PREPEND(struct pa_x11_client, w->clients, c);
+
+    return c;
+}
+
+void pa_x11_client_free(struct pa_x11_client *c) {
+    assert(c && c->wrapper && c->wrapper->ref >= 1);
+
+    PA_LLIST_REMOVE(struct pa_x11_client, c->wrapper->clients, c);
+    pa_xfree(c);
+}
diff --git a/polyp/x11wrap.h b/polyp/x11wrap.h
new file mode 100644 (file)
index 0000000..79c6901
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef foox11wraphfoo
+#define foox11wraphfoo
+
+/* $Id$ */
+
+/***
+  This file is part of polypaudio.
+  polypaudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published
+  by the Free Software Foundation; either version 2 of the License,
+  or (at your option) any later version.
+  polypaudio 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.
+  You should have received a copy of the GNU General Public License
+  along with polypaudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <X11/Xlib.h>
+
+#include "core.h"
+
+struct pa_x11_wrapper;
+
+/* Return the X11 wrapper for this core. In case no wrapper was
+    existant before, allocate a new one */
+struct pa_x11_wrapper* pa_x11_wrapper_get(struct pa_core *c, const char *name);
+
+/* Increase the wrapper's reference count by one */
+struct pa_x11_wrapper* pa_x11_wrapper_ref(struct pa_x11_wrapper *w);
+
+/* Decrease the reference counter of an X11 wrapper object */
+void pa_x11_wrapper_unref(struct pa_x11_wrapper* w);
+
+/* Return the X11 display object for this connection */
+Display *pa_x11_wrapper_get_display(struct pa_x11_wrapper *w);
+
+struct pa_x11_client;
+
+/* Register an X11 client, that is called for each X11 event */
+struct pa_x11_client* pa_x11_client_new(struct pa_x11_wrapper *w, int (*cb)(struct pa_x11_wrapper *w, XEvent *e, void *userdata), void *userdata);
+
+/* Free an X11 client object */
+void pa_x11_client_free(struct pa_x11_client *c);
+
+#endif