2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio 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.1 of the License,
9 or (at your option) any later version.
11 PulseAudio 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 PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulse/xmalloc.h>
27 #include <pulsecore/macro.h>
31 typedef struct pa_shared
{
32 char *name
; /* Points to memory allocated by the shared property system */
33 void *data
; /* Points to memory maintained by the caller */
36 /* Allocate a new shared property object */
37 static pa_shared
* shared_new(const char *name
, void *data
) {
43 p
= pa_xnew(pa_shared
, 1);
44 p
->name
= pa_xstrdup(name
);
50 /* Free a shared property object */
51 static void shared_free(pa_shared
*p
) {
58 void* pa_shared_get(pa_core
*c
, const char *name
) {
65 if (!(p
= pa_hashmap_get(c
->shared
, name
)))
71 int pa_shared_set(pa_core
*c
, const char *name
, void *data
) {
79 if (pa_hashmap_get(c
->shared
, name
))
82 p
= shared_new(name
, data
);
83 pa_hashmap_put(c
->shared
, p
->name
, p
);
87 int pa_shared_remove(pa_core
*c
, const char *name
) {
94 if (!(p
= pa_hashmap_remove(c
->shared
, name
)))
101 void pa_shared_dump(pa_core
*c
, pa_strbuf
*s
) {
108 while ((p
= pa_hashmap_iterate(c
->shared
, &state
, NULL
)))
109 pa_strbuf_printf(s
, "[%s] -> [%p]\n", p
->name
, p
->data
);
112 int pa_shared_replace(pa_core
*c
, const char *name
, void *data
) {
116 pa_shared_remove(c
, name
);
117 return pa_shared_set(c
, name
, data
);