4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio 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 License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 #include <polyp/xmalloc.h>
26 #include <polypcore/log.h>
30 typedef struct pa_property
{
31 char *name
; /* Points to memory allocated by the property subsystem */
32 void *data
; /* Points to memory maintained by the caller */
35 /* Allocate a new property object */
36 static pa_property
* property_new(const char *name
, void *data
) {
40 p
= pa_xmalloc(sizeof(pa_property
));
41 p
->name
= pa_xstrdup(name
);
47 /* Free a property object */
48 static void property_free(pa_property
*p
) {
55 void* pa_property_get(pa_core
*c
, const char *name
) {
57 assert(c
&& name
&& c
->properties
);
59 if (!(p
= pa_hashmap_get(c
->properties
, name
)))
65 int pa_property_set(pa_core
*c
, const char *name
, void *data
) {
67 assert(c
&& name
&& data
&& c
->properties
);
69 if (pa_hashmap_get(c
->properties
, name
))
72 p
= property_new(name
, data
);
73 pa_hashmap_put(c
->properties
, p
->name
, p
);
77 int pa_property_remove(pa_core
*c
, const char *name
) {
79 assert(c
&& name
&& c
->properties
);
81 if (!(p
= pa_hashmap_remove(c
->properties
, name
)))
88 void pa_property_init(pa_core
*c
) {
91 c
->properties
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
94 void pa_property_cleanup(pa_core
*c
) {
100 assert(!pa_hashmap_size(c
->properties
));
102 pa_hashmap_free(c
->properties
, NULL
, NULL
);
103 c
->properties
= NULL
;
107 void pa_property_dump(pa_core
*c
, pa_strbuf
*s
) {
112 while ((p
= pa_hashmap_iterate(c
->properties
, &state
, NULL
)))
113 pa_strbuf_printf(s
, "[%s] -> [%p]\n", p
->name
, p
->data
);
116 int pa_property_replace(pa_core
*c
, const char *name
, void *data
) {
119 pa_property_remove(c
, name
);
120 return pa_property_set(c
, name
, data
);