[tracker/libtracker-miner] Make it possible to get all pause apps/reasons
- From: Martyn James Russell <mr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/libtracker-miner] Make it possible to get all pause apps/reasons
- Date: Fri, 28 Aug 2009 11:45:38 +0000 (UTC)
commit aceee39e329549e44fa62172050f0e067dd7e9a4
Author: Martyn Russell <martyn lanedo com>
Date: Fri Aug 28 12:11:54 2009 +0100
Make it possible to get all pause apps/reasons
data/dbus/tracker-miner.xml | 5 +-
src/libtracker-miner/tracker-miner-dbus.h | 48 ++++++------
src/libtracker-miner/tracker-miner.c | 44 +++++++++--
src/tracker-utils/tracker-status.c | 128 +++++++++++++++++++++++++----
4 files changed, 178 insertions(+), 47 deletions(-)
---
diff --git a/data/dbus/tracker-miner.xml b/data/dbus/tracker-miner.xml
index 440af4d..2269969 100644
--- a/data/dbus/tracker-miner.xml
+++ b/data/dbus/tracker-miner.xml
@@ -19,9 +19,10 @@
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="d" name="progress" direction="out" />
</method>
- <method name="GetIsPaused">
+ <method name="GetPauseDetails">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
- <arg type="b" name="is_paused" direction="out" />
+ <arg type="as" name="pause_applications" direction="out" />
+ <arg type="as" name="pause_reasons" direction="out" />
</method>
<method name="Pause">
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
diff --git a/src/libtracker-miner/tracker-miner-dbus.h b/src/libtracker-miner/tracker-miner-dbus.h
index 1370f0e..6220c2f 100644
--- a/src/libtracker-miner/tracker-miner-dbus.h
+++ b/src/libtracker-miner/tracker-miner-dbus.h
@@ -27,30 +27,30 @@
G_BEGIN_DECLS
-void tracker_miner_dbus_get_name (TrackerMiner *miner,
- DBusGMethodInvocation *context,
- GError **error);
-void tracker_miner_dbus_get_description (TrackerMiner *miner,
- DBusGMethodInvocation *context,
- GError **error);
-void tracker_miner_dbus_get_status (TrackerMiner *miner,
- DBusGMethodInvocation *context,
- GError **error);
-void tracker_miner_dbus_get_progress (TrackerMiner *miner,
- DBusGMethodInvocation *context,
- GError **error);
-void tracker_miner_dbus_get_is_paused (TrackerMiner *miner,
- DBusGMethodInvocation *context,
- GError **error);
-void tracker_miner_dbus_pause (TrackerMiner *miner,
- const gchar *application,
- const gchar *name,
- DBusGMethodInvocation *context,
- GError **error);
-void tracker_miner_dbus_resume (TrackerMiner *miner,
- gint cookie,
- DBusGMethodInvocation *context,
- GError **error);
+void tracker_miner_dbus_get_name (TrackerMiner *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_dbus_get_description (TrackerMiner *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_dbus_get_status (TrackerMiner *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_dbus_get_progress (TrackerMiner *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_dbus_get_pause_details (TrackerMiner *miner,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_dbus_pause (TrackerMiner *miner,
+ const gchar *application,
+ const gchar *name,
+ DBusGMethodInvocation *context,
+ GError **error);
+void tracker_miner_dbus_resume (TrackerMiner *miner,
+ gint cookie,
+ DBusGMethodInvocation *context,
+ GError **error);
G_END_DECLS
diff --git a/src/libtracker-miner/tracker-miner.c b/src/libtracker-miner/tracker-miner.c
index 48104b2..962f7ad 100644
--- a/src/libtracker-miner/tracker-miner.c
+++ b/src/libtracker-miner/tracker-miner.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <libtracker-common/tracker-dbus.h>
+#include <libtracker-common/tracker-type-utils.h>
#include "tracker-marshal.h"
#include "tracker-miner.h"
@@ -676,12 +677,15 @@ tracker_miner_dbus_get_progress (TrackerMiner *miner,
}
void
-tracker_miner_dbus_get_is_paused (TrackerMiner *miner,
- DBusGMethodInvocation *context,
- GError **error)
+tracker_miner_dbus_get_pause_details (TrackerMiner *miner,
+ DBusGMethodInvocation *context,
+ GError **error)
{
+ GSList *applications, *reasons;
+ GStrv applications_strv, reasons_strv;
+ GHashTableIter iter;
+ gpointer key, value;
guint request_id;
- gboolean is_paused;
request_id = tracker_dbus_get_next_request_id ();
@@ -689,10 +693,38 @@ tracker_miner_dbus_get_is_paused (TrackerMiner *miner,
tracker_dbus_request_new (request_id, "%s()", __PRETTY_FUNCTION__);
- is_paused = g_hash_table_size (miner->private->pauses) > 0;
- dbus_g_method_return (context, is_paused);
+ applications = NULL;
+ reasons = NULL;
+
+ g_hash_table_iter_init (&iter, miner->private->pauses);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ PauseData *pd;
+
+ pd = value;
+
+ if (!pd) {
+ continue;
+ }
+
+ applications = g_slist_prepend (applications, pd->application);
+ reasons = g_slist_prepend (reasons, pd->reason);
+ }
+
+ applications = g_slist_reverse (applications);
+ reasons = g_slist_reverse (reasons);
+
+ applications_strv = tracker_gslist_to_string_list (applications);
+ reasons_strv = tracker_gslist_to_string_list (reasons);
+
+ dbus_g_method_return (context, applications_strv, reasons_strv);
tracker_dbus_request_success (request_id);
+
+ g_strfreev (applications_strv);
+ g_strfreev (reasons_strv);
+
+ g_slist_free (applications);
+ g_slist_free (reasons);
}
void
diff --git a/src/tracker-utils/tracker-status.c b/src/tracker-utils/tracker-status.c
index f5c223c..bc0070b 100644
--- a/src/tracker-utils/tracker-status.c
+++ b/src/tracker-utils/tracker-status.c
@@ -50,6 +50,7 @@ static GMainLoop *main_loop;
static gboolean show_key;
static gboolean list_miners_running;
static gboolean list_miners_available;
+static gboolean pause_details;
static gchar *miner_name;
static gchar *pause_reason;
static gint resume_cookie = -1;
@@ -77,6 +78,10 @@ static GOptionEntry entries[] = {
N_("List all miners installed"),
NULL
},
+ { "pause-details", 'i', 0, G_OPTION_ARG_NONE, &pause_details,
+ N_("List pause reasons and applications for a miner (you must use this with --miner)"),
+ NULL
+ },
{ "miner", 'm', 0, G_OPTION_ARG_STRING, &miner_name,
N_("Miner to use with other commands (you can use suffixes, e.g. FS or Applications)"),
N_("MINER")
@@ -306,15 +311,25 @@ static gboolean
miner_get_details (const gchar *miner,
gchar **status,
gdouble *progress,
- gboolean *is_paused)
+ GStrv *pause_applications,
+ GStrv *pause_reasons)
{
GError *error = NULL;
DBusGProxy *proxy;
gchar *name;
- *status = NULL;
- *progress = 0.0;
- *is_paused = FALSE;
+ if (status) {
+ *status = NULL;
+ }
+
+ if (progress) {
+ *progress = 0.0;
+ }
+
+ if (pause_applications && pause_reasons) {
+ *pause_applications = NULL;
+ *pause_reasons = NULL;
+ }
name = get_dbus_name (miner);
@@ -324,9 +339,9 @@ miner_get_details (const gchar *miner,
return FALSE;
}
- if (!org_freedesktop_Tracker_Miner_get_status (proxy,
- status,
- &error)) {
+ if (status && !org_freedesktop_Tracker_Miner_get_status (proxy,
+ status,
+ &error)) {
gchar *str;
str = g_strdup_printf (_("Could not get status from miner: %s"),
@@ -342,9 +357,9 @@ miner_get_details (const gchar *miner,
return FALSE;
}
- if (!org_freedesktop_Tracker_Miner_get_progress (proxy,
- progress,
- &error)) {
+ if (progress && !org_freedesktop_Tracker_Miner_get_progress (proxy,
+ progress,
+ &error)) {
gchar *str;
str = g_strdup_printf (_("Could not get progress from miner: %s"),
@@ -360,12 +375,14 @@ miner_get_details (const gchar *miner,
return FALSE;
}
- if (!org_freedesktop_Tracker_Miner_get_is_paused (proxy,
- is_paused,
- &error)) {
+ if ((pause_applications && pause_reasons) &&
+ !org_freedesktop_Tracker_Miner_get_pause_details (proxy,
+ pause_applications,
+ pause_reasons,
+ &error)) {
gchar *str;
- str = g_strdup_printf (_("Could not get paused state from miner: %s"),
+ str = g_strdup_printf (_("Could not get paused details from miner: %s"),
name);
g_printerr (" %s. %s\n",
str,
@@ -498,10 +515,79 @@ main (gint argc, gchar *argv[])
g_slist_foreach (miners_available, (GFunc) g_free, NULL);
g_slist_free (miners_available);
+ g_slist_foreach (miners_running, (GFunc) g_free, NULL);
+ g_slist_free (miners_running);
+
tracker_disconnect (client);
return EXIT_SUCCESS;
}
+ if (pause_details) {
+ if (!miners_running) {
+ g_print ("%s\n", _("No miners are running"));
+
+ g_slist_foreach (miners_available, (GFunc) g_free, NULL);
+ g_slist_free (miners_available);
+
+ g_slist_foreach (miners_running, (GFunc) g_free, NULL);
+ g_slist_free (miners_running);
+
+ return EXIT_SUCCESS;
+ }
+
+ g_print ("%s:\n", _("Miners"));
+
+ for (l = miners_running; l; l = l->next) {
+ const gchar *name;
+ GStrv pause_applications, pause_reasons;
+ gint i;
+
+ if (!strstr (l->data, TRACKER_MINER_DBUS_NAME_PREFIX)) {
+ g_critical ("We have a miner without the dbus name prefix? '%s'",
+ (gchar*) l->data);
+ continue;
+ }
+
+ name = (gchar*) l->data + strlen (TRACKER_MINER_DBUS_NAME_PREFIX);
+
+
+ if (!miner_get_details (l->data,
+ NULL,
+ NULL,
+ &pause_applications,
+ &pause_reasons)) {
+ continue;
+ }
+
+ if (!pause_applications && pause_reasons) {
+ g_strfreev (pause_applications);
+ g_strfreev (pause_reasons);
+ continue;
+ }
+
+ g_print ("%s:\n", name);
+
+ for (i = 0; pause_applications[i] != NULL; i++) {
+ g_print (" %s: '%s', %s: '%s'\n",
+ _("Application"),
+ pause_applications[i],
+ _("Reason"),
+ pause_reasons[i]);
+ }
+
+ g_strfreev (pause_applications);
+ g_strfreev (pause_reasons);
+ }
+
+ g_slist_foreach (miners_available, (GFunc) g_free, NULL);
+ g_slist_free (miners_available);
+
+ g_slist_foreach (miners_running, (GFunc) g_free, NULL);
+ g_slist_free (miners_running);
+
+ return EXIT_SUCCESS;
+ }
+
g_print ("%s:\n", _("Miners"));
for (l = miners_available; l; l = l->next) {
@@ -519,14 +605,21 @@ main (gint argc, gchar *argv[])
is_running = tracker_string_in_gslist (l->data, miners_running);
if (is_running) {
+ GStrv pause_applications, pause_reasons;
gchar *status = NULL;
gdouble progress;
gboolean is_paused;
- if (!miner_get_details (l->data, &status, &progress, &is_paused)) {
+ if (!miner_get_details (l->data,
+ &status,
+ &progress,
+ &pause_applications,
+ &pause_reasons)) {
continue;
}
+ is_paused = pause_applications || pause_reasons;
+
g_print (" [%s] %s: %3.0f%%, %s, %s: '%s'\n",
is_paused ? "P" : "R",
_("Progress"),
@@ -535,6 +628,8 @@ main (gint argc, gchar *argv[])
_("Status"),
status ? status : _("Unknown"));
+ g_strfreev (pause_applications);
+ g_strfreev (pause_reasons);
g_free (status);
} else {
g_print (" [ ] %s: %3.0f%%, %s\n",
@@ -547,6 +642,9 @@ main (gint argc, gchar *argv[])
g_slist_foreach (miners_available, (GFunc) g_free, NULL);
g_slist_free (miners_available);
+ g_slist_foreach (miners_running, (GFunc) g_free, NULL);
+ g_slist_free (miners_running);
+
if (!follow) {
/* Do nothing further */
tracker_disconnect (client);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]