Re: [pulseaudio-discuss] [PATCH 5/8] pactl: Implement list message-handlers

2018-07-15 Thread Tanu Kaskinen
On Mon, 2018-04-09 at 19:35 +0200, Georg Chini wrote:
> 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_param_split_list() and
> pa_message_param_read_string() for easy parsing of the message response
> string. Because the function needs 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.
> ---
>  man/pactl.1.xml.in   |   2 +-
>  shell-completion/bash/pulseaudio |   2 +-
>  shell-completion/zsh/_pulseaudio |   1 +
>  src/Makefile.am  |   1 +
>  src/map-file |   2 +
>  src/pulse/introspect.c   |  11 +++-
>  src/pulse/introspect.h   |   2 +-
>  src/pulse/message-params.c   | 116 
> +++
>  src/pulse/message-params.h   |  41 ++
>  src/pulsecore/core.c |   2 +-
>  src/pulsecore/message-handler.c  |   9 ++-
>  src/pulsecore/message-handler.h  |   2 +-
>  src/utils/pactl.c|  65 +-
>  13 files changed, 245 insertions(+), 11 deletions(-)
>  create mode 100644 src/pulse/message-params.c
>  create mode 100644 src/pulse/message-params.h
> 
> diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
> index 4052fae3..66c0bda9 100644
> --- a/man/pactl.1.xml.in
> +++ b/man/pactl.1.xml.in
> @@ -76,7 +76,7 @@ License along with PulseAudio; if not, see 
> .
>  
>list [short] [TYPE]
>Dump all currently loaded modules, available sinks, 
> sources, streams, etc.  TYPE must be one of:
> -  modules, sinks, sources, sink-inputs, source-outputs, clients, 
> samples, cards.  If not specified, all info is listed.  If
> +  modules, sinks, sources, sink-inputs, source-outputs, clients, 
> samples, cards, message-handlers.  If not specified, all info is listed.  If
>short is given, output is in a tabular format, for easy parsing by 
> scripts.
>  
>  
> diff --git a/shell-completion/bash/pulseaudio 
> b/shell-completion/bash/pulseaudio
> index 797ec067..24d2aa1c 100644
> --- a/shell-completion/bash/pulseaudio
> +++ b/shell-completion/bash/pulseaudio
> @@ -113,7 +113,7 @@ _pactl() {
>  local comps
>  local flags='-h --help --version -s --server= --client-name='
>  local list_types='short sinks sources sink-inputs source-outputs cards
> -modules samples clients'
> +modules samples clients message-handlers'
>  local commands=(stat info list exit upload-sample play-sample 
> remove-sample
>  load-module unload-module move-sink-input 
> move-source-output
>  suspend-sink suspend-source set-card-profile 
> set-sink-port
> diff --git a/shell-completion/zsh/_pulseaudio 
> b/shell-completion/zsh/_pulseaudio
> index a2817ebb..c24d0387 100644
> --- a/shell-completion/zsh/_pulseaudio
> +++ b/shell-completion/zsh/_pulseaudio
> @@ -285,6 +285,7 @@ _pactl_completion() {
>  'clients: list connected clients'
>  'samples: list samples'
>  'cards: list available cards'
> +'message-handlers: list available message-handlers'
>  )
>  
>  if ((CURRENT == 2)); then
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 27e5f875..ccdad8ff 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -896,6 +896,7 @@ libpulse_la_SOURCES = \
>   pulse/timeval.c pulse/timeval.h \
>   pulse/utf8.c pulse/utf8.h \
>   pulse/util.c pulse/util.h \
> + pulse/message-params.c pulse/message-params.h \
>   pulse/volume.c pulse/volume.h \
>   pulse/xmalloc.c pulse/xmalloc.h
>  
> diff --git a/src/map-file b/src/map-file
> index 4d747f19..385731dc 100644
> --- a/src/map-file
> +++ b/src/map-file
> @@ -225,6 +225,8 @@ pa_mainloop_quit;
>  pa_mainloop_run;
>  pa_mainloop_set_poll_func;
>  pa_mainloop_wakeup;
> +pa_message_param_read_string;
> +pa_message_param_split_list;

Let's use "pa_message_params" as the prefix to be consistent with the
file names (and plural makes more sense anyway).

>  pa_msleep;
>  pa_operation_cancel;
>  pa_operation_get_state;
> diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c
> index 76bfee41..23901eb3 100644
> --- a/src/pulse/introspect.c
> +++ b/src/pulse/introspect.c
> @@ -2215,8 +2215,15 @@ static void context_string_callback(pa_pdispatch *pd, 
> uint32_t command, uint32_t
>  response = "";
>  
>  if (o->callback) {
> -pa_context_string_cb_t cb = (pa_context_string_cb_t) o->callback;
> -cb(o->context, success, response, o->userdata);
> +char *response_copy;
> +pa_context_string_cb_t cb;
> +
> +response_copy = pa_xstrdup(response);
> +
> +   

[pulseaudio-discuss] [PATCH 5/8] pactl: Implement list message-handlers

2018-04-09 Thread Georg Chini
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_param_split_list() and
pa_message_param_read_string() for easy parsing of the message response
string. Because the function needs 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.
---
 man/pactl.1.xml.in   |   2 +-
 shell-completion/bash/pulseaudio |   2 +-
 shell-completion/zsh/_pulseaudio |   1 +
 src/Makefile.am  |   1 +
 src/map-file |   2 +
 src/pulse/introspect.c   |  11 +++-
 src/pulse/introspect.h   |   2 +-
 src/pulse/message-params.c   | 116 +++
 src/pulse/message-params.h   |  41 ++
 src/pulsecore/core.c |   2 +-
 src/pulsecore/message-handler.c  |   9 ++-
 src/pulsecore/message-handler.h  |   2 +-
 src/utils/pactl.c|  65 +-
 13 files changed, 245 insertions(+), 11 deletions(-)
 create mode 100644 src/pulse/message-params.c
 create mode 100644 src/pulse/message-params.h

diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
index 4052fae3..66c0bda9 100644
--- a/man/pactl.1.xml.in
+++ b/man/pactl.1.xml.in
@@ -76,7 +76,7 @@ License along with PulseAudio; if not, see 
.
 
   list [short] [TYPE]
   Dump all currently loaded modules, available sinks, sources, 
streams, etc.  TYPE must be one of:
-  modules, sinks, sources, sink-inputs, source-outputs, clients, samples, 
cards.  If not specified, all info is listed.  If
+  modules, sinks, sources, sink-inputs, source-outputs, clients, samples, 
cards, message-handlers.  If not specified, all info is listed.  If
   short is given, output is in a tabular format, for easy parsing by 
scripts.
 
 
diff --git a/shell-completion/bash/pulseaudio b/shell-completion/bash/pulseaudio
index 797ec067..24d2aa1c 100644
--- a/shell-completion/bash/pulseaudio
+++ b/shell-completion/bash/pulseaudio
@@ -113,7 +113,7 @@ _pactl() {
 local comps
 local flags='-h --help --version -s --server= --client-name='
 local list_types='short sinks sources sink-inputs source-outputs cards
-modules samples clients'
+modules samples clients message-handlers'
 local commands=(stat info list exit upload-sample play-sample remove-sample
 load-module unload-module move-sink-input 
move-source-output
 suspend-sink suspend-source set-card-profile set-sink-port
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index a2817ebb..c24d0387 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -285,6 +285,7 @@ _pactl_completion() {
 'clients: list connected clients'
 'samples: list samples'
 'cards: list available cards'
+'message-handlers: list available message-handlers'
 )
 
 if ((CURRENT == 2)); then
diff --git a/src/Makefile.am b/src/Makefile.am
index 27e5f875..ccdad8ff 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -896,6 +896,7 @@ libpulse_la_SOURCES = \
pulse/timeval.c pulse/timeval.h \
pulse/utf8.c pulse/utf8.h \
pulse/util.c pulse/util.h \
+   pulse/message-params.c pulse/message-params.h \
pulse/volume.c pulse/volume.h \
pulse/xmalloc.c pulse/xmalloc.h
 
diff --git a/src/map-file b/src/map-file
index 4d747f19..385731dc 100644
--- a/src/map-file
+++ b/src/map-file
@@ -225,6 +225,8 @@ pa_mainloop_quit;
 pa_mainloop_run;
 pa_mainloop_set_poll_func;
 pa_mainloop_wakeup;
+pa_message_param_read_string;
+pa_message_param_split_list;
 pa_msleep;
 pa_operation_cancel;
 pa_operation_get_state;
diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c
index 76bfee41..23901eb3 100644
--- a/src/pulse/introspect.c
+++ b/src/pulse/introspect.c
@@ -2215,8 +2215,15 @@ static void context_string_callback(pa_pdispatch *pd, 
uint32_t command, uint32_t
 response = "";
 
 if (o->callback) {
-pa_context_string_cb_t cb = (pa_context_string_cb_t) o->callback;
-cb(o->context, success, response, o->userdata);
+char *response_copy;
+pa_context_string_cb_t cb;
+
+response_copy = pa_xstrdup(response);
+
+cb = (pa_context_string_cb_t) o->callback;
+cb(o->context, success, response_copy, o->userdata);
+
+pa_xfree(response_copy);
 }
 
 finish:
diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h
index fbe5b668..bcec48da 100644
--- a/src/pulse/introspect.h
+++ b/src/pulse/introspect.h
@@ -449,7 +449,7 @@ pa_operation* pa_context_unload_module(pa_context *c, 
uint32_t