[pulseaudio-discuss] [PATCH 6/6] pactl: Add signal receiver

Georg Chini georg at chini.tk
Sat Aug 19 15:48:06 UTC 2017


---
 man/pactl.1.xml.in               |  5 +++++
 shell-completion/bash/pulseaudio |  2 +-
 shell-completion/zsh/_pulseaudio |  1 +
 src/utils/pactl.c                | 23 +++++++++++++++++++++++
 4 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
index e868babc..57afccd9 100644
--- a/man/pactl.1.xml.in
+++ b/man/pactl.1.xml.in
@@ -256,6 +256,11 @@ License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
       <optdesc><p>Subscribe to events, pactl does not exit by itself, but keeps waiting for new events.</p></optdesc>
     </option>
 
+    <option>
+      <p><opt>subscribe-signals</opt></p>
+      <optdesc><p>Subscribe to signals. Like subscribe, but waits for signals instead of subscription events.</p></optdesc>
+    </option>
+
   </section>
 
   <section name="Authors">
diff --git a/shell-completion/bash/pulseaudio b/shell-completion/bash/pulseaudio
index 797ec067..5e9d595a 100644
--- a/shell-completion/bash/pulseaudio
+++ b/shell-completion/bash/pulseaudio
@@ -121,7 +121,7 @@ _pactl() {
                     set-sink-input-volume set-source-output-volume set-sink-mute
                     set-source-mute set-sink-input-mute set-source-output-mute
                     set-sink-formats set-port-latency-offset subscribe send-message
-                    help)
+                    subscribe-signals help)
 
     _init_completion -n = || return
     preprev=${words[$cword-2]}
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index a2817ebb..641f1358 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -265,6 +265,7 @@ _pactl_completion() {
             'set-sink-formats: set supported formats of a sink'
             'send-message: send a message to a pulseaudio object'
             'subscribe: subscribe to events'
+            'subscribe-signals: subscribe to signals'
         )
 
         _describe 'pactl commands' _pactl_commands
diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index 5fde2bc6..a73c7e50 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -134,6 +134,7 @@ static enum {
     SET_SINK_FORMATS,
     SET_PORT_LATENCY_OFFSET,
     SEND_OBJECT_MESSAGE,
+    SUBSCRIBE_SIGNALS,
     SUBSCRIBE
 } action = NONE;
 
@@ -1200,6 +1201,17 @@ static void context_subscribe_callback(pa_context *c, pa_subscription_event_type
     fflush(stdout);
 }
 
+static void context_signal_callback(pa_context *c, const char *sender, const char *signal, const char *signal_info, void *userdata) {
+    pa_assert(c);
+
+    printf(_("Signal '%s' from %s\n"),
+           signal,
+           sender);
+    if (signal_info)
+        printf(_("Signal Info: '%s'\n"), signal_info);
+    fflush(stdout);
+}
+
 static void context_state_callback(pa_context *c, void *userdata) {
     pa_operation *o = NULL;
 
@@ -1441,6 +1453,12 @@ static void context_state_callback(pa_context *c, void *userdata) {
                                              NULL);
                     break;
 
+                case SUBSCRIBE_SIGNALS:
+                    pa_context_set_signal_callback(c, context_signal_callback, NULL);
+
+                    o = pa_context_subscribe_signals(c, (uint64_t) -1, NULL, NULL);
+                    break;
+
                 default:
                     pa_assert_not_reached();
             }
@@ -1602,6 +1620,7 @@ static void help(const char *argv0) {
     printf("%s %s %s %s\n", argv0, _("[options]"), "set-port-latency-offset", _("CARD-NAME|CARD-#N PORT OFFSET"));
     printf("%s %s %s %s\n", argv0, _("[options]"), "send-message", _("RECIPIENT MESSAGE MESSAGE_PARAMETERS"));
     printf("%s %s %s\n",    argv0, _("[options]"), "subscribe");
+    printf("%s %s %s\n",    argv0, _("[options]"), "subscribe-signals");
     printf(_("\nThe special names @DEFAULT_SINK@, @DEFAULT_SOURCE@ and @DEFAULT_MONITOR@\n"
              "can be used to specify the default sink, source and monitor.\n"));
 
@@ -2053,6 +2072,10 @@ int main(int argc, char *argv[]) {
 
             action = SUBSCRIBE;
 
+        else if (pa_streq(argv[optind], "subscribe-signals"))
+
+            action = SUBSCRIBE_SIGNALS;
+
         else if (pa_streq(argv[optind], "set-sink-formats")) {
             int32_t tmp;
 
-- 
2.11.0



More information about the pulseaudio-discuss mailing list