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
29 char *name
; /* Points to memory allocated by the property subsystem */
30 void *data
; /* Points to memory maintained by the caller */
33 /* Allocate a new property object */
34 static struct pa_property
* property_new(const char *name
, void *data
) {
35 struct pa_property
* p
;
38 p
= pa_xmalloc(sizeof(struct pa_property
));
39 p
->name
= pa_xstrdup(name
);
45 /* Free a property object */
46 static void property_free(struct pa_property
*p
) {
53 void* pa_property_get(struct pa_core
*c
, const char *name
) {
54 struct pa_property
*p
;
55 assert(c
&& name
&& c
->properties
);
57 if (!(p
= pa_hashmap_get(c
->properties
, name
)))
63 int pa_property_set(struct pa_core
*c
, const char *name
, void *data
) {
64 struct pa_property
*p
;
65 assert(c
&& name
&& data
&& c
->properties
);
67 if (pa_hashmap_get(c
->properties
, name
))
70 p
= property_new(name
, data
);
71 pa_hashmap_put(c
->properties
, p
->name
, p
);
75 int pa_property_remove(struct pa_core
*c
, const char *name
) {
76 struct pa_property
*p
;
77 assert(c
&& name
&& c
->properties
);
79 if (!(p
= pa_hashmap_remove(c
->properties
, name
)))
86 void pa_property_init(struct pa_core
*c
) {
89 c
->properties
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
92 void pa_property_cleanup(struct pa_core
*c
) {
98 assert(!pa_hashmap_ncontents(c
->properties
));
100 pa_hashmap_free(c
->properties
, NULL
, NULL
);
101 c
->properties
= NULL
;
105 void pa_property_dump(struct pa_core
*c
, struct pa_strbuf
*s
) {
107 struct pa_property
*p
;
110 while ((p
= pa_hashmap_iterate(c
->properties
, &state
, NULL
)))
111 pa_strbuf_printf(s
, "[%s] -> [%p]\n", p
->name
, p
->data
);
114 int pa_property_replace(struct pa_core
*c
, const char *name
, void *data
) {
117 pa_property_remove(c
, name
);
118 return pa_property_set(c
, name
, data
);