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
26 #include <pulse/xmalloc.h>
28 #include <pulsecore/log.h>
32 typedef struct pa_property
{
33 char *name
; /* Points to memory allocated by the property subsystem */
34 void *data
; /* Points to memory maintained by the caller */
37 /* Allocate a new property object */
38 static pa_property
* property_new(const char *name
, void *data
) {
42 p
= pa_xmalloc(sizeof(pa_property
));
43 p
->name
= pa_xstrdup(name
);
49 /* Free a property object */
50 static void property_free(pa_property
*p
) {
57 void* pa_property_get(pa_core
*c
, const char *name
) {
59 assert(c
&& name
&& c
->properties
);
61 if (!(p
= pa_hashmap_get(c
->properties
, name
)))
67 int pa_property_set(pa_core
*c
, const char *name
, void *data
) {
69 assert(c
&& name
&& data
&& c
->properties
);
71 if (pa_hashmap_get(c
->properties
, name
))
74 p
= property_new(name
, data
);
75 pa_hashmap_put(c
->properties
, p
->name
, p
);
79 int pa_property_remove(pa_core
*c
, const char *name
) {
81 assert(c
&& name
&& c
->properties
);
83 if (!(p
= pa_hashmap_remove(c
->properties
, name
)))
90 void pa_property_init(pa_core
*c
) {
93 c
->properties
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
96 void pa_property_cleanup(pa_core
*c
) {
102 assert(!pa_hashmap_size(c
->properties
));
104 pa_hashmap_free(c
->properties
, NULL
, NULL
);
105 c
->properties
= NULL
;
109 void pa_property_dump(pa_core
*c
, pa_strbuf
*s
) {
114 while ((p
= pa_hashmap_iterate(c
->properties
, &state
, NULL
)))
115 pa_strbuf_printf(s
, "[%s] -> [%p]\n", p
->name
, p
->data
);
118 int pa_property_replace(pa_core
*c
, const char *name
, void *data
) {
121 pa_property_remove(c
, name
);
122 return pa_property_set(c
, name
, data
);