Re: [Tracker] add one feature to query tracker daemon's busy/idle status



jamie 写道:
On Mon, 2007-07-02 at 22:00 +0800, jerry tan wrote:
  
so when tracker->file_process_queue is not empty, and pending table is
not empty,
track daemon is busy, right?
    

almost but not quite cause it could still be in the process of indexing
the last file

see the tracker->status variable as I suggest



  
en, use tracker->status is more simple .

Index: src/trackerd/trackerd.c
===================================================================
--- src/trackerd/trackerd.c     (revision 625)
+++ src/trackerd/trackerd.c     (working copy)
@@ -1431,7 +1431,18 @@
 
                                break;
 
+                        case DBUS_ACTION_IS_BUSY:
 
+                                reply = dbus_message_new_method_return (rec->message);
+                                gboolean is_busy = FALSE;
+                                if (tracker->status != STATUS_IDLE)
+                                   is_busy = TRUE;
+                                dbus_message_append_args (reply,
+                                                          DBUS_TYPE_BOOLEAN, &is_busy,
+                                                          DBUS_TYPE_INVALID);
+                                dbus_connection_send (rec->connection, reply, NULL);
+                                dbus_message_unref (reply);
+                                break;
 
                        case DBUS_ACTION_METADATA_GET:
 
Index: src/trackerd/tracker-dbus.c
===================================================================
--- src/trackerd/tracker-dbus.c (revision 625)
+++ 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 625)
+++ 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 625)
+++ 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 625)
+++ 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 625)
+++ 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-client.h
===================================================================
--- src/libtracker/tracker-client.h     (revision 625)
+++ 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 625)
+++ 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]