mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-06 13:29:56 -05:00
pactl: Implement list message-handlers
For better readability, "pactl list message-handlers" is introduced which prints a formatted output of "pactl send-message /core list-handlers". The patch also adds the functions pa_message_params_read_raw() and pa_message_params_read_string() for easy parsing of the message response string. Because the functions need to modify the parameter string, the message handler and the pa_context_string_callback function now receive a char* instead of a const char* as parameter argument. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/51>
This commit is contained in:
parent
5c0ab52145
commit
4a28b164d1
15 changed files with 253 additions and 12 deletions
|
|
@ -35,6 +35,7 @@
|
|||
#include <sndfile.h>
|
||||
|
||||
#include <pulse/pulseaudio.h>
|
||||
#include <pulse/message-params.h>
|
||||
#include <pulse/ext-device-restore.h>
|
||||
|
||||
#include <pulsecore/i18n.h>
|
||||
|
|
@ -882,7 +883,7 @@ static void index_callback(pa_context *c, uint32_t idx, void *userdata) {
|
|||
complete_action();
|
||||
}
|
||||
|
||||
static void send_message_callback(pa_context *c, int success, const char *response, void *userdata) {
|
||||
static void send_message_callback(pa_context *c, int success, char *response, void *userdata) {
|
||||
|
||||
if (!success) {
|
||||
pa_log(_("Send message failed: %s"), pa_strerror(pa_context_errno(c)));
|
||||
|
|
@ -895,6 +896,62 @@ static void send_message_callback(pa_context *c, int success, const char *respon
|
|||
complete_action();
|
||||
}
|
||||
|
||||
static void list_handlers_callback(pa_context *c, int success, char *response, void *userdata) {
|
||||
void *state = NULL;
|
||||
char *handler_list;
|
||||
char *handler_struct;
|
||||
int err;
|
||||
|
||||
if (!success) {
|
||||
pa_log(_("list-handlers message failed: %s"), pa_strerror(pa_context_errno(c)));
|
||||
quit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pa_message_params_read_raw(response, &handler_list, &state) <= 0) {
|
||||
pa_log(_("list-handlers message response could not be parsed correctly"));
|
||||
quit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
state = NULL;
|
||||
while ((err = pa_message_params_read_raw(handler_list, &handler_struct, &state)) > 0) {
|
||||
void *state2 = NULL;
|
||||
const char *path;
|
||||
const char *description;
|
||||
|
||||
if (pa_message_params_read_string(handler_struct, &path, &state2) <= 0) {
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
if (pa_message_params_read_string(handler_struct, &description, &state2) <= 0) {
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (short_list_format)
|
||||
printf("%s\n", path);
|
||||
else {
|
||||
if (nl)
|
||||
printf("\n");
|
||||
nl = true;
|
||||
|
||||
printf("Message Handler %s\n"
|
||||
"\tDescription: %s\n",
|
||||
path,
|
||||
description);
|
||||
}
|
||||
}
|
||||
|
||||
if (err < 0) {
|
||||
pa_log(_("list-handlers message response could not be parsed correctly"));
|
||||
quit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
complete_action();
|
||||
}
|
||||
|
||||
static void volume_relative_adjust(pa_cvolume *cv) {
|
||||
pa_assert(volume_flags & VOL_RELATIVE);
|
||||
|
||||
|
|
@ -1308,6 +1365,8 @@ static void context_state_callback(pa_context *c, void *userdata) {
|
|||
o = pa_context_get_sample_info_list(c, get_sample_info_callback, NULL);
|
||||
else if (pa_streq(list_type, "cards"))
|
||||
o = pa_context_get_card_info_list(c, get_card_info_callback, NULL);
|
||||
else if (pa_streq(list_type, "message-handlers"))
|
||||
o = pa_context_send_message_to_object(c, "/core", "list-handlers", NULL, list_handlers_callback, NULL);
|
||||
else
|
||||
pa_assert_not_reached();
|
||||
} else {
|
||||
|
|
@ -1744,12 +1803,13 @@ int main(int argc, char *argv[]) {
|
|||
if (pa_streq(argv[i], "modules") || pa_streq(argv[i], "clients") ||
|
||||
pa_streq(argv[i], "sinks") || pa_streq(argv[i], "sink-inputs") ||
|
||||
pa_streq(argv[i], "sources") || pa_streq(argv[i], "source-outputs") ||
|
||||
pa_streq(argv[i], "samples") || pa_streq(argv[i], "cards")) {
|
||||
pa_streq(argv[i], "samples") || pa_streq(argv[i], "cards") ||
|
||||
pa_streq(argv[i], "message-handlers")) {
|
||||
list_type = pa_xstrdup(argv[i]);
|
||||
} else if (pa_streq(argv[i], "short")) {
|
||||
short_list_format = true;
|
||||
} else {
|
||||
pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards");
|
||||
pa_log(_("Specify nothing, or one of: %s"), "modules, sinks, sources, sink-inputs, source-outputs, clients, samples, cards, message-handlers");
|
||||
goto quit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue