[pulseaudio-commits] r2085 - in /trunk/src: Makefile.am map-file pulse/proplist.c pulse/proplist.h tests/proplist-test.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Sun Dec 23 12:12:40 PST 2007
Author: lennart
Date: Sun Dec 23 21:12:37 2007
New Revision: 2085
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2085&root=pulseaudio&view=rev
Log:
add new property list implementation
Added:
trunk/src/pulse/proplist.c (with props)
trunk/src/pulse/proplist.h (with props)
trunk/src/tests/proplist-test.c (with props)
Modified:
trunk/src/Makefile.am
trunk/src/map-file
Modified: trunk/src/Makefile.am
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/Makefile.am?rev=2085&root=pulseaudio&r1=2084&r2=2085&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Sun Dec 23 21:12:37 2007
@@ -254,7 +254,8 @@
smoother-test \
mix-test \
remix-test \
- envelope-test
+ envelope-test \
+ proplist-test
if HAVE_SIGXCPU
noinst_PROGRAMS += \
@@ -423,6 +424,11 @@
envelope_test_LDADD = $(AM_LDADD) libpulsecore.la
envelope_test_CFLAGS = $(AM_CFLAGS) $(LIBOIL_CFLAGS)
envelope_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBOIL_LIBS)
+
+proplist_test_SOURCES = tests/proplist-test.c
+proplist_test_LDADD = $(AM_LDADD) libpulse.la
+proplist_test_CFLAGS = $(AM_CFLAGS) $(LIBOIL_CFLAGS)
+proplist_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) $(LIBOIL_LIBS)
###################################
# Client library #
@@ -451,7 +457,8 @@
pulse/util.h \
pulse/version.h \
pulse/volume.h \
- pulse/xmalloc.h
+ pulse/xmalloc.h \
+ pulse/proplist.h
if HAVE_AVAHI
pulseinclude_HEADERS += \
@@ -501,7 +508,8 @@
pulse/utf8.c pulse/utf8.h \
pulse/util.c pulse/util.h \
pulse/volume.c pulse/volume.h \
- pulse/xmalloc.c pulse/xmalloc.h
+ pulse/xmalloc.c pulse/xmalloc.h \
+ pulse/proplist.c pulse/proplist.h
# Internal stuff that is shared with libpulsecore
libpulse_la_SOURCES += \
Modified: trunk/src/map-file
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/map-file?rev=2085&root=pulseaudio&r1=2084&r2=2085&view=diff
==============================================================================
--- trunk/src/map-file (original)
+++ trunk/src/map-file Sun Dec 23 21:12:37 2007
@@ -127,6 +127,16 @@
pa_operation_unref;
pa_parse_sample_format;
pa_path_get_filename;
+pa_proplist_free;
+pa_proplist_get;
+pa_proplist_gets;
+pa_proplist_iterate;
+pa_proplist_merge;
+pa_proplist_new;
+pa_proplist_put;
+pa_proplist_puts;
+pa_proplist_remove;
+pa_proplist_to_string;
pa_sample_format_to_string;
pa_sample_size;
pa_sample_spec_equal;
Added: trunk/src/pulse/proplist.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulse/proplist.c?rev=2085&root=pulseaudio&view=auto
==============================================================================
--- trunk/src/pulse/proplist.c (added)
+++ trunk/src/pulse/proplist.c Sun Dec 23 21:12:37 2007
@@ -1,0 +1,244 @@
+/* $Id$ */
+
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2007 Lennart Poettering
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ PulseAudio 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with PulseAudio; 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 <string.h>
+
+#include <pulse/xmalloc.h>
+#include <pulse/utf8.h>
+
+#include <pulsecore/hashmap.h>
+#include <pulsecore/strbuf.h>
+#include <pulsecore/core-util.h>
+
+#include "proplist.h"
+
+struct property {
+ char *key;
+ void *value;
+ size_t nbytes;
+};
+
+#define MAKE_HASHMAP(p) ((pa_hashmap*) (p))
+#define MAKE_PROPLIST(p) ((pa_proplist*) (p))
+
+static pa_bool_t property_name_valid(const char *key) {
+
+ if (!pa_utf8_valid(key))
+ return FALSE;
+
+ if (strlen(key) <= 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static void property_free(struct property *prop) {
+ pa_assert(prop);
+
+ pa_xfree(prop->key);
+ pa_xfree(prop->value);
+ pa_xfree(prop);
+}
+
+pa_proplist* pa_proplist_new(void) {
+ return MAKE_PROPLIST(pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func));
+}
+
+void pa_proplist_free(pa_proplist* p) {
+ struct property *prop;
+
+ while ((prop = pa_hashmap_steal_first(MAKE_HASHMAP(p))))
+ property_free(prop);
+
+ pa_hashmap_free(MAKE_HASHMAP(p), NULL, NULL);
+}
+
+/** Will accept only valid UTF-8 */
+int pa_proplist_puts(pa_proplist *p, const char *key, const char *value) {
+ struct property *prop;
+ pa_bool_t add = FALSE;
+
+ pa_assert(p);
+ pa_assert(key);
+
+ if (!property_name_valid(key) || !pa_utf8_valid(value))
+ return -1;
+
+ if (!(prop = pa_hashmap_get(MAKE_HASHMAP(p), key))) {
+ prop = pa_xnew(struct property, 1);
+ prop->key = pa_xstrdup(key);
+ add = TRUE;
+ } else
+ pa_xfree(prop->value);
+
+ prop->value = pa_xstrdup(value);
+ prop->nbytes = strlen(value)+1;
+
+ if (add)
+ pa_hashmap_put(MAKE_HASHMAP(p), prop->key, prop);
+
+ return 0;
+}
+
+int pa_proplist_put(pa_proplist *p, const char *key, const void *data, size_t nbytes) {
+ struct property *prop;
+ pa_bool_t add = FALSE;
+
+ pa_assert(p);
+ pa_assert(key);
+
+ if (!property_name_valid(key))
+ return -1;
+
+ if (!(prop = pa_hashmap_get(MAKE_HASHMAP(p), key))) {
+ prop = pa_xnew(struct property, 1);
+ prop->key = pa_xstrdup(key);
+ add = TRUE;
+ } else
+ pa_xfree(prop->value);
+
+ prop->value = pa_xmemdup(data, nbytes);
+ prop->nbytes = nbytes;
+
+ if (add)
+ pa_hashmap_put(MAKE_HASHMAP(p), prop->key, prop);
+
+ return 0;
+}
+
+const char *pa_proplist_gets(pa_proplist *p, const char *key) {
+ struct property *prop;
+
+ pa_assert(p);
+ pa_assert(key);
+
+ if (!property_name_valid(key))
+ return NULL;
+
+ if (!(prop = pa_hashmap_get(MAKE_HASHMAP(p), key)))
+ return NULL;
+
+ if (prop->nbytes <= 0)
+ return NULL;
+
+ if (((char*) prop->value)[prop->nbytes-1] != 0)
+ return NULL;
+
+ if (strlen((char*) prop->value) != prop->nbytes-1)
+ return NULL;
+
+ if (!pa_utf8_valid((char*) prop->value))
+ return NULL;
+
+ return (char*) prop->value;
+}
+
+int pa_proplist_get(pa_proplist *p, const char *key, const void **data, size_t *nbytes) {
+ struct property *prop;
+
+ pa_assert(p);
+ pa_assert(key);
+
+ if (!property_name_valid(key))
+ return -1;
+
+ if (!(prop = pa_hashmap_get(MAKE_HASHMAP(p), key)))
+ return -1;
+
+ *data = prop->value;
+ *nbytes = prop->nbytes;
+
+ return 0;
+}
+
+void pa_proplist_merge(pa_proplist *p, pa_proplist *other) {
+ struct property *prop;
+ void *state = NULL;
+
+ pa_assert(p);
+ pa_assert(other);
+
+ while ((prop = pa_hashmap_iterate(MAKE_HASHMAP(other), &state, NULL)))
+ pa_assert_se(pa_proplist_put(p, prop->key, prop->value, prop->nbytes) == 0);
+}
+
+int pa_proplist_remove(pa_proplist *p, const char *key) {
+ struct property *prop;
+
+ pa_assert(p);
+ pa_assert(key);
+
+ if (!property_name_valid(key))
+ return -1;
+
+ if (!(prop = pa_hashmap_remove(MAKE_HASHMAP(p), key)))
+ return -1;
+
+ property_free(prop);
+ return 0;
+}
+
+const char *pa_proplist_iterate(pa_proplist *p, void **state) {
+ struct property *prop;
+
+ if (!(prop = pa_hashmap_iterate(MAKE_HASHMAP(p), state, NULL)))
+ return NULL;
+
+ return prop->key;
+}
+
+char *pa_proplist_to_string(pa_proplist *p) {
+ const char *key;
+ void *state = NULL;
+ pa_strbuf *buf;
+
+ pa_assert(p);
+
+ buf = pa_strbuf_new();
+
+ while ((key = pa_proplist_iterate(p, &state))) {
+
+ const char *v;
+
+ if ((v = pa_proplist_gets(p, key)))
+ pa_strbuf_printf(buf, "%s = \"%s\"\n", key, v);
+ else {
+ const void *value;
+ size_t nbytes;
+ char *c;
+
+ pa_assert_se(pa_proplist_get(p, key, &value, &nbytes) == 0);
+ c = pa_xnew(char, nbytes*2+1);
+ pa_hexstr((const uint8_t*) value, nbytes, c, nbytes*2+1);
+
+ pa_strbuf_printf(buf, "%s = hex:%s\n", key, c);
+ pa_xfree(c);
+ }
+ }
+
+ return pa_strbuf_tostring_free(buf);
+}
Propchange: trunk/src/pulse/proplist.c
------------------------------------------------------------------------------
svn:keywords = Id
Added: trunk/src/pulse/proplist.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulse/proplist.h?rev=2085&root=pulseaudio&view=auto
==============================================================================
--- trunk/src/pulse/proplist.h (added)
+++ trunk/src/pulse/proplist.h Sun Dec 23 21:12:37 2007
@@ -1,0 +1,88 @@
+#ifndef foopulseproplisthfoo
+#define foopulseproplisthfoo
+
+/* $Id$ */
+
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2007 Lennart Poettering
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ PulseAudio 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <pulsecore/macro.h>
+
+/* Defined properties:
+ *
+ * x11.xid
+ * x11.display
+ * x11.x_pointer
+ * x11.y_pointer
+ * x11.button
+ * media.name
+ * media.title
+ * media.artist
+ * media.language
+ * media.filename
+ * media.icon
+ * media.icon_name
+ * media.role video, music, game, event, phone, production
+ * application.name
+ * application.version
+ * application.icon
+ * application.icon_name
+ */
+
+#define PA_PROP_X11_XID "x11.xid"
+#define PA_PROP_X11_DISPLAY "x11.display"
+#define PA_PROP_X11_X_POINTER "x11.x_pointer"
+#define PA_PROP_X11_Y_POINTER "x11.y_pointer"
+#define PA_PROP_X11_BUTTON "x11.button"
+#define PA_PROP_MEDIA_NAME "media.name"
+#define PA_PROP_MEDIA_TITLE "media.title"
+#define PA_PROP_MEDIA_ARTIST "media.artist"
+#define PA_PROP_MEDIA_LANGUAGE "media.language"
+#define PA_PROP_MEDIA_FILENAME "media.filename"
+#define PA_PROP_MEDIA_ICON "media.icon"
+#define PA_PROP_MEDIA_ICON_NAME "media.icon_name"
+#define PA_PROP_MEDIA_ROLE "media.role"
+#define PA_PROP_APPLICATION_NAME "application.name"
+#define PA_PROP_APPLICATION_VERSION "application.version"
+#define PA_PROP_APPLICATION_ICON "application.icon"
+#define PA_PROP_APPLICATION_ICON_NAME "application.icon_name"
+
+typedef struct pa_proplist pa_proplist;
+
+pa_proplist* pa_proplist_new(void);
+void pa_proplist_free(pa_proplist* p);
+
+/** Will accept only valid UTF-8 */
+int pa_proplist_puts(pa_proplist *p, const char *key, const char *value);
+int pa_proplist_put(pa_proplist *p, const char *key, const void *data, size_t nbytes);
+
+/* Will return NULL if the data is not valid UTF-8 */
+const char *pa_proplist_gets(pa_proplist *p, const char *key);
+int pa_proplist_get(pa_proplist *p, const char *key, const void **data, size_t *nbytes);
+
+void pa_proplist_merge(pa_proplist *p, pa_proplist *other);
+int pa_proplist_remove(pa_proplist *p, const char *key);
+
+const char *pa_proplist_iterate(pa_proplist *p, void **state);
+
+char *pa_proplist_to_string(pa_proplist *p);
+
+#endif
Propchange: trunk/src/pulse/proplist.h
------------------------------------------------------------------------------
svn:keywords = Id
Added: trunk/src/tests/proplist-test.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/tests/proplist-test.c?rev=2085&root=pulseaudio&view=auto
==============================================================================
--- trunk/src/tests/proplist-test.c (added)
+++ trunk/src/tests/proplist-test.c Sun Dec 23 21:12:37 2007
@@ -1,0 +1,61 @@
+/* $Id$ */
+
+/***
+ This file is part of PulseAudio.
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ PulseAudio 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 Lesser General Public License
+ along with PulseAudio; 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 <pulse/proplist.h>
+#include <pulse/xmalloc.h>
+#include <pulsecore/macro.h>
+
+int main(int argc, char*argv[]) {
+ pa_proplist *a, *b;
+ char *s, *t;
+
+ a = pa_proplist_new();
+ pa_assert_se(pa_proplist_puts(a, PA_PROP_MEDIA_TITLE, "Brandenburgische Konzerte") == 0);
+ pa_assert_se(pa_proplist_puts(a, PA_PROP_MEDIA_ARTIST, "Johann Sebastian Bach") == 0);
+
+ b = pa_proplist_new();
+ pa_assert_se(pa_proplist_puts(b, PA_PROP_MEDIA_TITLE, "Goldbergvariationen") == 0);
+ pa_assert_se(pa_proplist_put(b, PA_PROP_MEDIA_ICON, "\0\1\2\3\4\5\6\7", 8) == 0);
+
+ pa_proplist_merge(a, b);
+
+ pa_assert_se(!pa_proplist_gets(a, PA_PROP_MEDIA_ICON));
+
+ printf("%s\n", pa_strnull(pa_proplist_gets(a, PA_PROP_MEDIA_TITLE)));
+ pa_assert_se(pa_proplist_remove(b, PA_PROP_MEDIA_TITLE) == 0);
+
+ s = pa_proplist_to_string(a);
+ t = pa_proplist_to_string(b);
+ printf("---\n%s---\n%s", s, t);
+ pa_xfree(s);
+ pa_xfree(t);
+
+ pa_proplist_free(a);
+ pa_proplist_free(b);
+
+ return 0;
+}
Propchange: trunk/src/tests/proplist-test.c
------------------------------------------------------------------------------
svn:keywords = Id
More information about the pulseaudio-commits
mailing list