4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <pulse/xmalloc.h>
29 #include <pulsecore/log.h>
30 #include <pulsecore/macro.h>
34 typedef struct pa_property
{
35 char *name
; /* Points to memory allocated by the property subsystem */
36 void *data
; /* Points to memory maintained by the caller */
39 /* Allocate a new property object */
40 static pa_property
* property_new(const char *name
, void *data
) {
46 p
= pa_xnew(pa_property
, 1);
47 p
->name
= pa_xstrdup(name
);
53 /* Free a property object */
54 static void property_free(pa_property
*p
) {
61 void* pa_property_get(pa_core
*c
, const char *name
) {
66 pa_assert(c
->properties
);
68 if (!(p
= pa_hashmap_get(c
->properties
, name
)))
74 int pa_property_set(pa_core
*c
, const char *name
, void *data
) {
80 pa_assert(c
->properties
);
82 if (pa_hashmap_get(c
->properties
, name
))
85 p
= property_new(name
, data
);
86 pa_hashmap_put(c
->properties
, p
->name
, p
);
90 int pa_property_remove(pa_core
*c
, const char *name
) {
95 pa_assert(c
->properties
);
97 if (!(p
= pa_hashmap_remove(c
->properties
, name
)))
104 void pa_property_init(pa_core
*c
) {
107 c
->properties
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
110 void pa_property_cleanup(pa_core
*c
) {
116 pa_assert(!pa_hashmap_size(c
->properties
));
118 pa_hashmap_free(c
->properties
, NULL
, NULL
);
119 c
->properties
= NULL
;
123 void pa_property_dump(pa_core
*c
, pa_strbuf
*s
) {
130 while ((p
= pa_hashmap_iterate(c
->properties
, &state
, NULL
)))
131 pa_strbuf_printf(s
, "[%s] -> [%p]\n", p
->name
, p
->data
);
134 int pa_property_replace(pa_core
*c
, const char *name
, void *data
) {
138 pa_property_remove(c
, name
);
139 return pa_property_set(c
, name
, data
);