[Tracker] add one feature to query tracker daemon's busy/idle status
- From: Jerry Tan <Jerry Tan Sun COM>
- To: tracker-list gnome org
- Subject: [Tracker] add one feature to query tracker daemon's busy/idle status
- Date: Fri, 29 Jun 2007 10:56:41 +0800
This patch add one API to tracker client,
so it is easy to query tracker daemon's busy/idle status by call it.
for example, a desktop applet can show different icons when tracker
daemon is busy or idle.
Index: src/trackerd/trackerd.c
===================================================================
--- src/trackerd/trackerd.c (revision 599)
+++ src/trackerd/trackerd.c (working copy)
@@ -1417,20 +1417,36 @@
break;
- case DBUS_ACTION_GET_SERVICES:
+ case DBUS_ACTION_IS_BUSY:
- tracker_dbus_method_get_services (rec);
+ reply = dbus_message_new_method_return (rec->message);
- break;
+ gboolean is_busy = FALSE;
+
+ gint has_pendings = g_async_queue_length(tracker->file_process_queue);
+ if (has_pendings > 0)
+ is_busy = TRUE;
+
+
+ dbus_message_append_args (reply,
+ DBUS_TYPE_BOOLEAN, &is_busy,
+ DBUS_TYPE_INVALID);
- case DBUS_ACTION_GET_VERSION:
+ dbus_connection_send (rec->connection, reply, NULL);
+ dbus_message_unref (reply);
- tracker_dbus_method_get_version (rec);
+
+// tracker_dbus_method_is_busy(rec);
+
+ break;
+ case DBUS_ACTION_GET_SERVICES:
+
+ tracker_dbus_method_get_services (rec);
+
break;
-
case DBUS_ACTION_METADATA_GET:
tracker_dbus_method_metadata_get (rec);
Index: src/trackerd/tracker-dbus.c
===================================================================
--- src/trackerd/tracker-dbus.c (revision 599)
+++ src/trackerd/tracker-dbus.c (working copy)
@@ -127,6 +127,12 @@
rec->action = DBUS_ACTION_PING;
+ } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_IS_BUSY)) {
+
+ dbus_message_ref (message);
+ rec->action = DBUS_ACTION_IS_BUSY;
+
+
} else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_GET_STATS)) {
dbus_message_ref (message);
Index: src/trackerd/tracker-dbus.h
===================================================================
--- src/trackerd/tracker-dbus.h (revision 599)
+++ src/trackerd/tracker-dbus.h (working copy)
@@ -40,6 +40,7 @@
/* main service interface */
#define TRACKER_METHOD_PING "Ping"
+#define TRACKER_METHOD_IS_BUSY "IsBusy"
#define TRACKER_METHOD_GET_STATS "GetStats"
#define TRACKER_METHOD_GET_SERVICES "GetServices"
#define TRACKER_METHOD_GET_VERSION "GetVersion"
@@ -109,6 +110,7 @@
DBUS_ACTION_NONE,
DBUS_ACTION_PING,
+ DBUS_ACTION_IS_BUSY,
DBUS_ACTION_GET_SERVICES,
DBUS_ACTION_GET_STATS,
DBUS_ACTION_GET_VERSION,
Index: src/libtracker/tracker.h
===================================================================
--- src/libtracker/tracker.h (revision 599)
+++ src/libtracker/tracker.h (working copy)
@@ -101,6 +101,7 @@
/* synchronous calls */
int tracker_get_version (TrackerClient *client, GError **error);
+gboolean tracker_is_busy (TrackerClient *client, GError
**error);
GHashTable * tracker_get_services (TrackerClient *client, gboolean
main_services_only, GError **error);
GPtrArray * tracker_get_stats (TrackerClient *client, GError **error);
@@ -156,6 +157,7 @@
void tracker_get_version_async (TrackerClient *client,
TrackerIntReply callback, gpointer user_data);
+void tracker_is_busy_async (TrackerClient *client,
TrackerIntReply callback, gpointer user_data);
void tracker_get_services_async (TrackerClient *client, gboolean
main_services_only, TrackerHashTableReply callback, gpointer user_data);
void tracker_get_stats_async (TrackerClient *client,
TrackerGPtrArrayReply callback, gpointer user_data);
Index: src/libtracker/Makefile.am
===================================================================
--- src/libtracker/Makefile.am (revision 599)
+++ src/libtracker/Makefile.am (working copy)
@@ -14,7 +14,7 @@
include_HEADERS = tracker.h tracker-client.h
-bin_PROGRAMS = tracker-search tracker-query tracker-meta-folder tracker-stats tracker-tag tracker-files
+bin_PROGRAMS = tracker-search tracker-query tracker-meta-folder tracker-stats tracker-tag tracker-files
tracker-busy
tracker_search_SOURCES = tracker-search.c
@@ -44,6 +44,14 @@
$(GOBJECT_LIBS) \
libtrackerclient.la
+tracker_busy_SOURCES = tracker-busy.c
+
+tracker_busy_LDADD = $(GLIB2_LIBS) \
+ $(DBUS_LIBS) \
+ $(GOBJECT_LIBS) \
+ libtrackerclient.la
+
+
tracker_tag_SOURCES = tracker-tag.c
tracker_tag_LDADD = $(GLIB2_LIBS) \
Index: src/libtracker/tracker.c
===================================================================
--- src/libtracker/tracker.c (revision 599)
+++ src/libtracker/tracker.c (working copy)
@@ -181,7 +181,7 @@
g_free (callback_struct);
}
-/*
+
static void
tracker_boolean_reply (DBusGProxy *proxy, gboolean OUT_result, GError *error, gpointer user_data)
{
@@ -194,9 +194,9 @@
g_free (callback_struct);
}
-*/
+
static void
tracker_void_reply (DBusGProxy *proxy, GError *error, gpointer user_data)
{
@@ -324,9 +324,18 @@
return version;
}
+gboolean
+tracker_is_busy (TrackerClient *client, GError **error)
+{
+ gboolean is_busy = FALSE;
+ org_freedesktop_Tracker_is_busy (client->proxy, &is_busy, &*error);
+ return is_busy;
+}
+
+
GHashTable *
tracker_get_services (TrackerClient *client, gboolean main_services_only, GError **error)
{
@@ -818,9 +827,21 @@
}
+void
+tracker_is_busy_async (TrackerClient *client, TrackerBooleanReply callback, gpointer user_data)
+{
+ BooleanCallBackStruct *callback_struct;
+ callback_struct = g_new (BooleanCallBackStruct, 1);
+ callback_struct->callback = callback;
+ callback_struct->data = user_data;
+ client->last_pending_call = org_freedesktop_Tracker_is_busy_async (client->proxy,
tracker_boolean_reply, callback_struct);
+
+}
+
+
void
tracker_get_services_async (TrackerClient *client, gboolean main_services_only, TrackerHashTableReply
callback, gpointer user_data)
{
Index: src/libtracker/tracker-busy.c
===================================================================
--- src/libtracker/tracker-busy.c (revision 0)
+++ src/libtracker/tracker-busy.c (revision 0)
@@ -0,0 +1,73 @@
+/* Tracker - indexer and metadata database engine
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <config.h>
+
+#include <locale.h>
+#include <string.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include "../libtracker/tracker.h"
+
+#define TOTAL_COUNT "Total files indexed"
+
+
+
+
+int
+main (int argc, char **argv)
+{
+
+ GError *error = NULL;
+ TrackerClient *client = NULL;
+
+ setlocale (LC_ALL, "");
+
+ bindtextdomain (GETTEXT_PACKAGE, TRACKER_LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+
+ client = tracker_connect (FALSE);
+
+ if (!client) {
+ g_printerr (_("%s: no connection to tracker daemon"), argv[0]);
+ g_printerr ("\n");
+ g_printerr (_("Ensure \"trackerd\" is running before launch this command."));
+ g_printerr ("\n");
+ return 1;
+ }
+
+ gboolean is_busy = FALSE;
+
+ is_busy = tracker_is_busy(client,&error);
+
+ if (is_busy) {
+ g_print("\ntracker is busy\n");
+ }
+ else {
+ g_print("\ntracker is idle\n");
+ }
+
+ tracker_disconnect (client);
+
+ return 0;
+}
Index: src/libtracker/tracker-client.h
===================================================================
--- src/libtracker/tracker-client.h (revision 599)
+++ src/libtracker/tracker-client.h (working copy)
@@ -52,6 +52,44 @@
inline
#endif
gboolean
+org_freedesktop_Tracker_is_busy (DBusGProxy *proxy, gboolean* OUT_is_busy, GError **error)
+
+{
+ return dbus_g_proxy_call (proxy, "IsBusy", error, G_TYPE_INVALID, G_TYPE_BOOLEAN, OUT_is_busy,
G_TYPE_INVALID);
+}
+
+typedef void (*org_freedesktop_Tracker_is_busy_reply) (DBusGProxy *proxy, gboolean OUT_is_busy, GError
*error, gpointer userdata);
+
+static void
+org_freedesktop_Tracker_is_busy_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+ DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+ GError *error = NULL;
+ gboolean OUT_is_busy;
+ dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_BOOLEAN, &OUT_is_busy, G_TYPE_INVALID);
+ (*(org_freedesktop_Tracker_is_busy_reply)data->cb) (proxy, OUT_is_busy, error, data->userdata);
+ return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+org_freedesktop_Tracker_is_busy_async (DBusGProxy *proxy, org_freedesktop_Tracker_is_busy_reply callback,
gpointer userdata)
+
+{
+ DBusGAsyncData *stuff;
+ stuff = g_new (DBusGAsyncData, 1);
+ stuff->cb = G_CALLBACK (callback);
+ stuff->userdata = userdata;
+ return dbus_g_proxy_begin_call (proxy, "IsBusy", org_freedesktop_Tracker_is_busy_async_callback, stuff,
g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
org_freedesktop_Tracker_get_services (DBusGProxy *proxy, const gboolean IN_main_services_only, GHashTable**
OUT_result, GError **error)
{
Index: data/tracker-introspect.xml
===================================================================
--- data/tracker-introspect.xml (revision 599)
+++ data/tracker-introspect.xml (working copy)
@@ -71,7 +71,12 @@
<arg type="i" name="version" direction="out" />
</method>
+ <!-- Return the busy/idle status of tracker daemon, true means busy, false means idel -->
+ <method name="IsBusy">
+ <arg type="b" name="is_busy" direction="out" />
+ </method>
+
<!-- Gets all implemented services and also returns any corresponding metadata type class for
the service (IE "File", "Doc", "Image" etc)
If main_services_only is set to true then only the major services are returned
Output is in dict format: (service -> metadata class, description) -->
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]