[tracker] libtracker-bus: Call BatchUpdate for low priority requests



commit 05557f44fc1a9dda9ef07a8ad1f165c0f33da90f
Author: Jürg Billeter <j bitron ch>
Date:   Fri Aug 20 11:44:44 2010 +0200

    libtracker-bus: Call BatchUpdate for low priority requests

 src/libtracker-bus/tracker-bus-fd-update.c    |   76 ++++++++++++++++++++++++-
 src/libtracker-bus/tracker-bus-fd-update.h    |   10 +++
 src/libtracker-bus/tracker-bus-fd-update.vapi |    4 +
 src/libtracker-bus/tracker-bus.vala           |   28 ++++++++-
 4 files changed, 113 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus-fd-update.c b/src/libtracker-bus/tracker-bus-fd-update.c
index d9fbfc6..86c5846 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.c
+++ b/src/libtracker-bus/tracker-bus-fd-update.c
@@ -40,7 +40,8 @@
 
 typedef enum {
 	FAST_UPDATE,
-	FAST_UPDATE_BLANK
+	FAST_UPDATE_BLANK,
+	FAST_UPDATE_BATCH
 } FastOperationType;
 
 typedef struct {
@@ -181,6 +182,7 @@ sparql_update_fast_callback (DBusPendingCall *call,
 	/* Call iterator callback */
 	switch (fad->operation_type) {
 	case FAST_UPDATE:
+	case FAST_UPDATE_BATCH:
 		g_simple_async_result_complete (fad->res);
 		break;
 	case FAST_UPDATE_BLANK:
@@ -236,6 +238,9 @@ sparql_update_fast_send (DBusConnection     *connection,
 	case FAST_UPDATE_BLANK:
 		dbus_method = "UpdateBlank";
 		break;
+	case FAST_UPDATE_BATCH:
+		dbus_method = "BatchUpdate";
+		break;
 	default:
 		g_assert_not_reached ();
 	}
@@ -508,3 +513,72 @@ tracker_bus_fd_sparql_update_blank_async (DBusGConnection       *connection,
 #endif /* HAVE_DBUS_FD_PASSING */
 }
 
+void
+tracker_bus_fd_sparql_batch_update (DBusGConnection *connection,
+                                    const char      *query,
+                                    GError         **error)
+{
+#ifdef HAVE_DBUS_FD_PASSING
+	DBusMessage *reply;
+
+	g_return_if_fail (query != NULL);
+
+	reply = sparql_update_fast (dbus_g_connection_get_connection (connection),
+	                            query, FAST_UPDATE_BATCH, error);
+
+	if (!reply) {
+		return;
+	}
+
+	dbus_message_unref (reply);
+#else
+	g_assert_not_reached ();
+#endif /* HAVE_DBUS_FD_PASSING */
+}
+
+void
+tracker_bus_fd_sparql_batch_update_async (DBusGConnection       *connection,
+                                          const char            *query,
+                                          GCancellable          *cancellable,
+                                          GAsyncReadyCallback    callback,
+                                          gpointer               user_data)
+{
+#ifdef HAVE_DBUS_FD_PASSING
+	FastAsyncData *fad;
+	GError *error = NULL;
+
+	g_return_if_fail (query != NULL);
+
+	fad = fast_async_data_new (dbus_g_connection_get_connection (connection),
+	                           FAST_UPDATE_BATCH, cancellable, user_data);
+
+	fad->res = g_simple_async_result_new (NULL, callback, user_data,
+	                                      tracker_bus_fd_sparql_batch_update_async);
+
+	sparql_update_fast_async (dbus_g_connection_get_connection (connection),
+	                          query, fad, &error);
+
+	if (error) {
+		g_critical ("Could not initiate update: %s", error->message);
+		g_error_free (error);
+		g_object_unref (fad->res);
+		fast_async_data_free (fad);
+	}
+
+#else
+	g_assert_not_reached ();
+#endif /* HAVE_DBUS_FD_PASSING */
+}
+
+void
+tracker_bus_fd_sparql_batch_update_finish (GAsyncResult     *res,
+                                           GError          **error)
+{
+#ifdef HAVE_DBUS_FD_PASSING
+	g_return_if_fail (res != NULL);
+
+	g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
+#else /* HAVE_DBUS_FD_PASSING */
+	g_assert_not_reached ();
+#endif /* HAVE_DBUS_FD_PASSING */
+}
diff --git a/src/libtracker-bus/tracker-bus-fd-update.h b/src/libtracker-bus/tracker-bus-fd-update.h
index 7ea91b8..b844a13 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.h
+++ b/src/libtracker-bus/tracker-bus-fd-update.h
@@ -39,9 +39,19 @@ void        tracker_bus_fd_sparql_update_blank_async     (DBusGConnection
                                                           GCancellable          *cancellable,
                                                           GAsyncReadyCallback    callback,
                                                           gpointer               user_data);
+void        tracker_bus_fd_sparql_batch_update           (DBusGConnection       *connection,
+                                                          const char            *query,
+                                                          GError               **error);
+void        tracker_bus_fd_sparql_batch_update_async     (DBusGConnection       *connection,
+                                                          const char            *query,
+                                                          GCancellable          *cancellable,
+                                                          GAsyncReadyCallback    callback,
+                                                          gpointer               user_data);
 void        tracker_bus_fd_sparql_update_finish          (GAsyncResult          *res,
                                                           GError               **error);
 GVariant *  tracker_bus_fd_sparql_update_blank_finish    (GAsyncResult          *res,
                                                           GError               **error);
+void        tracker_bus_fd_sparql_batch_update_finish    (GAsyncResult          *res,
+                                                          GError               **error);
 
 G_END_DECLS
diff --git a/src/libtracker-bus/tracker-bus-fd-update.vapi b/src/libtracker-bus/tracker-bus-fd-update.vapi
index 26df9e2..a94ed3d 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.vapi
+++ b/src/libtracker-bus/tracker-bus-fd-update.vapi
@@ -22,6 +22,10 @@ public void tracker_bus_fd_sparql_update (DBus.Connection connection, string que
 [CCode (cheader_filename = "tracker-bus-fd-update.h")]
 public extern GLib.Variant tracker_bus_fd_sparql_update_blank (DBus.Connection connection, string query) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
 [CCode (cheader_filename = "tracker-bus-fd-update.h")]
+public void tracker_bus_fd_sparql_batch_update (DBus.Connection connection, string query) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
+[CCode (cheader_filename = "tracker-bus-fd-update.h")]
 public extern async void tracker_bus_fd_sparql_update_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
 [CCode (cheader_filename = "tracker-bus-fd-update.h")]
 public extern async GLib.Variant tracker_bus_fd_sparql_update_blank_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
+[CCode (cheader_filename = "tracker-bus-fd-update.h")]
+public extern async void tracker_bus_fd_sparql_batch_update_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 9ed11a6..3f8c402 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -27,6 +27,10 @@ private interface Tracker.Bus.Resources : GLib.Object {
 	[DBus (name = "SparqlUpdate")]
 	public abstract async void sparql_update_async (string query) throws Sparql.Error, DBus.Error;
 
+	public abstract void batch_sparql_update (string query) throws Sparql.Error, DBus.Error;
+	[DBus (name = "BatchSparqlUpdate")]
+	public abstract async void batch_sparql_update_async (string query) throws Sparql.Error, DBus.Error;
+
 	public abstract void load (string uri) throws Sparql.Error, DBus.Error;
 	[DBus (name = "Load")]
 	public abstract async void load_async (string uri) throws Sparql.Error, DBus.Error;
@@ -115,9 +119,17 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 	public override void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
 			if (use_steroids) {
-				tracker_bus_fd_sparql_update (connection, sparql);
+				if (priority >= GLib.Priority.DEFAULT) {
+					tracker_bus_fd_sparql_update (connection, sparql);
+				} else {
+					tracker_bus_fd_sparql_batch_update (connection, sparql);
+				}
 			} else {
-				resources_object.sparql_update (sparql);
+				if (priority >= GLib.Priority.DEFAULT) {
+					resources_object.sparql_update (sparql);
+				} else {
+					resources_object.batch_sparql_update (sparql);
+				}
 			}
 		} catch (DBus.Error e) {
 			throw new Sparql.Error.INTERNAL (e.message);
@@ -127,9 +139,17 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 	public async override void update_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
 			if (use_steroids) {
-				yield tracker_bus_fd_sparql_update_async (connection, sparql, cancellable);
+				if (priority >= GLib.Priority.DEFAULT) {
+					yield tracker_bus_fd_sparql_update_async (connection, sparql, cancellable);
+				} else {
+					yield tracker_bus_fd_sparql_batch_update_async (connection, sparql, cancellable);
+				}
 			} else {
-				yield resources_object.sparql_update_async (sparql);
+				if (priority >= GLib.Priority.DEFAULT) {
+					yield resources_object.sparql_update_async (sparql);
+				} else {
+					yield resources_object.batch_sparql_update_async (sparql);
+				}
 			}
 		} catch (DBus.Error e) {
 			throw new Sparql.Error.INTERNAL (e.message);



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