rename pa_property_xxx to pa_shared_xxx to avoid confusion with property lists

This commit is contained in:
Lennart Poettering 2008-08-01 01:56:09 +03:00
parent a5a7b79938
commit edc56a7f7a
10 changed files with 84 additions and 83 deletions

View file

@ -254,7 +254,7 @@ static pa_dbus_connection* pa_dbus_connection_new(pa_core* c, DBusConnection *co
pconn->connection = conn; pconn->connection = conn;
pconn->dispatch_event = c->mainloop->defer_new(c->mainloop, dispatch_cb, conn); pconn->dispatch_event = c->mainloop->defer_new(c->mainloop, dispatch_cb, conn);
pa_property_set(c, name, pconn); pa_shared_set(c, name, pconn);
return pconn; return pconn;
} }
@ -282,7 +282,7 @@ void pa_dbus_connection_unref(pa_dbus_connection *c) {
} }
/* already disconnected, just free */ /* already disconnected, just free */
pa_property_remove(c->core, c->property_name); pa_shared_remove(c->core, c->property_name);
c->core->mainloop->defer_free(c->dispatch_event); c->core->mainloop->defer_free(c->dispatch_event);
dbus_connection_unref(c->connection); dbus_connection_unref(c->connection);
pa_xfree(c); pa_xfree(c);
@ -309,7 +309,7 @@ pa_dbus_connection* pa_dbus_bus_get(pa_core *c, DBusBusType type, DBusError *err
pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER); pa_assert(type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION || type == DBUS_BUS_STARTER);
if ((pconn = pa_property_get(c, prop_name[type]))) if ((pconn = pa_shared_get(c, prop_name[type])))
return pa_dbus_connection_ref(pconn); return pa_dbus_connection_ref(pconn);
if (!(conn = dbus_bus_get_private(type, error))) if (!(conn = dbus_bus_get_private(type, error)))

View file

@ -152,7 +152,7 @@ int pa__init(pa_module*m) {
if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL)))) if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
goto fail; goto fail;
if (!(l = pa_property_get(m->core, PA_NATIVE_SERVER_PROPERTY_NAME))) if (!(l = pa_shared_get(m->core, PA_NATIVE_SERVER_PROPERTY_NAME)))
goto fail; goto fail;
l = pa_strlist_reverse(l); l = pa_strlist_reverse(l);

View file

@ -47,7 +47,7 @@ int pa_authkey_prop_get(pa_core *c, const char *name, void *data, size_t len) {
pa_assert(data); pa_assert(data);
pa_assert(len > 0); pa_assert(len > 0);
if (!(a = pa_property_get(c, name))) if (!(a = pa_shared_get(c, name)))
return -1; return -1;
pa_assert(a->length == len); pa_assert(a->length == len);
@ -62,7 +62,7 @@ int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t l
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
if (pa_property_get(c, name)) if (pa_shared_get(c, name))
return -1; return -1;
a = pa_xmalloc(PA_ALIGN(sizeof(struct authkey_data)) + len); a = pa_xmalloc(PA_ALIGN(sizeof(struct authkey_data)) + len);
@ -70,7 +70,7 @@ int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t l
a->length = len; a->length = len;
memcpy((uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), data, len); memcpy((uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), data, len);
pa_property_set(c, name, a); pa_shared_set(c, name, a);
return 0; return 0;
} }
@ -81,7 +81,7 @@ void pa_authkey_prop_ref(pa_core *c, const char *name) {
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
a = pa_property_get(c, name); a = pa_shared_get(c, name);
pa_assert(a); pa_assert(a);
pa_assert(PA_REFCNT_VALUE(a) >= 1); pa_assert(PA_REFCNT_VALUE(a) >= 1);
PA_REFCNT_INC(a); PA_REFCNT_INC(a);
@ -93,14 +93,12 @@ void pa_authkey_prop_unref(pa_core *c, const char *name) {
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
a = pa_property_get(c, name); a = pa_shared_get(c, name);
pa_assert(a); pa_assert(a);
pa_assert(PA_REFCNT_VALUE(a) >= 1); pa_assert(PA_REFCNT_VALUE(a) >= 1);
if (PA_REFCNT_DEC(a) <= 0) { if (PA_REFCNT_DEC(a) <= 0) {
pa_property_remove(c, name); pa_shared_remove(c, name);
pa_xfree(a); pa_xfree(a);
} }
} }

View file

@ -110,7 +110,7 @@ static int pa_cli_command_autoload_list(pa_core *c, pa_tokenizer *t, pa_strbuf *
static int pa_cli_command_autoload_add(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_autoload_add(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_autoload_remove(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_autoload_remove(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_list_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_list_shared_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_move_sink_input(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_move_sink_input(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_move_source_output(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_move_source_output(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_vacuum(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail); static int pa_cli_command_vacuum(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
@ -160,7 +160,7 @@ static const struct command commands[] = {
{ "remove-autoload-sink", pa_cli_command_autoload_remove, NULL /*"Remove autoload entry for a sink (args: name)"*/, 2}, { "remove-autoload-sink", pa_cli_command_autoload_remove, NULL /*"Remove autoload entry for a sink (args: name)"*/, 2},
{ "remove-autoload-source", pa_cli_command_autoload_remove, NULL /*"Remove autoload entry for a source (args: name)"*/, 2}, { "remove-autoload-source", pa_cli_command_autoload_remove, NULL /*"Remove autoload entry for a source (args: name)"*/, 2},
{ "dump", pa_cli_command_dump, "Dump daemon configuration", 1}, { "dump", pa_cli_command_dump, "Dump daemon configuration", 1},
{ "list-props", pa_cli_command_list_props, NULL, 1}, { "shared", pa_cli_command_list_shared_props, NULL, 1},
{ "move-sink-input", pa_cli_command_move_sink_input, "Move sink input to another sink (args: index, sink)", 3}, { "move-sink-input", pa_cli_command_move_sink_input, "Move sink input to another sink (args: index, sink)", 3},
{ "move-source-output", pa_cli_command_move_source_output, "Move source output to another source (args: index, source)", 3}, { "move-source-output", pa_cli_command_move_source_output, "Move source output to another source (args: index, source)", 3},
{ "vacuum", pa_cli_command_vacuum, NULL, 1}, { "vacuum", pa_cli_command_vacuum, NULL, 1},
@ -996,13 +996,13 @@ static int pa_cli_command_autoload_list(pa_core *c, pa_tokenizer *t, pa_strbuf *
return 0; return 0;
} }
static int pa_cli_command_list_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) { static int pa_cli_command_list_shared_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
pa_core_assert_ref(c); pa_core_assert_ref(c);
pa_assert(t); pa_assert(t);
pa_assert(buf); pa_assert(buf);
pa_assert(fail); pa_assert(fail);
pa_property_dump(c, buf); pa_shared_dump(c, buf);
return 0; return 0;
} }

View file

@ -141,7 +141,7 @@ pa_core* pa_core_new(pa_mainloop_api *m, int shared) {
for (j = 0; j < PA_CORE_HOOK_MAX; j++) for (j = 0; j < PA_CORE_HOOK_MAX; j++)
pa_hook_init(&c->hooks[j], c); pa_hook_init(&c->hooks[j], c);
pa_property_init(c); pa_shared_init(c);
pa_random(&c->cookie, sizeof(c->cookie)); pa_random(&c->cookie, sizeof(c->cookie));
@ -189,7 +189,7 @@ static void core_free(pa_object *o) {
pa_silence_cache_done(&c->silence_cache); pa_silence_cache_done(&c->silence_cache);
pa_mempool_free(c->mempool); pa_mempool_free(c->mempool);
pa_property_cleanup(c); pa_shared_cleanup(c);
for (j = 0; j < PA_CORE_HOOK_MAX; j++) for (j = 0; j < PA_CORE_HOOK_MAX; j++)
pa_hook_free(&c->hooks[j]); pa_hook_free(&c->hooks[j]);

View file

@ -94,7 +94,7 @@ struct pa_core {
pa_idxset *clients, *sinks, *sources, *sink_inputs, *source_outputs, *modules, *scache, *autoload_idxset; pa_idxset *clients, *sinks, *sources, *sink_inputs, *source_outputs, *modules, *scache, *autoload_idxset;
/* Some hashmaps for all sorts of entities */ /* Some hashmaps for all sorts of entities */
pa_hashmap *namereg, *autoload_hashmap, *properties; pa_hashmap *namereg, *autoload_hashmap, *shared;
/* The name of the default sink/source */ /* The name of the default sink/source */
char *default_source_name, *default_sink_name; char *default_source_name, *default_sink_name;

View file

@ -29,110 +29,110 @@
#include "props.h" #include "props.h"
typedef struct pa_property { typedef struct pa_shared {
char *name; /* Points to memory allocated by the property subsystem */ char *name; /* Points to memory allocated by the shared property system */
void *data; /* Points to memory maintained by the caller */ void *data; /* Points to memory maintained by the caller */
} pa_property; } pa_shared;
/* Allocate a new property object */ /* Allocate a new shared property object */
static pa_property* property_new(const char *name, void *data) { static pa_shared* shared_new(const char *name, void *data) {
pa_property* p; pa_shared* p;
pa_assert(name); pa_assert(name);
pa_assert(data); pa_assert(data);
p = pa_xnew(pa_property, 1); p = pa_xnew(pa_shared, 1);
p->name = pa_xstrdup(name); p->name = pa_xstrdup(name);
p->data = data; p->data = data;
return p; return p;
} }
/* Free a property object */ /* Free a shared property object */
static void property_free(pa_property *p) { static void shared_free(pa_shared *p) {
pa_assert(p); pa_assert(p);
pa_xfree(p->name); pa_xfree(p->name);
pa_xfree(p); pa_xfree(p);
} }
void* pa_property_get(pa_core *c, const char *name) { void* pa_shared_get(pa_core *c, const char *name) {
pa_property *p; pa_shared *p;
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
pa_assert(c->properties); pa_assert(c->shared);
if (!(p = pa_hashmap_get(c->properties, name))) if (!(p = pa_hashmap_get(c->shared, name)))
return NULL; return NULL;
return p->data; return p->data;
} }
int pa_property_set(pa_core *c, const char *name, void *data) { int pa_shared_set(pa_core *c, const char *name, void *data) {
pa_property *p; pa_shared *p;
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
pa_assert(data); pa_assert(data);
pa_assert(c->properties); pa_assert(c->shared);
if (pa_hashmap_get(c->properties, name)) if (pa_hashmap_get(c->shared, name))
return -1; return -1;
p = property_new(name, data); p = shared_new(name, data);
pa_hashmap_put(c->properties, p->name, p); pa_hashmap_put(c->shared, p->name, p);
return 0; return 0;
} }
int pa_property_remove(pa_core *c, const char *name) { int pa_shared_remove(pa_core *c, const char *name) {
pa_property *p; pa_shared *p;
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
pa_assert(c->properties); pa_assert(c->shared);
if (!(p = pa_hashmap_remove(c->properties, name))) if (!(p = pa_hashmap_remove(c->shared, name)))
return -1; return -1;
property_free(p); shared_free(p);
return 0; return 0;
} }
void pa_property_init(pa_core *c) { void pa_shared_init(pa_core *c) {
pa_assert(c); pa_assert(c);
c->properties = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); c->shared = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
} }
void pa_property_cleanup(pa_core *c) { void pa_shared_cleanup(pa_core *c) {
pa_assert(c); pa_assert(c);
if (!c->properties) if (!c->shared)
return; return;
pa_assert(!pa_hashmap_size(c->properties)); pa_assert(pa_hashmap_isempty(c->shared));
pa_hashmap_free(c->properties, NULL, NULL); pa_hashmap_free(c->shared, NULL, NULL);
c->properties = NULL; c->shared = NULL;
} }
void pa_property_dump(pa_core *c, pa_strbuf *s) { void pa_shared_dump(pa_core *c, pa_strbuf *s) {
void *state = NULL; void *state = NULL;
pa_property *p; pa_shared *p;
pa_assert(c); pa_assert(c);
pa_assert(s); pa_assert(s);
while ((p = pa_hashmap_iterate(c->properties, &state, NULL))) while ((p = pa_hashmap_iterate(c->shared, &state, NULL)))
pa_strbuf_printf(s, "[%s] -> [%p]\n", p->name, p->data); pa_strbuf_printf(s, "[%s] -> [%p]\n", p->name, p->data);
} }
int pa_property_replace(pa_core *c, const char *name, void *data) { int pa_shared_replace(pa_core *c, const char *name, void *data) {
pa_assert(c); pa_assert(c);
pa_assert(name); pa_assert(name);
pa_property_remove(c, name); pa_shared_remove(c, name);
return pa_property_set(c, name, data); return pa_shared_set(c, name, data);
} }

View file

@ -1,5 +1,5 @@
#ifndef foopropshfoo #ifndef foosharedshfoo
#define foopropshfoo #define foosharedshfoo
/*** /***
This file is part of PulseAudio. This file is part of PulseAudio.
@ -25,34 +25,37 @@
#include <pulsecore/core.h> #include <pulsecore/core.h>
#include <pulsecore/strbuf.h> #include <pulsecore/strbuf.h>
/* The property subsystem is to be used to share data between /* The shared property subsystem is to be used to share data between
* modules. Consider them to be kind of "global" variables for a * modules. Consider them to be kind of "global" variables for a
* core. Why not use the hashmap functions directly? The hashmap * core. Why not use the hashmap functions directly? The hashmap
* functions copy neither the key nor value, while this property * functions copy neither the key nor value, while this property
* system copies the key. Users of this system have to think about * system copies the key. Users of this system have to think about
* reference counting themselves. */ * reference counting themselves. */
/* Return a pointer to the value of the specified property. */ /* Note: please don't confuse this with the proplist framework in
void* pa_property_get(pa_core *c, const char *name); * pulse/proplist.[ch]! */
/* Set the property 'name' to 'data'. This function fails in case a /* Return a pointer to the value of the specified shared property. */
* property by this name already exists. The property data is not void* pa_shared_get(pa_core *c, const char *name);
* copied or reference counted. This is the caller's job. */
int pa_property_set(pa_core *c, const char *name, void *data);
/* Remove the specified property. Return non-zero on failure */ /* Set the shared property 'name' to 'data'. This function fails in
int pa_property_remove(pa_core *c, const char *name); * case a property by this name already exists. The property data is
* not copied or reference counted. This is the caller's job. */
int pa_shared_set(pa_core *c, const char *name, void *data);
/* A combination of pa_property_remove() and pa_property_set() */ /* Remove the specified shared property. Return non-zero on failure */
int pa_property_replace(pa_core *c, const char *name, void *data); int pa_shared_remove(pa_core *c, const char *name);
/* Free all memory used by the property system */ /* A combination of pa_shared_remove() and pa_shared_set() */
void pa_property_cleanup(pa_core *c); int pa_shared_replace(pa_core *c, const char *name, void *data);
/* Initialize the properties subsystem */ /* Free all memory used by the shared property system */
void pa_property_init(pa_core *c); void pa_shared_cleanup(pa_core *c);
/* Dump the current set of properties */ /* Initialize the shared property system */
void pa_property_dump(pa_core *c, pa_strbuf *s); void pa_shared_init(pa_core *c);
/* Dump the current set of shared properties */
void pa_shared_dump(pa_core *c, pa_strbuf *s);
#endif #endif

View file

@ -4134,9 +4134,9 @@ pa_protocol_native* pa_protocol_native_new(pa_core *core, pa_socket_server *serv
if (pa_socket_server_get_address(p->server, t, sizeof(t))) { if (pa_socket_server_get_address(p->server, t, sizeof(t))) {
pa_strlist *l; pa_strlist *l;
l = pa_property_get(core, PA_NATIVE_SERVER_PROPERTY_NAME); l = pa_shared_get(core, PA_NATIVE_SERVER_PROPERTY_NAME);
l = pa_strlist_prepend(l, t); l = pa_strlist_prepend(l, t);
pa_property_replace(core, PA_NATIVE_SERVER_PROPERTY_NAME, l); pa_shared_replace(core, PA_NATIVE_SERVER_PROPERTY_NAME, l);
} }
return p; return p;
@ -4155,13 +4155,13 @@ void pa_protocol_native_free(pa_protocol_native *p) {
if (pa_socket_server_get_address(p->server, t, sizeof(t))) { if (pa_socket_server_get_address(p->server, t, sizeof(t))) {
pa_strlist *l; pa_strlist *l;
l = pa_property_get(p->core, PA_NATIVE_SERVER_PROPERTY_NAME); l = pa_shared_get(p->core, PA_NATIVE_SERVER_PROPERTY_NAME);
l = pa_strlist_remove(l, t); l = pa_strlist_remove(l, t);
if (l) if (l)
pa_property_replace(p->core, PA_NATIVE_SERVER_PROPERTY_NAME, l); pa_shared_replace(p->core, PA_NATIVE_SERVER_PROPERTY_NAME, l);
else else
pa_property_remove(p->core, PA_NATIVE_SERVER_PROPERTY_NAME); pa_shared_remove(p->core, PA_NATIVE_SERVER_PROPERTY_NAME);
} }
pa_socket_server_unref(p->server); pa_socket_server_unref(p->server);

View file

@ -192,7 +192,7 @@ static pa_x11_wrapper* x11_wrapper_new(pa_core *c, const char *name, const char
XAddConnectionWatch(d, x11_watch, (XPointer) w); XAddConnectionWatch(d, x11_watch, (XPointer) w);
pa_assert_se(pa_property_set(c, w->property_name, w) >= 0); pa_assert_se(pa_shared_set(c, w->property_name, w) >= 0);
return w; return w;
} }
@ -200,7 +200,7 @@ static pa_x11_wrapper* x11_wrapper_new(pa_core *c, const char *name, const char
static void x11_wrapper_free(pa_x11_wrapper*w) { static void x11_wrapper_free(pa_x11_wrapper*w) {
pa_assert(w); pa_assert(w);
pa_assert_se(pa_property_remove(w->core, w->property_name) >= 0); pa_assert_se(pa_shared_remove(w->core, w->property_name) >= 0);
pa_assert(!w->clients); pa_assert(!w->clients);
@ -224,7 +224,7 @@ pa_x11_wrapper* pa_x11_wrapper_get(pa_core *c, const char *name) {
pa_core_assert_ref(c); pa_core_assert_ref(c);
pa_snprintf(t, sizeof(t), "x11-wrapper%s%s", name ? "-" : "", name ? name : ""); pa_snprintf(t, sizeof(t), "x11-wrapper%s%s", name ? "-" : "", name ? name : "");
if ((w = pa_property_get(c, t))) if ((w = pa_shared_get(c, t)))
return pa_x11_wrapper_ref(w); return pa_x11_wrapper_ref(w);
return x11_wrapper_new(c, name, t); return x11_wrapper_new(c, name, t);