Add --poll-for-media option to devkit-disks(1)
authorDavid Zeuthen <davidz@redhat.com>
Tue, 7 Jul 2009 00:44:03 +0000 (20:44 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Tue, 7 Jul 2009 00:44:03 +0000 (20:44 -0400)
doc/man/devkit-disks.xml
tools/devkit-disks-bash-completion.sh
tools/devkit-disks.c

index aa38687..31158be 100644 (file)
 
       <varlistentry>
         <term>
+          <option>--poll-for-media</option>
+          <arg choice="plain"><replaceable>device_file</replaceable></arg>
+        </term>
+        <listitem>
+          <para>
+            Polls <replaceable>device_file</replaceable> to perform media detection.
+          </para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>
           <option>--inhibit-all-polling</option>
           <arg><option>-- program arg ...</option></arg>
         </term>
index 57af088..1ade65f 100644 (file)
@@ -24,8 +24,10 @@ __devkit_disks() {
         _filedir || return 0
     elif [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--set-spindown" ] ; then
         COMPREPLY=($(compgen -W "$(devkit-disks --enumerate-device-files)" -- $cur))
+    elif [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--poll-for-media" ] ; then
+        COMPREPLY=($(compgen -W "$(devkit-disks --enumerate-device-files)" -- $cur))
     else
-        COMPREPLY=($(IFS=: compgen -W "--dump:--inhibit-polling:--inhibit-all-polling:--enumerate:--enumerate-device-files:--monitor:--monitor-detail:--show-info:--help:--mount:--mount-fstype:--mount-options:--unmount:--unmount-options:--detach:--detach-options:--ata-smart-refresh:--ata-smart-wakeup:--ata-smart-simulate:--set-spindown:--set-spindown-all:--spindown-timeout" -- $cur))
+        COMPREPLY=($(IFS=: compgen -W "--dump:--inhibit-polling:--inhibit-all-polling:--enumerate:--enumerate-device-files:--monitor:--monitor-detail:--show-info:--help:--mount:--mount-fstype:--mount-options:--unmount:--unmount-options:--detach:--detach-options:--ata-smart-refresh:--ata-smart-wakeup:--ata-smart-simulate:--set-spindown:--set-spindown-all:--spindown-timeout:--poll-for-media" -- $cur))
     fi
 }
 
index 5b23520..f8e7da8 100644 (file)
@@ -58,6 +58,7 @@ static gboolean      opt_monitor                = FALSE;
 static gboolean      opt_monitor_detail         = FALSE;
 static char         *opt_show_info              = NULL;
 static char         *opt_inhibit_polling        = NULL;
+static char         *opt_poll_for_media         = NULL;
 static gboolean      opt_inhibit                = FALSE;
 static gboolean      opt_inhibit_all_polling    = FALSE;
 static char         *opt_drive_spindown         = NULL;
@@ -1300,6 +1301,36 @@ do_show_info (const char *object_path)
 /* ---------------------------------------------------------------------------------------------------- */
 
 static gint
+do_poll_for_media (const char *object_path)
+{
+        DBusGProxy *proxy;
+        GError *error;
+        gint ret;
+
+        ret = 1;
+
+       proxy = dbus_g_proxy_new_for_name (bus,
+                                           "org.freedesktop.DeviceKit.Disks",
+                                           object_path,
+                                           "org.freedesktop.DeviceKit.Disks.Device");
+
+        error = NULL;
+        if (!org_freedesktop_DeviceKit_Disks_Device_drive_poll_media (proxy,
+                                                                      &error)) {
+                g_print ("Poll for media failed: %s\n", error->message);
+                g_error_free (error);
+                goto out;
+        }
+
+        ret = 0;
+
+out:
+        return ret;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static gint
 do_inhibit_polling (const char *object_path,
                     gint         argc,
                     gchar       *argv[])
@@ -1730,6 +1761,7 @@ main (int argc, char **argv)
                 { "show-info", 0, 0, G_OPTION_ARG_STRING, &opt_show_info, "Show information about a device file", NULL },
                 { "inhibit-polling", 0, 0, G_OPTION_ARG_STRING, &opt_inhibit_polling, "Inhibit polling", NULL },
                 { "inhibit-all-polling", 0, 0, G_OPTION_ARG_NONE, &opt_inhibit_all_polling, "Inhibit all polling", NULL },
+                { "poll-for-media", 0, 0, G_OPTION_ARG_STRING, &opt_poll_for_media, "Poll for media", NULL },
                 { "set-spindown", 0, 0, G_OPTION_ARG_STRING, &opt_drive_spindown, "Set spindown timeout for drive", NULL },
                 { "set-spindown-all", 0, 0, G_OPTION_ARG_NONE, &opt_drive_spindown_all, "Set spindown timeout for all drives", NULL },
                 { "spindown-timeout", 0, 0, G_OPTION_ARG_INT, &opt_spindown_seconds, "Spindown timeout in seconds", NULL },
@@ -1853,6 +1885,12 @@ main (int argc, char **argv)
                         goto out;
                 ret = do_inhibit_polling (device_file, argc - 1, argv + 1);
                 goto out;
+        } else if (opt_poll_for_media != NULL) {
+                device_file = device_file_to_object_path (opt_poll_for_media);
+                if (device_file == NULL)
+                        goto out;
+                ret = do_poll_for_media (device_file);
+                goto out;
         } else if (opt_inhibit_all_polling) {
                 ret = do_inhibit_all_polling (argc - 1, argv + 1);
                 goto out;