#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
+#include <fcntl.h>
+#include <ctype.h>
#include <pulse/xmalloc.h>
#include <pulse/error.h>
static int pa_cli_command_suspend_sink(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_suspend_source(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_suspend(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
+static int pa_cli_command_log_target(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_log_level(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_log_meta(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_log_time(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_sink_port(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_source_port(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
+static int pa_cli_command_port_offset(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
static int pa_cli_command_dump_volumes(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail);
/* A method table for all available commands */
{ "ls", pa_cli_command_info, NULL, 1 },
{ "list", pa_cli_command_info, NULL, 1 },
{ "load-module", pa_cli_command_load, "Load a module (args: name, arguments)", 3},
- { "unload-module", pa_cli_command_unload, "Unload a module (args: index)", 2},
+ { "unload-module", pa_cli_command_unload, "Unload a module (args: index|name)", 2},
{ "describe-module", pa_cli_command_describe, "Describe a module (arg: name)", 2},
{ "set-sink-volume", pa_cli_command_sink_volume, "Set the volume of a sink (args: index|name, volume)", 3},
{ "set-source-volume", pa_cli_command_source_volume, "Set the volume of a source (args: index|name, volume)", 3},
{ "set-card-profile", pa_cli_command_card_profile, "Change the profile of a card (args: index|name, profile-name)", 3},
{ "set-sink-port", pa_cli_command_sink_port, "Change the port of a sink (args: index|name, port-name)", 3},
{ "set-source-port", pa_cli_command_source_port, "Change the port of a source (args: index|name, port-name)", 3},
+ { "set-port-latency-offset", pa_cli_command_port_offset, "Change the latency of a port (args: card-index|card-name, port-name, latency-offset)", 4},
{ "suspend-sink", pa_cli_command_suspend_sink, "Suspend sink (args: index|name, bool)", 3},
{ "suspend-source", pa_cli_command_suspend_source, "Suspend source (args: index|name, bool)", 3},
{ "suspend", pa_cli_command_suspend, "Suspend all sinks and all sources (args: bool)", 2},
{ "kill-client", pa_cli_command_kill_client, "Kill a client (args: index)", 2},
{ "kill-sink-input", pa_cli_command_kill_sink_input, "Kill a sink input (args: index)", 2},
{ "kill-source-output", pa_cli_command_kill_source_output, "Kill a source output (args: index)", 2},
+ { "set-log-target", pa_cli_command_log_target, "Change the log target (args: null|auto|syslog|stderr|file:PATH|newfile:PATH)", 2},
{ "set-log-level", pa_cli_command_log_level, "Change the log level (args: numeric level)", 2},
{ "set-log-meta", pa_cli_command_log_meta, "Show source code location in log messages (args: bool)", 2},
{ "set-log-time", pa_cli_command_log_time, "Show timestamps in log messages (args: bool)", 2},
pa_module *m;
uint32_t idx;
const char *i;
- char *e;
+ pa_bool_t unloaded = FALSE;
pa_core_assert_ref(c);
pa_assert(t);
pa_assert(fail);
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 or name.\n");
return -1;
}
- idx = (uint32_t) strtoul(i, &e, 10);
- if (*e || !(m = pa_idxset_get_by_index(c->modules, idx))) {
- pa_strbuf_puts(buf, "Invalid module index.\n");
- return -1;
+ if (pa_atou(i, &idx) >= 0) {
+ if (!(m = pa_idxset_get_by_index(c->modules, idx))) {
+ pa_strbuf_puts(buf, "Invalid module index.\n");
+ return -1;
+ }
+
+ pa_module_unload_request(m, FALSE);
+
+ } else {
+ PA_IDXSET_FOREACH(m, c->modules, idx)
+ if (pa_streq(i, m->name)) {
+ unloaded = TRUE;
+ pa_module_unload_request(m, FALSE);
+ }
+
+ if (unloaded == FALSE) {
+ pa_strbuf_printf(buf, "Module %s not loaded.\n", i);
+ return -1;
+ }
}
- pa_module_unload_request(m, FALSE);
return 0;
}
return -1;
}
+ pa_log_debug("%s of sink %s requested via CLI.", suspend ? "Suspending" : "Resuming", sink->name);
+
if ((r = pa_sink_suspend(sink, suspend, PA_SUSPEND_USER)) < 0)
pa_strbuf_printf(buf, "Failed to resume/suspend sink: %s\n", pa_strerror(r));
return -1;
}
+ pa_log_debug("%s of source %s requested via CLI.", suspend ? "Suspending" : "Resuming", source->name);
+
if ((r = pa_source_suspend(source, suspend, PA_SUSPEND_USER)) < 0)
pa_strbuf_printf(buf, "Failed to resume/suspend source: %s\n", pa_strerror(r));
return -1;
}
+ pa_log_debug("%s of all sinks and sources requested via CLI.", suspend ? "Suspending" : "Resuming");
+
if ((r = pa_sink_suspend_all(c, suspend, PA_SUSPEND_USER)) < 0)
pa_strbuf_printf(buf, "Failed to resume/suspend all sinks: %s\n", pa_strerror(r));
return 0;
}
+static int pa_cli_command_log_target(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
+ const char *m;
+ pa_log_target *log_target = NULL;
+
+ pa_core_assert_ref(c);
+ pa_assert(t);
+ pa_assert(buf);
+ pa_assert(fail);
+
+ if (!(m = pa_tokenizer_get(t, 1))) {
+ pa_strbuf_puts(buf, "You need to specify a log target (null|auto|syslog|stderr|file:PATH|newfile:PATH).\n");
+ return -1;
+ }
+
+ /* 'auto' is actually the effect with 'stderr' */
+ if (pa_streq(m, "auto"))
+ log_target = pa_log_target_new(PA_LOG_STDERR, NULL);
+ else {
+ log_target = pa_log_parse_target(m);
+
+ if (!log_target) {
+ pa_strbuf_puts(buf, "Invalid log target.\n");
+ return -1;
+ }
+ }
+
+ if (pa_log_set_target(log_target) < 0) {
+ pa_strbuf_puts(buf, "Failed to set log target.\n");
+ pa_log_target_free(log_target);
+ return -1;
+ }
+
+ pa_log_target_free(log_target);
+
+ return 0;
+}
+
static int pa_cli_command_log_level(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
const char *m;
uint32_t level;
static int pa_cli_command_log_meta(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
const char *m;
- pa_bool_t b;
+ int b;
pa_core_assert_ref(c);
pa_assert(t);
static int pa_cli_command_log_time(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
const char *m;
- pa_bool_t b;
+ int b;
pa_core_assert_ref(c);
pa_assert(t);
return 0;
}
+static int pa_cli_command_port_offset(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
+ const char *n, *p, *l;
+ pa_device_port *port;
+ pa_card *card;
+ int32_t offset;
+
+ pa_core_assert_ref(c);
+ pa_assert(t);
+ pa_assert(buf);
+ pa_assert(fail);
+
+ if (!(n = pa_tokenizer_get(t, 1))) {
+ pa_strbuf_puts(buf, "You need to specify a card either by its name or its index.\n");
+ return -1;
+ }
+
+ if (!(p = pa_tokenizer_get(t, 2))) {
+ pa_strbuf_puts(buf, "You need to specify a port by its name.\n");
+ return -1;
+ }
+
+ if (!(l = pa_tokenizer_get(t, 3))) {
+ pa_strbuf_puts(buf, "You need to specify a latency offset.\n");
+ return -1;
+ }
+
+ if (pa_atoi(l, &offset) < 0) {
+ pa_strbuf_puts(buf, "Failed to parse the latency offset.\n");
+ return -1;
+ }
+
+ if (!(card = pa_namereg_get(c, n, PA_NAMEREG_CARD))) {
+ pa_strbuf_puts(buf, "No card found by this name or index.\n");
+ return -1;
+ }
+
+ if (!(port = pa_hashmap_get(card->ports, p))) {
+ pa_strbuf_puts(buf, "No port found by this name.\n");
+ return -1;
+ }
+
+ pa_device_port_set_latency_offset(port, offset);
+
+ return 0;
+}
+
static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_bool_t *fail) {
pa_module *m;
pa_sink *sink;
nl = TRUE;
}
- if (card->active_profile)
- pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name);
+ pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name);
}
nl = FALSE;
char *pathname;
pathname = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", p, filename);
- pa_xfree(p);
*ifstate = access(pathname, F_OK) == 0 ? IFSTATE_TRUE : IFSTATE_FALSE;
pa_log_debug("Checking for existence of '%s': %s", pathname, *ifstate == IFSTATE_TRUE ? "success" : "failure");
+ if (PA_UNLIKELY(pa_run_from_build_tree())) {
+ /* If run from the build tree, search in <path>/.libs as well */
+ char *ltpathname = pa_sprintf_malloc("%s" PA_PATH_SEP ".libs" PA_PATH_SEP "%s", p, filename);
+
+ *ifstate = access(ltpathname, F_OK) == 0 ? IFSTATE_TRUE : IFSTATE_FALSE;
+ pa_log_debug("Checking for existence of '%s': %s", ltpathname, *ifstate == IFSTATE_TRUE ? "success" : "failure");
+
+ pa_xfree(ltpathname);
+ }
+
+ pa_xfree(p);
pa_xfree(pathname);
if (*ifstate == IFSTATE_TRUE)