[tracker/direct-wait: 2/6] tracker-store: Add Status.Wait method



commit 665a57eb3c3f6334f3d437df36ca46f61b928155
Author: Jürg Billeter <j bitron ch>
Date:   Mon Aug 23 17:27:29 2010 +0200

    tracker-store: Add Status.Wait method

 data/dbus/tracker-status.xml       |    3 +++
 src/tracker-store/tracker-status.c |   30 ++++++++++++++++++++++++++++++
 src/tracker-store/tracker-status.h |    3 +++
 3 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/data/dbus/tracker-status.xml b/data/dbus/tracker-status.xml
index ffc0bad..e309939 100644
--- a/data/dbus/tracker-status.xml
+++ b/data/dbus/tracker-status.xml
@@ -11,6 +11,9 @@
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="d" name="progress" direction="out" />
     </method>
+    <method name="Wait">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+    </method>
 
     <!-- Signals -->
     <signal name="Progress">
diff --git a/src/tracker-store/tracker-status.c b/src/tracker-store/tracker-status.c
index a8c07f7..177546d 100644
--- a/src/tracker-store/tracker-status.c
+++ b/src/tracker-store/tracker-status.c
@@ -39,6 +39,7 @@ typedef struct {
 	gchar *status;
 	guint timer_id;
 	TrackerStatus *object;
+	GList *wait_list;
 } TrackerStatusPrivate;
 
 enum {
@@ -137,6 +138,20 @@ tracker_status_callback (const gchar *status,
 
 	priv->progress = progress;
 
+	if (progress == 1 && priv->wait_list) {
+		GList *l;
+
+		/* notify clients that tracker-store is no longer busy */
+
+		priv->wait_list = g_list_reverse (priv->wait_list);
+		for (l = priv->wait_list; l; l = l->next) {
+			dbus_g_method_return (l->data);
+		}
+
+		g_list_free (priv->wait_list);
+		priv->wait_list = NULL;
+	}
+
 	if (g_strcmp0 (status, priv->status) != 0) {
 		g_free (priv->status);
 		priv->status = g_strdup (status);
@@ -196,3 +211,18 @@ tracker_status_get_status  (TrackerStatus    *object,
 
 	return;
 }
+
+void
+tracker_status_wait  (TrackerStatus          *object,
+                      DBusGMethodInvocation  *context,
+                      GError                **error)
+{
+	TrackerStatusPrivate *priv = TRACKER_STATUS_GET_PRIVATE (object);
+
+	if (priv->progress == 1) {
+		/* tracker-store is idle */
+		dbus_g_method_return (context);
+	} else {
+		priv->wait_list = g_list_prepend (priv->wait_list, context);
+	}
+}
diff --git a/src/tracker-store/tracker-status.h b/src/tracker-store/tracker-status.h
index 3c53199..7a96b08 100644
--- a/src/tracker-store/tracker-status.h
+++ b/src/tracker-store/tracker-status.h
@@ -67,6 +67,9 @@ void                  tracker_status_get_progress  (TrackerStatus          *obje
 void                  tracker_status_get_status    (TrackerStatus          *object,
                                                     DBusGMethodInvocation  *context,
                                                     GError                **error);
+void                  tracker_status_wait          (TrackerStatus          *object,
+                                                    DBusGMethodInvocation  *context,
+                                                    GError                **error);
 
 
 G_END_DECLS



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]