[pulseaudio-discuss] [PATCH 2/6] pactl: New command: device-manager-list-devices

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Wed Jan 14 13:27:10 PST 2015


---
 man/pactl.1.xml.in               |  6 ++++
 shell-completion/bash/pulseaudio |  3 +-
 shell-completion/zsh/_pulseaudio |  1 +
 src/utils/pactl.c                | 63 ++++++++++++++++++++++++++++++++++++++--
 4 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
index c2064ca..6b93661 100644
--- a/man/pactl.1.xml.in
+++ b/man/pactl.1.xml.in
@@ -250,6 +250,12 @@ 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>device-manager-list-devices</opt></p>
+      <optdesc><p>List all entries in the device-manager database. This command
+      works only if module-device-manager is loaded.</p></optdesc>
+    </option>
+
   </section>
 
   <section name="Authors">
diff --git a/shell-completion/bash/pulseaudio b/shell-completion/bash/pulseaudio
index 4d7e0b8..ac06603 100644
--- a/shell-completion/bash/pulseaudio
+++ b/shell-completion/bash/pulseaudio
@@ -120,7 +120,8 @@ _pactl() {
                     set-source-port set-sink-volume set-source-volume
                     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 help)
+                    set-sink-formats set-port-latency-offset subscribe help
+                    device-manager-list-devices)
 
     _init_completion -n = || return
     preprev=${words[$cword-2]}
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index c7d68f5..908e49d 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -264,6 +264,7 @@ _pactl_completion() {
             'set-source-output-mute: mute a recording stream'
             'set-sink-formats: set supported formats of a sink'
             'subscribe: subscribe to events'
+            'device-manager-list-devices: list devices in the device-manager database'
         )
 
         _describe 'pactl commands' _pactl_commands
diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index a3ff527..ecaa4dc 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -131,7 +131,8 @@ static enum {
     SET_SOURCE_OUTPUT_MUTE,
     SET_SINK_FORMATS,
     SET_PORT_LATENCY_OFFSET,
-    SUBSCRIBE
+    SUBSCRIBE,
+    DEVICE_MANAGER_LIST_DEVICES,
 } action = NONE;
 
 static void quit(int ret) {
@@ -1194,6 +1195,51 @@ static void device_manager_subscribe_callback(pa_context *c, void *userdata) {
     fflush(stdout);
 }
 
+static void device_manager_read_callback(pa_context *c, const pa_ext_device_manager_info *info, int is_last, void *userdata) {
+    char *index_str;
+    unsigned i;
+
+    pa_assert(c);
+
+    if (is_last < 0) {
+        pa_log(_("Failed to get device manager information: %s"), pa_strerror(pa_context_errno(c)));
+        quit(1);
+        return;
+    }
+
+    if (is_last) {
+        complete_action();
+        return;
+    }
+
+    pa_assert(info);
+
+    if (nl)
+        printf("\n");
+    nl = true;
+
+    if (info->index != PA_INVALID_INDEX)
+        index_str = pa_sprintf_malloc("%u", info->index);
+    else
+        index_str = pa_xstrdup(_("(unset)"));
+
+    printf(_("Device %s\n"
+             "\tDescription: %s\n"
+             "\tIcon: %s\n"
+             "\tIndex: %s\n"
+             "\tRole priorities: %s\n"),
+           info->name,
+           info->description ? info->description : _("(unset)"),
+           info->icon ? info->icon : _("(unset)"),
+           index_str,
+           info->n_role_priorities > 0 ? "" : _("(none)"));
+
+    for (i = 0; i < info->n_role_priorities; i++)
+        printf("\t\t%s: %u\n", info->role_priorities[i].role, info->role_priorities[i].priority);
+
+    pa_xfree(index_str);
+}
+
 static void context_state_callback(pa_context *c, void *userdata) {
     pa_operation *o = NULL;
 
@@ -1439,7 +1485,11 @@ static void context_state_callback(pa_context *c, void *userdata) {
 
                     break;
 
-                default:
+                case DEVICE_MANAGER_LIST_DEVICES:
+                    o = pa_ext_device_manager_read(c, device_manager_read_callback, NULL);
+                    break;
+
+                case NONE:
                     pa_assert_not_reached();
             }
 
@@ -1593,6 +1643,7 @@ static void help(const char *argv0) {
     printf("%s %s %s %s\n", argv0, _("[options]"), "set-sink-formats", _("#N FORMATS"));
     printf("%s %s %s %s\n", argv0, _("[options]"), "set-port-latency-offset", _("CARD-NAME|CARD-#N PORT OFFSET"));
     printf("%s %s %s\n",    argv0, _("[options]"), "subscribe");
+    printf("%s %s %s\n",    argv0, _("[options]"), "device-manager-list-devices");
     printf(_("\nThe special names @DEFAULT_SINK@, @DEFAULT_SOURCE@ and @DEFAULT_MONITOR@\n"
              "can be used to specify the default sink, source and monitor.\n"));
 
@@ -2058,6 +2109,14 @@ int main(int argc, char *argv[]) {
                 goto quit;
             }
 
+        } else if (pa_streq(argv[optind], "device-manager-list-devices")) {
+            action = DEVICE_MANAGER_LIST_DEVICES;
+
+            if (argc > optind + 1) {
+                pa_log(_("Too many arguments."));
+                goto quit;
+            }
+
         } else if (pa_streq(argv[optind], "help")) {
             help(bn);
             ret = 0;
-- 
1.9.3



More information about the pulseaudio-discuss mailing list