[pulseaudio-discuss] [PATCH 4/6] pactl: New command: device-manager-delete-entries

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


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

diff --git a/man/pactl.1.xml.in b/man/pactl.1.xml.in
index c4be220..8cff2e4 100644
--- a/man/pactl.1.xml.in
+++ b/man/pactl.1.xml.in
@@ -264,6 +264,15 @@ License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
       This command works only if module-device-manager is loaded.</p></optdesc>
     </option>
 
+    <option>
+      <p><opt>device-manager-delete-entries</opt>
+      <arg>DEVICE [DEVICE ...]</arg></p>
+      <optdesc><p>Delete device entries from the device-manager database.
+      DEVICE has format TYPE:NAME, where TYPE is "sink" or "source" and NAME is
+      the sink or source name. 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 45a705c..6d598ce 100644
--- a/shell-completion/bash/pulseaudio
+++ b/shell-completion/bash/pulseaudio
@@ -128,7 +128,8 @@ _pactl() {
                     set-source-mute set-sink-input-mute set-source-output-mute
                     set-sink-formats set-port-latency-offset subscribe help
                     device-manager-list-devices
-                    device-manager-set-device-description)
+                    device-manager-set-device-description
+                    device-manager-delete-entries)
 
     _init_completion -n = || return
     preprev=${words[$cword-2]}
@@ -248,6 +249,12 @@ _pactl() {
     esac
     [[ $COMPREPLY ]] && return 0
 
+    if [[ "$command" == device-manager-delete-entries ]] ; then
+        comps=$(__device_manager_devices)
+        COMPREPLY=($(compgen -W '${comps[*]}' -- "$cur"))
+        return 0
+    fi
+
     case $cur in
         --server=*)
             cur=${cur#*=}
diff --git a/shell-completion/zsh/_pulseaudio b/shell-completion/zsh/_pulseaudio
index 569fae1..4e8eae4 100644
--- a/shell-completion/zsh/_pulseaudio
+++ b/shell-completion/zsh/_pulseaudio
@@ -288,6 +288,7 @@ _pactl_completion() {
             'subscribe: subscribe to events'
             'device-manager-list-devices: list devices in the device-manager database'
             'device-manager-set-device-description: set the description of a device'
+            'device-manager-delete-entries: delete device entries from the device-manager database'
         )
 
         _describe 'pactl commands' _pactl_commands
@@ -517,6 +518,7 @@ _pactl_completion() {
             set-sink-formats)                      if ((CURRENT == 2)); then _devices; fi;;
             set-port-latency-offset)               _set_port_latency_offset_parameter;;
             device-manager-set-device-description) if ((CURRENT == 2)); then _device_manager_devices; fi;;
+            device-manager-delete-entries)         _device_manager_devices;;
         esac
     }
 
diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index f460a93..e5eba49 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -61,6 +61,9 @@ static char
     *device = NULL,
     *description = NULL;
 
+static int n_devices = 0;
+static char **devices = NULL;
+
 static uint32_t
     sink_input_idx = PA_INVALID_INDEX,
     source_output_idx = PA_INVALID_INDEX,
@@ -136,6 +139,7 @@ static enum {
     SUBSCRIBE,
     DEVICE_MANAGER_LIST_DEVICES,
     DEVICE_MANAGER_SET_DEVICE_DESCRIPTION,
+    DEVICE_MANAGER_DELETE_ENTRIES,
 } action = NONE;
 
 static void quit(int ret) {
@@ -1496,6 +1500,10 @@ static void context_state_callback(pa_context *c, void *userdata) {
                     o = pa_ext_device_manager_set_device_description(c, device, description, simple_callback, (void *) false);
                     break;
 
+                case DEVICE_MANAGER_DELETE_ENTRIES:
+                    o = pa_ext_device_manager_delete(c, (const char * const *) devices, simple_callback, (void *) false);
+                    break;
+
                 case NONE:
                     pa_assert_not_reached();
             }
@@ -1652,6 +1660,7 @@ static void help(const char *argv0) {
     printf("%s %s %s\n",    argv0, _("[options]"), "subscribe");
     printf("%s %s %s\n",    argv0, _("[options]"), "device-manager-list-devices");
     printf("%s %s %s %s\n", argv0, _("[options]"), "device-manager-set-device-description", _("DEVICE DESCRIPTION"));
+    printf("%s %s %s %s\n", argv0, _("[options]"), "device-manager-delete-entries", _("DEVICE [DEVICE ...]"));
     printf(_("\nThe special names @DEFAULT_SINK@, @DEFAULT_SOURCE@ and @DEFAULT_MONITOR@\n"
              "can be used to specify the default sink, source and monitor.\n"));
 
@@ -1670,6 +1679,7 @@ int main(int argc, char *argv[]) {
     pa_mainloop *m = NULL;
     int ret = 1, c;
     char *server = NULL, *bn;
+    int i;
 
     static const struct option long_options[] = {
         {"server",      1, NULL, 's'},
@@ -1743,7 +1753,7 @@ int main(int argc, char *argv[]) {
         else if (pa_streq(argv[optind], "list")) {
             action = LIST;
 
-            for (int i = optind+1; i < argc; i++) {
+            for (i = optind + 1; i < argc; i++) {
                 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") ||
@@ -1836,7 +1846,6 @@ int main(int argc, char *argv[]) {
             source_name = pa_xstrdup(argv[optind+2]);
 
         } else if (pa_streq(argv[optind], "load-module")) {
-            int i;
             size_t n = 0;
             char *p;
 
@@ -2141,6 +2150,21 @@ int main(int argc, char *argv[]) {
             device = pa_xstrdup(argv[optind + 1]);
             description = pa_xstrdup(argv[optind + 2]);
 
+        } else if (pa_streq(argv[optind], "device-manager-delete-entries")) {
+            action = DEVICE_MANAGER_DELETE_ENTRIES;
+
+            n_devices = argc - optind - 1;
+
+            if (n_devices == 0) {
+                pa_log(_("Too few arguments. You have to specify at least one device."));
+                goto quit;
+            }
+
+            devices = pa_xnew0(char *, n_devices + 1);
+
+            for (i = 0; i < n_devices; i++)
+                devices[i] = pa_xstrdup(argv[optind + 1 + i]);
+
         } else if (pa_streq(argv[optind], "help")) {
             help(bn);
             ret = 0;
@@ -2206,6 +2230,11 @@ quit:
     pa_xfree(device);
     pa_xfree(description);
 
+    for (i = 0; i < n_devices; i++)
+        pa_xfree(devices[i]);
+
+    pa_xfree(devices);
+
     if (sndfile)
         sf_close(sndfile);
 
-- 
1.9.3



More information about the pulseaudio-discuss mailing list