more modernizations, s/assert/pa_assert/g

git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1806 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2007-09-11 14:58:25 +00:00
parent 27f13b3853
commit 9c523e0607
9 changed files with 387 additions and 189 deletions

View file

@ -25,44 +25,53 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <string.h> #include <string.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/props.h> #include <pulsecore/props.h>
#include <pulsecore/macro.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/refcnt.h>
#include "authkey-prop.h" #include "authkey-prop.h"
struct authkey_data { struct authkey_data {
PA_REFCNT_DECLARE;
int ref; int ref;
size_t length; size_t length;
}; };
int pa_authkey_prop_get(pa_core *c, const char *name, void *data, size_t len) { int pa_authkey_prop_get(pa_core *c, const char *name, void *data, size_t len) {
struct authkey_data *a; struct authkey_data *a;
assert(c && name && data && len > 0);
pa_assert(c);
pa_assert(name);
pa_assert(data);
pa_assert(len > 0);
if (!(a = pa_property_get(c, name))) if (!(a = pa_property_get(c, name)))
return -1; return -1;
assert(a->length == len); pa_assert(a->length == len);
memcpy(data, a+1, len); memcpy(data, (uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), len);
return 0; return 0;
} }
int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t len) { int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t len) {
struct authkey_data *a; struct authkey_data *a;
assert(c && name);
pa_assert(c);
pa_assert(name);
if (pa_property_get(c, name)) if (pa_property_get(c, name))
return -1; return -1;
a = pa_xmalloc(sizeof(struct authkey_data) + len); a = pa_xmalloc(PA_ALIGN(sizeof(struct authkey_data)) + len);
a->ref = 1; PA_REFCNT_INIT(a);
a->length = len; a->length = len;
memcpy(a+1, data, len); memcpy((uint8_t*) a + PA_ALIGN(sizeof(struct authkey_data)), data, len);
pa_property_set(c, name, a); pa_property_set(c, name, a);
@ -71,22 +80,27 @@ int pa_authkey_prop_put(pa_core *c, const char *name, const void *data, size_t l
void pa_authkey_prop_ref(pa_core *c, const char *name) { void pa_authkey_prop_ref(pa_core *c, const char *name) {
struct authkey_data *a; struct authkey_data *a;
assert(c && name);
pa_assert(c);
pa_assert(name);
a = pa_property_get(c, name); a = pa_property_get(c, name);
assert(a && a->ref >= 1); pa_assert(a);
pa_assert(PA_REFCNT_VALUE(a) >= 1);
a->ref++; PA_REFCNT_INC(a);
} }
void pa_authkey_prop_unref(pa_core *c, const char *name) { void pa_authkey_prop_unref(pa_core *c, const char *name) {
struct authkey_data *a; struct authkey_data *a;
assert(c && name);
pa_assert(c);
pa_assert(name);
a = pa_property_get(c, name); a = pa_property_get(c, name);
assert(a && a->ref >= 1); pa_assert(a);
pa_assert(PA_REFCNT_VALUE(a) >= 1);
if (!(--a->ref)) { if (PA_REFCNT_DEC(a) <= 0) {
pa_property_remove(c, name); pa_property_remove(c, name);
pa_xfree(a); pa_xfree(a);
} }

View file

@ -26,7 +26,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -36,13 +35,14 @@
#include <pulsecore/memchunk.h> #include <pulsecore/memchunk.h>
#include <pulsecore/sound-file.h> #include <pulsecore/sound-file.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-scache.h> #include <pulsecore/core-scache.h>
#include <pulsecore/core-subscribe.h> #include <pulsecore/core-subscribe.h>
#include "autoload.h" #include "autoload.h"
static void entry_free(pa_autoload_entry *e) { static void entry_free(pa_autoload_entry *e) {
assert(e); pa_assert(e);
pa_subscription_post(e->core, PA_SUBSCRIPTION_EVENT_AUTOLOAD|PA_SUBSCRIPTION_EVENT_REMOVE, PA_INVALID_INDEX); pa_subscription_post(e->core, PA_SUBSCRIPTION_EVENT_AUTOLOAD|PA_SUBSCRIPTION_EVENT_REMOVE, PA_INVALID_INDEX);
pa_xfree(e->name); pa_xfree(e->name);
pa_xfree(e->module); pa_xfree(e->module);
@ -51,7 +51,8 @@ static void entry_free(pa_autoload_entry *e) {
} }
static void entry_remove_and_free(pa_autoload_entry *e) { static void entry_remove_and_free(pa_autoload_entry *e) {
assert(e && e->core); pa_assert(e);
pa_assert(e->core);
pa_idxset_remove_by_data(e->core->autoload_idxset, e, NULL); pa_idxset_remove_by_data(e->core->autoload_idxset, e, NULL);
pa_hashmap_remove(e->core->autoload_hashmap, e->name); pa_hashmap_remove(e->core->autoload_hashmap, e->name);
@ -60,12 +61,14 @@ static void entry_remove_and_free(pa_autoload_entry *e) {
static pa_autoload_entry* entry_new(pa_core *c, const char *name) { static pa_autoload_entry* entry_new(pa_core *c, const char *name) {
pa_autoload_entry *e = NULL; pa_autoload_entry *e = NULL;
assert(c && name);
pa_core_assert_ref(c);
pa_assert(name);
if (c->autoload_hashmap && (e = pa_hashmap_get(c->autoload_hashmap, name))) if (c->autoload_hashmap && (e = pa_hashmap_get(c->autoload_hashmap, name)))
return NULL; return NULL;
e = pa_xmalloc(sizeof(pa_autoload_entry)); e = pa_xnew(pa_autoload_entry, 1);
e->core = c; e->core = c;
e->name = pa_xstrdup(name); e->name = pa_xstrdup(name);
e->module = e->argument = NULL; e->module = e->argument = NULL;
@ -73,7 +76,7 @@ static pa_autoload_entry* entry_new(pa_core *c, const char *name) {
if (!c->autoload_hashmap) if (!c->autoload_hashmap)
c->autoload_hashmap = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); c->autoload_hashmap = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
assert(c->autoload_hashmap); pa_assert(c->autoload_hashmap);
pa_hashmap_put(c->autoload_hashmap, e->name, e); pa_hashmap_put(c->autoload_hashmap, e->name, e);
@ -88,7 +91,11 @@ static pa_autoload_entry* entry_new(pa_core *c, const char *name) {
int pa_autoload_add(pa_core *c, const char*name, pa_namereg_type_t type, const char*module, const char *argument, uint32_t *idx) { int pa_autoload_add(pa_core *c, const char*name, pa_namereg_type_t type, const char*module, const char *argument, uint32_t *idx) {
pa_autoload_entry *e = NULL; pa_autoload_entry *e = NULL;
assert(c && name && module && (type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE));
pa_assert(c);
pa_assert(name);
pa_assert(module);
pa_assert(type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE);
if (!(e = entry_new(c, name))) if (!(e = entry_new(c, name)))
return -1; return -1;
@ -105,7 +112,10 @@ int pa_autoload_add(pa_core *c, const char*name, pa_namereg_type_t type, const c
int pa_autoload_remove_by_name(pa_core *c, const char*name, pa_namereg_type_t type) { int pa_autoload_remove_by_name(pa_core *c, const char*name, pa_namereg_type_t type) {
pa_autoload_entry *e; pa_autoload_entry *e;
assert(c && name && (type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE));
pa_assert(c);
pa_assert(name);
pa_assert(type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE);
if (!c->autoload_hashmap || !(e = pa_hashmap_get(c->autoload_hashmap, name)) || e->type != type) if (!c->autoload_hashmap || !(e = pa_hashmap_get(c->autoload_hashmap, name)) || e->type != type)
return -1; return -1;
@ -116,7 +126,9 @@ int pa_autoload_remove_by_name(pa_core *c, const char*name, pa_namereg_type_t ty
int pa_autoload_remove_by_index(pa_core *c, uint32_t idx) { int pa_autoload_remove_by_index(pa_core *c, uint32_t idx) {
pa_autoload_entry *e; pa_autoload_entry *e;
assert(c && idx != PA_IDXSET_INVALID);
pa_assert(c);
pa_assert(idx != PA_IDXSET_INVALID);
if (!c->autoload_idxset || !(e = pa_idxset_get_by_index(c->autoload_idxset, idx))) if (!c->autoload_idxset || !(e = pa_idxset_get_by_index(c->autoload_idxset, idx)))
return -1; return -1;
@ -128,7 +140,9 @@ int pa_autoload_remove_by_index(pa_core *c, uint32_t idx) {
void pa_autoload_request(pa_core *c, const char *name, pa_namereg_type_t type) { void pa_autoload_request(pa_core *c, const char *name, pa_namereg_type_t type) {
pa_autoload_entry *e; pa_autoload_entry *e;
pa_module *m; pa_module *m;
assert(c && name);
pa_assert(c);
pa_assert(name);
if (!c->autoload_hashmap || !(e = pa_hashmap_get(c->autoload_hashmap, name)) || (e->type != type)) if (!c->autoload_hashmap || !(e = pa_hashmap_get(c->autoload_hashmap, name)) || (e->type != type))
return; return;
@ -153,6 +167,7 @@ static void free_func(void *p, PA_GCC_UNUSED void *userdata) {
} }
void pa_autoload_free(pa_core *c) { void pa_autoload_free(pa_core *c) {
if (c->autoload_hashmap) { if (c->autoload_hashmap) {
pa_hashmap_free(c->autoload_hashmap, free_func, NULL); pa_hashmap_free(c->autoload_hashmap, free_func, NULL);
c->autoload_hashmap = NULL; c->autoload_hashmap = NULL;
@ -166,7 +181,9 @@ void pa_autoload_free(pa_core *c) {
const pa_autoload_entry* pa_autoload_get_by_name(pa_core *c, const char*name, pa_namereg_type_t type) { const pa_autoload_entry* pa_autoload_get_by_name(pa_core *c, const char*name, pa_namereg_type_t type) {
pa_autoload_entry *e; pa_autoload_entry *e;
assert(c && name);
pa_core_assert_ref(c);
pa_assert(name);
if (!c->autoload_hashmap || !(e = pa_hashmap_get(c->autoload_hashmap, name)) || e->type != type) if (!c->autoload_hashmap || !(e = pa_hashmap_get(c->autoload_hashmap, name)) || e->type != type)
return NULL; return NULL;
@ -176,7 +193,9 @@ const pa_autoload_entry* pa_autoload_get_by_name(pa_core *c, const char*name, pa
const pa_autoload_entry* pa_autoload_get_by_index(pa_core *c, uint32_t idx) { const pa_autoload_entry* pa_autoload_get_by_index(pa_core *c, uint32_t idx) {
pa_autoload_entry *e; pa_autoload_entry *e;
assert(c && idx != PA_IDXSET_INVALID);
pa_core_assert_ref(c);
pa_assert(idx != PA_IDXSET_INVALID);
if (!c->autoload_idxset || !(e = pa_idxset_get_by_index(c->autoload_idxset, idx))) if (!c->autoload_idxset || !(e = pa_idxset_get_by_index(c->autoload_idxset, idx)))
return NULL; return NULL;

View file

@ -21,11 +21,14 @@
USA. USA.
***/ ***/
#include <assert.h> #ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "avahi-wrap.h" #include "avahi-wrap.h"
@ -61,9 +64,9 @@ static pa_io_event_flags_t translate_io_flags(AvahiWatchEvent e) {
static void watch_callback(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) { static void watch_callback(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) {
AvahiWatch *w = userdata; AvahiWatch *w = userdata;
assert(a); pa_assert(a);
assert(e); pa_assert(e);
assert(w); pa_assert(w);
w->current_event = translate_io_flags_back(events); w->current_event = translate_io_flags_back(events);
w->callback(w, fd, w->current_event, w->userdata); w->callback(w, fd, w->current_event, w->userdata);
@ -74,12 +77,10 @@ static AvahiWatch* watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent event
pa_avahi_poll *p; pa_avahi_poll *p;
AvahiWatch *w; AvahiWatch *w;
assert(api); pa_assert(api);
assert(fd >= 0); pa_assert(fd >= 0);
assert(callback); pa_assert(callback);
pa_assert_se(p = api->userdata);
p = api->userdata;
assert(p);
w = pa_xnew(AvahiWatch, 1); w = pa_xnew(AvahiWatch, 1);
w->avahi_poll = p; w->avahi_poll = p;
@ -92,19 +93,19 @@ static AvahiWatch* watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent event
} }
static void watch_update(AvahiWatch *w, AvahiWatchEvent event) { static void watch_update(AvahiWatch *w, AvahiWatchEvent event) {
assert(w); pa_assert(w);
w->avahi_poll->mainloop->io_enable(w->io_event, translate_io_flags(event)); w->avahi_poll->mainloop->io_enable(w->io_event, translate_io_flags(event));
} }
static AvahiWatchEvent watch_get_events(AvahiWatch *w) { static AvahiWatchEvent watch_get_events(AvahiWatch *w) {
assert(w); pa_assert(w);
return w->current_event; return w->current_event;
} }
static void watch_free(AvahiWatch *w) { static void watch_free(AvahiWatch *w) {
assert(w); pa_assert(w);
w->avahi_poll->mainloop->io_free(w->io_event); w->avahi_poll->mainloop->io_free(w->io_event);
pa_xfree(w); pa_xfree(w);
@ -120,9 +121,9 @@ struct AvahiTimeout {
static void timeout_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) { static void timeout_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) {
AvahiTimeout *t = userdata; AvahiTimeout *t = userdata;
assert(a); pa_assert(a);
assert(e); pa_assert(e);
assert(t); pa_assert(t);
t->callback(t, t->userdata); t->callback(t, t->userdata);
} }
@ -131,11 +132,9 @@ static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv,
pa_avahi_poll *p; pa_avahi_poll *p;
AvahiTimeout *t; AvahiTimeout *t;
assert(api); pa_assert(api);
assert(callback); pa_assert(callback);
pa_assert_se(p = api->userdata);
p = api->userdata;
assert(p);
t = pa_xnew(AvahiTimeout, 1); t = pa_xnew(AvahiTimeout, 1);
t->avahi_poll = p; t->avahi_poll = p;
@ -148,7 +147,7 @@ static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv,
} }
static void timeout_update(AvahiTimeout *t, const struct timeval *tv) { static void timeout_update(AvahiTimeout *t, const struct timeval *tv) {
assert(t); pa_assert(t);
if (t->time_event && tv) if (t->time_event && tv)
t->avahi_poll->mainloop->time_restart(t->time_event, tv); t->avahi_poll->mainloop->time_restart(t->time_event, tv);
@ -161,7 +160,7 @@ static void timeout_update(AvahiTimeout *t, const struct timeval *tv) {
} }
static void timeout_free(AvahiTimeout *t) { static void timeout_free(AvahiTimeout *t) {
assert(t); pa_assert(t);
if (t->time_event) if (t->time_event)
t->avahi_poll->mainloop->time_free(t->time_event); t->avahi_poll->mainloop->time_free(t->time_event);
@ -171,7 +170,7 @@ static void timeout_free(AvahiTimeout *t) {
AvahiPoll* pa_avahi_poll_new(pa_mainloop_api *m) { AvahiPoll* pa_avahi_poll_new(pa_mainloop_api *m) {
pa_avahi_poll *p; pa_avahi_poll *p;
assert(m); pa_assert(m);
p = pa_xnew(pa_avahi_poll, 1); p = pa_xnew(pa_avahi_poll, 1);
@ -190,9 +189,8 @@ AvahiPoll* pa_avahi_poll_new(pa_mainloop_api *m) {
void pa_avahi_poll_free(AvahiPoll *api) { void pa_avahi_poll_free(AvahiPoll *api) {
pa_avahi_poll *p; pa_avahi_poll *p;
assert(api); pa_assert(api);
p = api->userdata; pa_assert_se(p = api->userdata);
assert(p);
pa_xfree(p); pa_xfree(p);
} }

View file

@ -182,15 +182,23 @@ static uint32_t parse_index(const char *n) {
return idx; return idx;
} }
static int pa_cli_command_exit(pa_core *c, pa_tokenizer *t, PA_GCC_UNUSED pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_exit(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
assert(c && c->mainloop && t); pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
c->mainloop->quit(c->mainloop, 0); c->mainloop->quit(c->mainloop, 0);
return 0; return 0;
} }
static int pa_cli_command_help(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_help(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const struct command*command; const struct command*command;
assert(c && t && buf);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_strbuf_puts(buf, "Available commands:\n"); pa_strbuf_puts(buf, "Available commands:\n");
@ -200,67 +208,91 @@ static int pa_cli_command_help(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_G
return 0; return 0;
} }
static int pa_cli_command_modules(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_modules(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
char *s; char *s;
assert(c && t);
s = pa_module_list_to_string(c); pa_core_assert_ref(c);
assert(s); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_assert_se(s = pa_module_list_to_string(c));
pa_strbuf_puts(buf, s); pa_strbuf_puts(buf, s);
pa_xfree(s); pa_xfree(s);
return 0; return 0;
} }
static int pa_cli_command_clients(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_clients(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
char *s; char *s;
assert(c && t);
s = pa_client_list_to_string(c); pa_core_assert_ref(c);
assert(s); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_assert_se(s = pa_client_list_to_string(c));
pa_strbuf_puts(buf, s); pa_strbuf_puts(buf, s);
pa_xfree(s); pa_xfree(s);
return 0; return 0;
} }
static int pa_cli_command_sinks(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_sinks(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
char *s; char *s;
assert(c && t);
s = pa_sink_list_to_string(c); pa_core_assert_ref(c);
assert(s); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_assert_se(s = pa_sink_list_to_string(c));
pa_strbuf_puts(buf, s); pa_strbuf_puts(buf, s);
pa_xfree(s); pa_xfree(s);
return 0; return 0;
} }
static int pa_cli_command_sources(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_sources(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
char *s; char *s;
assert(c && t);
s = pa_source_list_to_string(c); pa_core_assert_ref(c);
assert(s); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_assert_se(s = pa_source_list_to_string(c));
pa_strbuf_puts(buf, s); pa_strbuf_puts(buf, s);
pa_xfree(s); pa_xfree(s);
return 0; return 0;
} }
static int pa_cli_command_sink_inputs(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_sink_inputs(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
char *s; char *s;
assert(c && t);
s = pa_sink_input_list_to_string(c); pa_core_assert_ref(c);
assert(s); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_assert_se(s = pa_sink_input_list_to_string(c));
pa_strbuf_puts(buf, s); pa_strbuf_puts(buf, s);
pa_xfree(s); pa_xfree(s);
return 0; return 0;
} }
static int pa_cli_command_source_outputs(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_source_outputs(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
char *s; char *s;
assert(c && t);
s = pa_source_output_list_to_string(c); pa_core_assert_ref(c);
assert(s); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_assert_se(s = pa_source_output_list_to_string(c));
pa_strbuf_puts(buf, s); pa_strbuf_puts(buf, s);
pa_xfree(s); pa_xfree(s);
return 0; return 0;
} }
static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
char s[256]; char s[256];
const pa_mempool_stat *stat; const pa_mempool_stat *stat;
unsigned k; unsigned k;
@ -275,8 +307,10 @@ static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_G
[PA_MEMBLOCK_IMPORTED] = "IMPORTED", [PA_MEMBLOCK_IMPORTED] = "IMPORTED",
}; };
assert(c); pa_core_assert_ref(c);
assert(t); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
stat = pa_mempool_get_stat(c->mempool); stat = pa_mempool_get_stat(c->mempool);
@ -320,7 +354,11 @@ static int pa_cli_command_stat(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_G
} }
static int pa_cli_command_info(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) { static int pa_cli_command_info(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
assert(c && t); pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_cli_command_stat(c, t, buf, fail); pa_cli_command_stat(c, t, buf, fail);
pa_cli_command_modules(c, t, buf, fail); pa_cli_command_modules(c, t, buf, fail);
pa_cli_command_sinks(c, t, buf, fail); pa_cli_command_sinks(c, t, buf, fail);
@ -333,10 +371,14 @@ static int pa_cli_command_info(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int
return 0; return 0;
} }
static int pa_cli_command_load(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_load(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
pa_module *m; pa_module *m;
const char *name; const char *name;
assert(c && t);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(name = pa_tokenizer_get(t, 1))) { if (!(name = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify the module name and optionally arguments.\n"); pa_strbuf_puts(buf, "You need to specify the module name and optionally arguments.\n");
@ -351,12 +393,16 @@ static int pa_cli_command_load(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_G
return 0; return 0;
} }
static int pa_cli_command_unload(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_unload(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
pa_module *m; pa_module *m;
uint32_t idx; uint32_t idx;
const char *i; const char *i;
char *e; char *e;
assert(c && t);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(i = pa_tokenizer_get(t, 1))) { if (!(i = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify the module index.\n"); pa_strbuf_puts(buf, "You need to specify the module index.\n");
@ -373,12 +419,17 @@ static int pa_cli_command_unload(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA
return 0; return 0;
} }
static int pa_cli_command_sink_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_sink_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n, *v; const char *n, *v;
pa_sink *sink; pa_sink *sink;
uint32_t volume; uint32_t volume;
pa_cvolume cvolume; pa_cvolume cvolume;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n"); pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
return -1; return -1;
@ -404,13 +455,18 @@ static int pa_cli_command_sink_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
return 0; return 0;
} }
static int pa_cli_command_sink_input_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_sink_input_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n, *v; const char *n, *v;
pa_sink_input *si; pa_sink_input *si;
pa_volume_t volume; pa_volume_t volume;
pa_cvolume cvolume; pa_cvolume cvolume;
uint32_t idx; uint32_t idx;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n"); pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n");
return -1; return -1;
@ -441,12 +497,17 @@ static int pa_cli_command_sink_input_volume(pa_core *c, pa_tokenizer *t, pa_strb
return 0; return 0;
} }
static int pa_cli_command_source_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_source_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n, *v; const char *n, *v;
pa_source *source; pa_source *source;
uint32_t volume; uint32_t volume;
pa_cvolume cvolume; pa_cvolume cvolume;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n"); pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n");
return -1; return -1;
@ -472,11 +533,16 @@ static int pa_cli_command_source_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *
return 0; return 0;
} }
static int pa_cli_command_sink_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_sink_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n, *m; const char *n, *m;
pa_sink *sink; pa_sink *sink;
int mute; int mute;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n"); pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
return -1; return -1;
@ -501,11 +567,16 @@ static int pa_cli_command_sink_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf,
return 0; return 0;
} }
static int pa_cli_command_source_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_source_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n, *m; const char *n, *m;
pa_source *source; pa_source *source;
int mute; int mute;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n"); pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n");
return -1; return -1;
@ -530,12 +601,17 @@ static int pa_cli_command_source_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
return 0; return 0;
} }
static int pa_cli_command_sink_input_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_sink_input_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n, *v; const char *n, *v;
pa_sink_input *si; pa_sink_input *si;
uint32_t idx; uint32_t idx;
int mute; int mute;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n"); pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n");
return -1; return -1;
@ -565,9 +641,13 @@ static int pa_cli_command_sink_input_mute(pa_core *c, pa_tokenizer *t, pa_strbuf
return 0; return 0;
} }
static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n; const char *n;
assert(c && t);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n"); pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
@ -578,9 +658,13 @@ static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *b
return 0; return 0;
} }
static int pa_cli_command_source_default(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_source_default(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n; const char *n;
assert(c && t);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n"); pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n");
@ -591,11 +675,15 @@ static int pa_cli_command_source_default(pa_core *c, pa_tokenizer *t, pa_strbuf
return 0; return 0;
} }
static int pa_cli_command_kill_client(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_kill_client(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n; const char *n;
pa_client *client; pa_client *client;
uint32_t idx; uint32_t idx;
assert(c && t);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a client by its index.\n"); pa_strbuf_puts(buf, "You need to specify a client by its index.\n");
@ -616,11 +704,15 @@ static int pa_cli_command_kill_client(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
return 0; return 0;
} }
static int pa_cli_command_kill_sink_input(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_kill_sink_input(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n; const char *n;
pa_sink_input *sink_input; pa_sink_input *sink_input;
uint32_t idx; uint32_t idx;
assert(c && t);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n"); pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n");
@ -641,11 +733,15 @@ static int pa_cli_command_kill_sink_input(pa_core *c, pa_tokenizer *t, pa_strbuf
return 0; return 0;
} }
static int pa_cli_command_kill_source_output(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_kill_source_output(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n; const char *n;
pa_source_output *source_output; pa_source_output *source_output;
uint32_t idx; uint32_t idx;
assert(c && t);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a source output by its index.\n"); pa_strbuf_puts(buf, "You need to specify a source output by its index.\n");
@ -666,20 +762,29 @@ static int pa_cli_command_kill_source_output(pa_core *c, pa_tokenizer *t, pa_str
return 0; return 0;
} }
static int pa_cli_command_scache_list(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_scache_list(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
char *s; char *s;
assert(c && t);
s = pa_scache_list_to_string(c); pa_core_assert_ref(c);
assert(s); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_assert_se(s = pa_scache_list_to_string(c));
pa_strbuf_puts(buf, s); pa_strbuf_puts(buf, s);
pa_xfree(s); pa_xfree(s);
return 0; return 0;
} }
static int pa_cli_command_scache_play(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) { static int pa_cli_command_scache_play(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n, *sink_name; const char *n, *sink_name;
pa_sink *sink; pa_sink *sink;
assert(c && t && buf && fail);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1)) || !(sink_name = pa_tokenizer_get(t, 2))) { if (!(n = pa_tokenizer_get(t, 1)) || !(sink_name = pa_tokenizer_get(t, 2))) {
pa_strbuf_puts(buf, "You need to specify a sample name and a sink name.\n"); pa_strbuf_puts(buf, "You need to specify a sample name and a sink name.\n");
@ -701,7 +806,11 @@ static int pa_cli_command_scache_play(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
static int pa_cli_command_scache_remove(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) { static int pa_cli_command_scache_remove(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *n; const char *n;
assert(c && t && buf && fail);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a sample name.\n"); pa_strbuf_puts(buf, "You need to specify a sample name.\n");
@ -719,7 +828,11 @@ static int pa_cli_command_scache_remove(pa_core *c, pa_tokenizer *t, pa_strbuf *
static int pa_cli_command_scache_load(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) { static int pa_cli_command_scache_load(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *fname, *n; const char *fname, *n;
int r; int r;
assert(c && t && buf && fail);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(fname = pa_tokenizer_get(t, 2)) || !(n = pa_tokenizer_get(t, 1))) { if (!(fname = pa_tokenizer_get(t, 2)) || !(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a file name and a sample name.\n"); pa_strbuf_puts(buf, "You need to specify a file name and a sample name.\n");
@ -739,7 +852,11 @@ static int pa_cli_command_scache_load(pa_core *c, pa_tokenizer *t, pa_strbuf *bu
static int pa_cli_command_scache_load_dir(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) { static int pa_cli_command_scache_load_dir(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *pname; const char *pname;
assert(c && t && buf && fail);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(pname = pa_tokenizer_get(t, 1))) { if (!(pname = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a path name.\n"); pa_strbuf_puts(buf, "You need to specify a path name.\n");
@ -757,7 +874,11 @@ static int pa_cli_command_scache_load_dir(pa_core *c, pa_tokenizer *t, pa_strbuf
static int pa_cli_command_play_file(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) { static int pa_cli_command_play_file(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *fname, *sink_name; const char *fname, *sink_name;
pa_sink *sink; pa_sink *sink;
assert(c && t && buf && fail);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(fname = pa_tokenizer_get(t, 1)) || !(sink_name = pa_tokenizer_get(t, 2))) { if (!(fname = pa_tokenizer_get(t, 1)) || !(sink_name = pa_tokenizer_get(t, 2))) {
pa_strbuf_puts(buf, "You need to specify a file name and a sink name.\n"); pa_strbuf_puts(buf, "You need to specify a file name and a sink name.\n");
@ -775,7 +896,11 @@ static int pa_cli_command_play_file(pa_core *c, pa_tokenizer *t, pa_strbuf *buf,
static int pa_cli_command_autoload_add(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) { static int pa_cli_command_autoload_add(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *a, *b; const char *a, *b;
assert(c && t && buf && fail);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(a = pa_tokenizer_get(t, 1)) || !(b = pa_tokenizer_get(t, 2))) { if (!(a = pa_tokenizer_get(t, 1)) || !(b = pa_tokenizer_get(t, 2))) {
pa_strbuf_puts(buf, "You need to specify a device name, a filename or a module name and optionally module arguments\n"); pa_strbuf_puts(buf, "You need to specify a device name, a filename or a module name and optionally module arguments\n");
@ -789,7 +914,11 @@ static int pa_cli_command_autoload_add(pa_core *c, pa_tokenizer *t, pa_strbuf *b
static int pa_cli_command_autoload_remove(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) { static int pa_cli_command_autoload_remove(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
const char *name; const char *name;
assert(c && t && buf && fail);
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(name = pa_tokenizer_get(t, 1))) { if (!(name = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a device name\n"); pa_strbuf_puts(buf, "You need to specify a device name\n");
@ -804,25 +933,36 @@ static int pa_cli_command_autoload_remove(pa_core *c, pa_tokenizer *t, pa_strbuf
return 0; return 0;
} }
static int pa_cli_command_autoload_list(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_autoload_list(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
char *s; char *s;
assert(c && t);
s = pa_autoload_list_to_string(c); pa_core_assert_ref(c);
assert(s); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_assert_se(s = pa_autoload_list_to_string(c));
pa_strbuf_puts(buf, s); pa_strbuf_puts(buf, s);
pa_xfree(s); pa_xfree(s);
return 0; return 0;
} }
static int pa_cli_command_list_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_list_props(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
assert(c && t); pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_property_dump(c, buf); pa_property_dump(c, buf);
return 0; return 0;
} }
static int pa_cli_command_vacuum(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) { static int pa_cli_command_vacuum(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
assert(c); pa_core_assert_ref(c);
assert(t); pa_assert(t);
pa_assert(buf);
pa_assert(fail);
pa_mempool_vacuum(c->mempool); pa_mempool_vacuum(c->mempool);
@ -835,6 +975,11 @@ static int pa_cli_command_move_sink_input(pa_core *c, pa_tokenizer *t, pa_strbuf
pa_sink *sink; pa_sink *sink;
uint32_t idx; uint32_t idx;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n"); pa_strbuf_puts(buf, "You need to specify a sink input by its index.\n");
return -1; return -1;
@ -873,6 +1018,11 @@ static int pa_cli_command_move_source_output(pa_core *c, pa_tokenizer *t, pa_str
pa_source *source; pa_source *source;
uint32_t idx; uint32_t idx;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a source output by its index.\n"); pa_strbuf_puts(buf, "You need to specify a source output by its index.\n");
return -1; return -1;
@ -910,6 +1060,11 @@ static int pa_cli_command_suspend_sink(pa_core *c, pa_tokenizer *t, pa_strbuf *b
pa_sink *sink; pa_sink *sink;
int suspend; int suspend;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n"); pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
return -1; return -1;
@ -939,6 +1094,11 @@ static int pa_cli_command_suspend_source(pa_core *c, pa_tokenizer *t, pa_strbuf
pa_source *source; pa_source *source;
int suspend; int suspend;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(n = pa_tokenizer_get(t, 1))) { if (!(n = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n"); pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n");
return -1; return -1;
@ -968,6 +1128,11 @@ static int pa_cli_command_suspend(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, i
int suspend; int suspend;
int ret; int ret;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
if (!(m = pa_tokenizer_get(t, 1))) { if (!(m = pa_tokenizer_get(t, 1))) {
pa_strbuf_puts(buf, "You need to specify a suspend switch setting (0/1).\n"); pa_strbuf_puts(buf, "You need to specify a suspend switch setting (0/1).\n");
return -1; return -1;
@ -988,7 +1153,7 @@ static int pa_cli_command_suspend(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, i
return 0; return 0;
} }
static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) { static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail) {
pa_module *m; pa_module *m;
pa_sink *sink; pa_sink *sink;
pa_source *source; pa_source *source;
@ -1000,7 +1165,10 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_G
void *i; void *i;
pa_autoload_entry *a; pa_autoload_entry *a;
assert(c && t); pa_core_assert_ref(c);
pa_assert(t);
pa_assert(buf);
pa_assert(fail);
time(&now); time(&now);
@ -1097,6 +1265,10 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_G
int pa_cli_command_execute_line_stateful(pa_core *c, const char *s, pa_strbuf *buf, int *fail, int *ifstate) { int pa_cli_command_execute_line_stateful(pa_core *c, const char *s, pa_strbuf *buf, int *fail, int *ifstate) {
const char *cs; const char *cs;
pa_assert(c);
pa_assert(s);
pa_assert(buf);
cs = s+strspn(s, whitespace); cs = s+strspn(s, whitespace);
if (*cs == '#' || !*cs) if (*cs == '#' || !*cs)
@ -1160,14 +1332,13 @@ int pa_cli_command_execute_line_stateful(pa_core *c, const char *s, pa_strbuf *b
if (ifstate && *ifstate == IFSTATE_FALSE) if (ifstate && *ifstate == IFSTATE_FALSE)
return 0; return 0;
l = strcspn(cs, whitespace); l = strcspn(cs, whitespace);
for (command = commands; command->name; command++) for (command = commands; command->name; command++)
if (strlen(command->name) == l && !strncmp(cs, command->name, l)) { if (strlen(command->name) == l && !strncmp(cs, command->name, l)) {
int ret; int ret;
pa_tokenizer *t = pa_tokenizer_new(cs, command->args); pa_tokenizer *t = pa_tokenizer_new(cs, command->args);
assert(t); pa_assert(t);
ret = command->proc(c, t, buf, fail); ret = command->proc(c, t, buf, fail);
pa_tokenizer_free(t); pa_tokenizer_free(t);
unknown = 0; unknown = 0;
@ -1198,9 +1369,9 @@ int pa_cli_command_execute_file(pa_core *c, const char *fn, pa_strbuf *buf, int
int ifstate = IFSTATE_NONE; int ifstate = IFSTATE_NONE;
int ret = -1; int ret = -1;
assert(c); pa_assert(c);
assert(fn); pa_assert(fn);
assert(buf); pa_assert(buf);
if (!(f = fopen(fn, "r"))) { if (!(f = fopen(fn, "r"))) {
pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, pa_cstrerror(errno)); pa_strbuf_printf(buf, "open('%s') failed: %s\n", fn, pa_cstrerror(errno));
@ -1230,9 +1401,9 @@ int pa_cli_command_execute(pa_core *c, const char *s, pa_strbuf *buf, int *fail)
const char *p; const char *p;
int ifstate = IFSTATE_NONE; int ifstate = IFSTATE_NONE;
assert(c); pa_assert(c);
assert(s); pa_assert(s);
assert(buf); pa_assert(buf);
p = s; p = s;
while (*p) { while (*p) {

View file

@ -25,7 +25,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <string.h> #include <string.h>
#include <pulse/volume.h> #include <pulse/volume.h>
@ -41,6 +40,7 @@
#include <pulsecore/sample-util.h> #include <pulsecore/sample-util.h>
#include <pulsecore/core-scache.h> #include <pulsecore/core-scache.h>
#include <pulsecore/autoload.h> #include <pulsecore/autoload.h>
#include <pulsecore/macro.h>
#include "cli-text.h" #include "cli-text.h"
@ -48,10 +48,9 @@ char *pa_module_list_to_string(pa_core *c) {
pa_strbuf *s; pa_strbuf *s;
pa_module *m; pa_module *m;
uint32_t idx = PA_IDXSET_INVALID; uint32_t idx = PA_IDXSET_INVALID;
assert(c); pa_assert(c);
s = pa_strbuf_new(); s = pa_strbuf_new();
assert(s);
pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules)); pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));
@ -72,10 +71,9 @@ char *pa_client_list_to_string(pa_core *c) {
pa_strbuf *s; pa_strbuf *s;
pa_client *client; pa_client *client;
uint32_t idx = PA_IDXSET_INVALID; uint32_t idx = PA_IDXSET_INVALID;
assert(c); pa_assert(c);
s = pa_strbuf_new(); s = pa_strbuf_new();
assert(s);
pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients)); pa_strbuf_printf(s, "%u client(s) logged in.\n", pa_idxset_size(c->clients));
@ -99,10 +97,9 @@ char *pa_sink_list_to_string(pa_core *c) {
[PA_SINK_IDLE] = "IDLE", [PA_SINK_IDLE] = "IDLE",
[PA_SINK_UNLINKED] = "UNLINKED" [PA_SINK_UNLINKED] = "UNLINKED"
}; };
assert(c); pa_assert(c);
s = pa_strbuf_new(); s = pa_strbuf_new();
assert(s);
pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks)); pa_strbuf_printf(s, "%u sink(s) available.\n", pa_idxset_size(c->sinks));
@ -159,10 +156,9 @@ char *pa_source_list_to_string(pa_core *c) {
[PA_SOURCE_IDLE] = "IDLE", [PA_SOURCE_IDLE] = "IDLE",
[PA_SOURCE_UNLINKED] = "UNLINKED" [PA_SOURCE_UNLINKED] = "UNLINKED"
}; };
assert(c); pa_assert(c);
s = pa_strbuf_new(); s = pa_strbuf_new();
assert(s);
pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources)); pa_strbuf_printf(s, "%u source(s) available.\n", pa_idxset_size(c->sources));
@ -220,17 +216,16 @@ char *pa_source_output_list_to_string(pa_core *c) {
[PA_SOURCE_OUTPUT_CORKED] = "CORKED", [PA_SOURCE_OUTPUT_CORKED] = "CORKED",
[PA_SOURCE_OUTPUT_UNLINKED] = "UNLINKED" [PA_SOURCE_OUTPUT_UNLINKED] = "UNLINKED"
}; };
assert(c); pa_assert(c);
s = pa_strbuf_new(); s = pa_strbuf_new();
assert(s);
pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs)); pa_strbuf_printf(s, "%u source outputs(s) available.\n", pa_idxset_size(c->source_outputs));
for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) { for (o = pa_idxset_first(c->source_outputs, &idx); o; o = pa_idxset_next(c->source_outputs, &idx)) {
char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
assert(o->source); pa_assert(o->source);
pa_strbuf_printf( pa_strbuf_printf(
s, s,
@ -275,16 +270,15 @@ char *pa_sink_input_list_to_string(pa_core *c) {
[PA_SINK_INPUT_UNLINKED] = "UNLINKED" [PA_SINK_INPUT_UNLINKED] = "UNLINKED"
}; };
assert(c); pa_assert(c);
s = pa_strbuf_new(); s = pa_strbuf_new();
assert(s);
pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs)); pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) { for (i = pa_idxset_first(c->sink_inputs, &idx); i; i = pa_idxset_next(c->sink_inputs, &idx)) {
char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
assert(i->sink); pa_assert(i->sink);
pa_strbuf_printf( pa_strbuf_printf(
s, s,
@ -325,10 +319,9 @@ char *pa_sink_input_list_to_string(pa_core *c) {
char *pa_scache_list_to_string(pa_core *c) { char *pa_scache_list_to_string(pa_core *c) {
pa_strbuf *s; pa_strbuf *s;
assert(c); pa_assert(c);
s = pa_strbuf_new(); s = pa_strbuf_new();
assert(s);
pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0); pa_strbuf_printf(s, "%u cache entries available.\n", c->scache ? pa_idxset_size(c->scache) : 0);
@ -374,10 +367,9 @@ char *pa_scache_list_to_string(pa_core *c) {
char *pa_autoload_list_to_string(pa_core *c) { char *pa_autoload_list_to_string(pa_core *c) {
pa_strbuf *s; pa_strbuf *s;
assert(c); pa_assert(c);
s = pa_strbuf_new(); s = pa_strbuf_new();
assert(s);
pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0); pa_strbuf_printf(s, "%u autoload entries available.\n", c->autoload_hashmap ? pa_hashmap_size(c->autoload_hashmap) : 0);

View file

@ -45,6 +45,7 @@
#include <pulsecore/cli-text.h> #include <pulsecore/cli-text.h>
#include <pulsecore/cli-command.h> #include <pulsecore/cli-command.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "cli.h" #include "cli.h"
@ -68,19 +69,17 @@ static void client_kill(pa_client *c);
pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) { pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) {
char cname[256]; char cname[256];
pa_cli *c; pa_cli *c;
assert(io); pa_assert(io);
c = pa_xmalloc(sizeof(pa_cli)); c = pa_xnew(pa_cli, 1);
c->core = core; c->core = core;
c->line = pa_ioline_new(io); pa_assert_se(c->line = pa_ioline_new(io));
assert(c->line);
c->userdata = NULL; c->userdata = NULL;
c->eof_callback = NULL; c->eof_callback = NULL;
pa_iochannel_socket_peer_to_string(io, cname, sizeof(cname)); pa_iochannel_socket_peer_to_string(io, cname, sizeof(cname));
c->client = pa_client_new(core, __FILE__, cname); pa_assert_se(c->client = pa_client_new(core, __FILE__, cname));
assert(c->client);
c->client->kill = client_kill; c->client->kill = client_kill;
c->client->userdata = c; c->client->userdata = c;
c->client->owner = m; c->client->owner = m;
@ -94,7 +93,8 @@ pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) {
} }
void pa_cli_free(pa_cli *c) { void pa_cli_free(pa_cli *c) {
assert(c); pa_assert(c);
pa_ioline_close(c->line); pa_ioline_close(c->line);
pa_ioline_unref(c->line); pa_ioline_unref(c->line);
pa_client_free(c->client); pa_client_free(c->client);
@ -103,8 +103,9 @@ void pa_cli_free(pa_cli *c) {
static void client_kill(pa_client *client) { static void client_kill(pa_client *client) {
pa_cli *c; pa_cli *c;
assert(client && client->userdata);
c = client->userdata; pa_assert(client);
pa_assert_se(c = client->userdata);
pa_log_debug("CLI client killed."); pa_log_debug("CLI client killed.");
if (c->defer_kill) if (c->defer_kill)
@ -119,7 +120,9 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
pa_strbuf *buf; pa_strbuf *buf;
pa_cli *c = userdata; pa_cli *c = userdata;
char *p; char *p;
assert(line && c);
pa_assert(line);
pa_assert(c);
if (!s) { if (!s) {
pa_log_debug("CLI got EOF from user."); pa_log_debug("CLI got EOF from user.");
@ -129,8 +132,7 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
return; return;
} }
buf = pa_strbuf_new(); pa_assert_se(buf = pa_strbuf_new());
assert(buf);
c->defer_kill++; c->defer_kill++;
pa_cli_command_execute_line(c->core, s, buf, &c->fail); pa_cli_command_execute_line(c->core, s, buf, &c->fail);
c->defer_kill--; c->defer_kill--;
@ -145,7 +147,8 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
} }
void pa_cli_set_eof_callback(pa_cli *c, void (*cb)(pa_cli*c, void *userdata), void *userdata) { void pa_cli_set_eof_callback(pa_cli *c, void (*cb)(pa_cli*c, void *userdata), void *userdata) {
assert(c); pa_assert(c);
c->eof_callback = cb; c->eof_callback = cb;
c->userdata = userdata; c->userdata = userdata;
} }

View file

@ -27,7 +27,6 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -35,15 +34,16 @@
#include <pulsecore/core-subscribe.h> #include <pulsecore/core-subscribe.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "client.h" #include "client.h"
pa_client *pa_client_new(pa_core *core, const char *driver, const char *name) { pa_client *pa_client_new(pa_core *core, const char *driver, const char *name) {
pa_client *c; pa_client *c;
int r;
assert(core);
c = pa_xmalloc(sizeof(pa_client)); pa_core_assert_ref(core);
c = pa_xnew(pa_client, 1);
c->name = pa_xstrdup(name); c->name = pa_xstrdup(name);
c->driver = pa_xstrdup(driver); c->driver = pa_xstrdup(driver);
c->owner = NULL; c->owner = NULL;
@ -52,10 +52,9 @@ pa_client *pa_client_new(pa_core *core, const char *driver, const char *name) {
c->kill = NULL; c->kill = NULL;
c->userdata = NULL; c->userdata = NULL;
r = pa_idxset_put(core->clients, c, &c->index); pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
assert(c->index != PA_IDXSET_INVALID && r >= 0);
pa_log_info("created %u \"%s\"", c->index, c->name); pa_log_info("Created %u \"%s\"", c->index, c->name);
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index); pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
pa_core_check_quit(core); pa_core_check_quit(core);
@ -64,13 +63,14 @@ pa_client *pa_client_new(pa_core *core, const char *driver, const char *name) {
} }
void pa_client_free(pa_client *c) { void pa_client_free(pa_client *c) {
assert(c && c->core); pa_assert(c);
pa_assert(c->core);
pa_idxset_remove_by_data(c->core->clients, c, NULL); pa_idxset_remove_by_data(c->core->clients, c, NULL);
pa_core_check_quit(c->core); pa_core_check_quit(c->core);
pa_log_info("freed %u \"%s\"", c->index, c->name); pa_log_info("Freed %u \"%s\"", c->index, c->name);
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index); pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
pa_xfree(c->name); pa_xfree(c->name);
pa_xfree(c->driver); pa_xfree(c->driver);
@ -78,7 +78,8 @@ void pa_client_free(pa_client *c) {
} }
void pa_client_kill(pa_client *c) { void pa_client_kill(pa_client *c) {
assert(c); pa_assert(c);
if (!c->kill) { if (!c->kill) {
pa_log_warn("kill() operation not implemented for client %u", c->index); pa_log_warn("kill() operation not implemented for client %u", c->index);
return; return;
@ -88,9 +89,9 @@ void pa_client_kill(pa_client *c) {
} }
void pa_client_set_name(pa_client *c, const char *name) { void pa_client_set_name(pa_client *c, const char *name) {
assert(c); pa_assert(c);
pa_log_info("client %u changed name from \"%s\" to \"%s\"", c->index, c->name, name); pa_log_info("Client %u changed name from \"%s\" to \"%s\"", c->index, c->name, name);
pa_xfree(c->name); pa_xfree(c->name);
c->name = pa_xstrdup(name); c->name = pa_xstrdup(name);

View file

@ -27,7 +27,6 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
@ -160,21 +159,21 @@ static void core_free(pa_object *o) {
pa_assert(c); pa_assert(c);
pa_module_unload_all(c); pa_module_unload_all(c);
assert(!c->modules); pa_assert(!c->modules);
assert(pa_idxset_isempty(c->clients)); pa_assert(pa_idxset_isempty(c->clients));
pa_idxset_free(c->clients, NULL, NULL); pa_idxset_free(c->clients, NULL, NULL);
assert(pa_idxset_isempty(c->sinks)); pa_assert(pa_idxset_isempty(c->sinks));
pa_idxset_free(c->sinks, NULL, NULL); pa_idxset_free(c->sinks, NULL, NULL);
assert(pa_idxset_isempty(c->sources)); pa_assert(pa_idxset_isempty(c->sources));
pa_idxset_free(c->sources, NULL, NULL); pa_idxset_free(c->sources, NULL, NULL);
assert(pa_idxset_isempty(c->source_outputs)); pa_assert(pa_idxset_isempty(c->source_outputs));
pa_idxset_free(c->source_outputs, NULL, NULL); pa_idxset_free(c->source_outputs, NULL, NULL);
assert(pa_idxset_isempty(c->sink_inputs)); pa_assert(pa_idxset_isempty(c->sink_inputs));
pa_idxset_free(c->sink_inputs, NULL, NULL); pa_idxset_free(c->sink_inputs, NULL, NULL);
pa_scache_free(c); pa_scache_free(c);
@ -200,7 +199,7 @@ static void core_free(pa_object *o) {
static void quit_callback(pa_mainloop_api*m, pa_time_event *e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) { static void quit_callback(pa_mainloop_api*m, pa_time_event *e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
pa_core *c = userdata; pa_core *c = userdata;
pa_assert(c->quit_event = e); pa_assert(c->quit_event == e);
m->quit(m, 0); m->quit(m, 0);
} }

View file

@ -50,8 +50,9 @@ struct pa_strbuf {
}; };
pa_strbuf *pa_strbuf_new(void) { pa_strbuf *pa_strbuf_new(void) {
pa_strbuf *sb;
pa_strbuf *sb = pa_xnew(pa_strbuf, 1); sb = pa_xnew(pa_strbuf, 1);
sb->length = 0; sb->length = 0;
sb->head = sb->tail = NULL; sb->head = sb->tail = NULL;