[tracker/gdbus-evolution: 4/28] libtracker-sparql: Port from libdbus/dbus-glib to GDBus



commit f8a0d999e4326fe41a54c3dc6360f6831e88979e
Author: Jürg Billeter <j bitron ch>
Date:   Tue Oct 19 16:04:48 2010 +0200

    libtracker-sparql: Port from libdbus/dbus-glib to GDBus
    
    Fixes NB#199968.

 src/libtracker-bus/.gitignore                 |    1 +
 src/libtracker-bus/Makefile.am                |   24 +-
 src/libtracker-bus/tracker-bus-fd-cursor.c    |  417 ------------
 src/libtracker-bus/tracker-bus-fd-cursor.h    |   45 --
 src/libtracker-bus/tracker-bus-fd-cursor.vala |  121 ++++
 src/libtracker-bus/tracker-bus-fd-cursor.vapi |   21 -
 src/libtracker-bus/tracker-bus-fd-update.c    |  877 -------------------------
 src/libtracker-bus/tracker-bus-fd-update.h    |   74 ---
 src/libtracker-bus/tracker-bus-fd-update.vapi |   35 -
 src/libtracker-bus/tracker-bus-shared.c       |   83 ---
 src/libtracker-bus/tracker-bus-shared.h       |   29 -
 src/libtracker-bus/tracker-bus.vala           |  310 +++++++--
 src/libtracker-common/tracker-dbus.h          |    2 +
 src/libtracker-direct/Makefile.am             |    6 +-
 src/libtracker-sparql/Makefile.am             |    5 +-
 src/libtracker-sparql/tracker-backend.vala    |   30 +-
 src/libtracker-sparql/tracker-connection.vala |    4 +-
 17 files changed, 391 insertions(+), 1693 deletions(-)
---
diff --git a/src/libtracker-bus/.gitignore b/src/libtracker-bus/.gitignore
index c326b36..f5dec99 100644
--- a/src/libtracker-bus/.gitignore
+++ b/src/libtracker-bus/.gitignore
@@ -1,3 +1,4 @@
 tracker-bus.[ch]
 tracker-bus*.vapi
 tracker-array-cursor.c
+tracker-bus-fd-cursor.c
diff --git a/src/libtracker-bus/Makefile.am b/src/libtracker-bus/Makefile.am
index fcb2282..9920da9 100644
--- a/src/libtracker-bus/Makefile.am
+++ b/src/libtracker-bus/Makefile.am
@@ -5,12 +5,12 @@ modulesdir = $(libdir)/tracker-$(TRACKER_API_VERSION)/sparql-modules
 INCLUDES =								\
 	-DG_LOG_DOMAIN=\"Tracker\"					\
 	-DTRACKER_COMPILATION						\
+	-DNO_LIBDBUS							\
 	-I$(top_srcdir)/src						\
 	-I$(top_srcdir)/src/libtracker-sparql				\
 	-I$(top_builddir)/src						\
 	-I$(top_builddir)/src/libtracker-sparql				\
 	$(WARN_CFLAGS)							\
-	$(DBUS_CFLAGS)							\
 	$(GLIB2_CFLAGS)							\
 	$(GCOV_CFLAGS)							\
 	$(GIO_CFLAGS)
@@ -19,17 +19,12 @@ modules_LTLIBRARIES = libtracker-bus.la
 
 libtracker_bus_la_VALASOURCES = 		\
 	tracker-bus.vala			\
-	tracker-array-cursor.vala
+	tracker-array-cursor.vala		\
+	tracker-bus-fd-cursor.vala
 
 libtracker_bus_la_SOURCES = 	\
 	libtracker-bus.vala.stamp			\
-	$(libtracker_bus_la_VALASOURCES:.vala=.c)	\
-	tracker-bus-fd-cursor.h				\
-	tracker-bus-fd-cursor.c				\
-	tracker-bus-fd-update.c				\
-	tracker-bus-fd-update.h				\
-	tracker-bus-shared.c				\
-	tracker-bus-shared.h
+	$(libtracker_bus_la_VALASOURCES:.vala=.c)
 
 libtracker_bus_la_LDFLAGS = 	\
 	-module -avoid-version -no-undefined
@@ -40,12 +35,10 @@ noinst_HEADERS = 			\
 # Vala sources
 vapi_sources =						\
 	$(top_builddir)/src/libtracker-sparql/tracker-sparql-$(TRACKER_API_VERSION).vapi 	\
-	$(top_srcdir)/src/libtracker-common/libtracker-common.vapi 				\
-	tracker-bus-fd-cursor.vapi 			\
-	tracker-bus-fd-update.vapi
+	$(top_srcdir)/src/libtracker-common/libtracker-common.vapi
 
 libtracker-bus.vala.stamp: $(libtracker_bus_la_VALASOURCES) $(vapi_sources)
-	$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 -H tracker-bus.h --vapi tracker-bus.vapi $^
+	$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg gio-unix-2.0 --pkg posix -H tracker-bus.h --vapi tracker-bus.vapi $^
 	$(AM_V_GEN)touch $@
 
 BUILT_SOURCES = libtracker-bus.vala.stamp
@@ -54,7 +47,6 @@ libtracker_bus_la_LIBADD = 						\
 	$(top_builddir)/src/libtracker-sparql/libtracker-sparql-$(TRACKER_API_VERSION).la 	\
 	$(top_builddir)/src/libtracker-common/libtracker-common.la 	\
 	$(GLIB2_LIBS) \
-	$(DBUS_LIBS) \
 	$(GCOV_LIBS) \
 	$(GIO_LIBS)
 
@@ -67,7 +59,5 @@ MAINTAINERCLEANFILES =					\
 EXTRA_DIST = 						\
 	$(libtracker_bus_la_VALASOURCES) \
 	libtracker-bus.vala.stamp \
-	tracker-bus.vapi \
-	tracker-bus-fd-cursor.vapi \
-	tracker-bus-fd-update.vapi
+	tracker-bus.vapi
 
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.vala b/src/libtracker-bus/tracker-bus-fd-cursor.vala
new file mode 100644
index 0000000..7294aa3
--- /dev/null
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.vala
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+class Tracker.Bus.FDCursor : Tracker.Sparql.Cursor {
+	internal char* buffer;
+	internal ulong buffer_index;
+	internal ulong buffer_size;
+
+	internal int _n_columns;
+	internal int* offsets;
+	internal int* types;
+	internal char* data;
+	internal string[] variable_names;
+
+	public FDCursor (char* buffer, ulong buffer_size, string[] variable_names) {
+		this.buffer = buffer;
+		this.buffer_size = buffer_size;
+		this.variable_names = variable_names;
+		_n_columns = variable_names.length;
+	}
+
+	~FDCursor () {
+		free (buffer);
+	}
+
+	inline int buffer_read_int () {
+		int v = *((int*) (buffer + buffer_index));
+
+		buffer_index += 4;
+
+		return v;
+	}
+
+	public override int n_columns {
+		get { return _n_columns; }
+	}
+
+	public override Sparql.ValueType get_value_type (int column)
+	requires (types != null) {
+		/* Cast from int to enum */
+		return (Sparql.ValueType) types[column];
+	}
+
+	public override unowned string? get_variable_name (int column)
+	requires (variable_names != null) {
+		return variable_names[column];
+	}
+
+	public override unowned string? get_string (int column, out long length = null)
+	requires (column < n_columns && data != null) {
+		unowned string str = null;
+
+		if (column == 0) {
+			str = (string) data;
+		} else {
+			str = (string) (data + offsets[column - 1] + 1);
+		}
+
+		length = str.length;
+
+		return str;
+	}
+
+	public override bool next (Cancellable? cancellable = null) throws GLib.Error {
+		int last_offset;
+
+		if (buffer_index >= buffer_size) {
+			return false;
+		}
+
+		/* So, the make up on each cursor segment is:
+		 *
+		 * iteration = [4 bytes for number of columns,
+		 *              columns x 4 bytes for types
+		 *              columns x 4 bytes for offsets]
+		 */
+
+		_n_columns = buffer_read_int ();
+
+		/* Storage of ints that will be cast to TrackerSparqlValueType enums,
+		 * also see get_value_type */
+		types = (int*) (buffer + buffer_index);
+		buffer_index += sizeof (int) * n_columns;
+
+		offsets = (int*) (buffer + buffer_index);
+		buffer_index += sizeof (int) * (n_columns - 1);
+		last_offset = buffer_read_int ();
+
+		data = buffer + buffer_index;
+
+		buffer_index += last_offset + 1;
+
+		return true;
+	}
+
+	public override async bool next_async (Cancellable? cancellable = null) throws GLib.Error {
+		// next never blocks
+		return next (cancellable);
+	}
+
+	public override void rewind () {
+		buffer_index = 0;
+		data = buffer;
+	}
+}
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 6008134..715bd75 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -17,26 +17,54 @@
  * Boston, MA  02110-1301, USA.
  */
 
-[DBus (name = "org.freedesktop.Tracker1.Resources", timeout = 2147483647 /* INT_MAX */)]
-private interface Tracker.Bus.Resources : GLib.Object {
-	public abstract void load (string uri) throws Sparql.Error, DBus.Error;
+[DBus (name = "org.freedesktop.Tracker1.Resources")]
+private interface Tracker.Bus.Resources : DBusProxy {
+	public abstract void load (string uri, Cancellable? cancellable) throws Sparql.Error, DBusError;
 	[DBus (name = "Load")]
-	public abstract async void load_async (string uri) throws Sparql.Error, DBus.Error;
+	public abstract async void load_async (string uri, Cancellable? cancellable) throws Sparql.Error, DBusError;
 }
 
-[DBus (name = "org.freedesktop.Tracker1.Statistics")]
-private interface Tracker.Bus.Statistics : GLib.Object {
-	public abstract string[,] Get () throws DBus.Error;
-	public async abstract string[,] Get_async () throws DBus.Error;
+[DBus (name = "org.freedesktop.Tracker1.Steroids")]
+private interface Tracker.Bus.Steroids : DBusProxy {
+	public abstract async string[] query (string query, UnixOutputStream result_stream, Cancellable? cancellable) throws Sparql.Error, DBusError;
+	public abstract async void update (UnixInputStream sparql_stream, Cancellable? cancellable) throws Sparql.Error, DBusError;
+	[DBus (signature = "aaa{ss}")]
+	public abstract async Variant update_blank (UnixInputStream sparql_stream, Cancellable? cancellable) throws Sparql.Error, DBusError;
+	public abstract async void batch_update (UnixInputStream sparql_stream, Cancellable? cancellable) throws Sparql.Error, DBusError;
+	[DBus (signature = "as")]
+	public abstract async Variant update_array (UnixInputStream sparql_stream, Cancellable? cancellable) throws Sparql.Error, DBusError;
+	[DBus (signature = "as")]
+	public abstract async Variant batch_update_array (UnixInputStream sparql_stream, Cancellable? cancellable) throws Sparql.Error, DBusError;
+
+	[DBus (visible = false)]
+	public void update_begin (UnixInputStream sparql_stream, int priority, Cancellable? cancellable, AsyncReadyCallback callback) {
+		if (priority >= GLib.Priority.DEFAULT) {
+			update.begin (sparql_stream, cancellable, callback);
+		} else {
+			batch_update.begin (sparql_stream, cancellable, callback);
+		}
+	}
+
+	[DBus (visible = false)]
+	public void update_array_begin (UnixInputStream sparql_stream, int priority, Cancellable? cancellable, AsyncReadyCallback callback) {
+		if (priority >= GLib.Priority.DEFAULT) {
+			update_array.begin (sparql_stream, cancellable, callback);
+		} else {
+			batch_update_array.begin (sparql_stream, cancellable, callback);
+		}
+	}
 }
 
-// Imported DBus FD API until we have support with Vala
-public extern Tracker.Sparql.Cursor tracker_bus_fd_query (DBus.Connection connection, string query, Cancellable? cancellable) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
+[DBus (name = "org.freedesktop.Tracker1.Statistics")]
+private interface Tracker.Bus.Statistics : DBusProxy {
+	public abstract string[,] Get (Cancellable? cancellable) throws DBusError;
+	public async abstract string[,] Get_async (Cancellable? cancellable) throws DBusError;
+}
 
 // Actual class definition
 public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
-	static DBus.Connection connection;
 	static Resources resources_object;
+	static Steroids steroids_object;
 	static Statistics statistics_object;
 	static bool initialized;
 
@@ -45,16 +73,17 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		initialized = true;
 		
 		try {
-			connection = DBus.Bus.get (DBus.BusType.SESSION);
-
 			// FIXME: Ideally we would just get these as and when we need them
-			resources_object = (Resources) connection.get_object (TRACKER_DBUS_SERVICE,
-			                                                      TRACKER_DBUS_OBJECT_RESOURCES,
-			                                                      TRACKER_DBUS_INTERFACE_RESOURCES);
-			statistics_object = (Statistics) connection.get_object (TRACKER_DBUS_SERVICE,
-			                                                        TRACKER_DBUS_OBJECT_STATISTICS,
-			                                                        TRACKER_DBUS_INTERFACE_STATISTICS);
-		} catch (DBus.Error e) {
+			resources_object = GLib.Bus.get_proxy_sync (BusType.SESSION,
+			                                            TRACKER_DBUS_SERVICE,
+			                                            TRACKER_DBUS_OBJECT_RESOURCES);
+			steroids_object = GLib.Bus.get_proxy_sync (BusType.SESSION,
+			                                           TRACKER_DBUS_SERVICE,
+			                                           TRACKER_DBUS_OBJECT_STEROIDS);
+			statistics_object = GLib.Bus.get_proxy_sync (BusType.SESSION,
+			                                             TRACKER_DBUS_SERVICE,
+			                                             TRACKER_DBUS_OBJECT_STATISTICS);
+		} catch (DBusError e) {
 			warning ("Could not connect to D-Bus service:'%s': %s", TRACKER_DBUS_INTERFACE_RESOURCES, e.message);
 			initialized = false;
 			return;
@@ -67,114 +96,255 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		initialized = false;
 	}
 
-	public override Sparql.Cursor query (string sparql, Cancellable? cancellable) throws Sparql.Error, IOError {
-		try {
-			return tracker_bus_fd_query (connection, sparql, cancellable);
-		} catch (DBus.Error e) {
-			throw new Sparql.Error.INTERNAL (e.message);
+	void pipe (out UnixInputStream input, out UnixOutputStream output) throws IOError {
+		int pipefd[2];
+		if (Posix.pipe (pipefd) < 0) {
+			throw new IOError.FAILED ("Pipe creation failed");
 		}
+		input = new UnixInputStream (pipefd[0], true);
+		output = new UnixOutputStream (pipefd[1], true);
+	}
+
+	public override Sparql.Cursor query (string sparql, Cancellable? cancellable) throws Sparql.Error, IOError {
+		// use separate main context for sync operation
+		var context = new MainContext ();
+		var loop = new MainLoop (context, false);
+		context.push_thread_default ();
+		AsyncResult async_res = null;
+		query_async.begin (sparql, cancellable, (o, res) => {
+			async_res = res;
+			loop.quit ();
+		});
+		loop.run ();
+		context.pop_thread_default ();
+		return query_async.end (async_res);
 	}
 
 	public async override Sparql.Cursor query_async (string sparql, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
-			return yield tracker_bus_fd_query_async (connection, sparql, cancellable);
-		} catch (DBus.Error e) {
+			UnixInputStream input;
+			UnixOutputStream output;
+			pipe (out input, out output);
+
+			// send D-Bus request
+			AsyncResult dbus_res = null;
+			bool received_result = false;
+			steroids_object.query.begin (sparql, output, cancellable, (o, res) => {
+				dbus_res = res;
+				if (received_result) {
+					query_async.callback ();
+				}
+			});
+
+			output = null;
+
+			// receive query results via FD
+			var mem_stream = new MemoryOutputStream (null, 0, GLib.realloc, GLib.free);
+			yield mem_stream.splice_async (input, OutputStreamSpliceFlags.CLOSE_SOURCE | OutputStreamSpliceFlags.CLOSE_TARGET, Priority.DEFAULT, cancellable);
+
+			// wait for D-Bus reply
+			received_result = true;
+			if (dbus_res == null) {
+				yield;
+			}
+			string[] variable_names = steroids_object.query.end (dbus_res);
+			mem_stream.close ();
+			return new FDCursor (mem_stream.steal_data (), mem_stream.data_size, variable_names);
+		} catch (DBusError e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
 	}
 
 	public override void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
-		try {
-			if (priority >= GLib.Priority.DEFAULT) {
-				tracker_bus_fd_sparql_update (connection, sparql);
-			} else {
-				tracker_bus_fd_sparql_batch_update (connection, sparql);
-			}
-		} catch (DBus.Error e) {
-			throw new Sparql.Error.INTERNAL (e.message);
-		}
+		// use separate main context for sync operation
+		var context = new MainContext ();
+		var loop = new MainLoop (context, false);
+		context.push_thread_default ();
+		AsyncResult async_res = null;
+		update_async.begin (sparql, priority, cancellable, (o, res) => {
+			async_res = res;
+			loop.quit ();
+		});
+		loop.run ();
+		context.pop_thread_default ();
+		update_async.end (async_res);
 	}
 
 	public async override void update_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
+			UnixInputStream input;
+			UnixOutputStream output;
+			pipe (out input, out output);
+
+			// send D-Bus request
+			AsyncResult dbus_res = null;
+			bool sent_update = false;
+			steroids_object.update_begin (input, priority, cancellable, (o, res) => {
+				dbus_res = res;
+				if (sent_update) {
+					update_async.callback ();
+				}
+			});
+
+			// send sparql string via fd
+			var data_stream = new DataOutputStream (output);
+			data_stream.set_byte_order (DataStreamByteOrder.HOST_ENDIAN);
+			data_stream.put_int32 ((int32) sparql.length);
+			data_stream.put_string (sparql);
+			data_stream = null;
+
+			// wait for D-Bus reply
+			sent_update = true;
+			if (dbus_res == null) {
+				yield;
+			}
+
 			if (priority >= GLib.Priority.DEFAULT) {
-				yield tracker_bus_fd_sparql_update_async (connection, sparql, cancellable);
+				steroids_object.update.end (dbus_res);
 			} else {
-				yield tracker_bus_fd_sparql_batch_update_async (connection, sparql, cancellable);
+				steroids_object.batch_update.end (dbus_res);
 			}
-		} catch (DBus.Error e) {
+		} catch (DBusError e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
 	}
 
-	public async override GLib.PtrArray? update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
+	public async override GenericArray<Error?> update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
-			// helper variable necessary to work around bug in vala < 0.11
-			PtrArray result;
+			UnixInputStream input;
+			UnixOutputStream output;
+			pipe (out input, out output);
+
+			// send D-Bus request
+			AsyncResult dbus_res = null;
+			bool sent_update = false;
+			steroids_object.update_array_begin (input, priority, cancellable, (o, res) => {
+				dbus_res = res;
+				if (sent_update) {
+					update_array_async.callback ();
+				}
+			});
+
+			// send sparql strings via fd
+			var data_stream = new DataOutputStream (output);
+			data_stream.set_byte_order (DataStreamByteOrder.HOST_ENDIAN);
+			data_stream.put_int32 ((int32) sparql.length);
+			for (int i = 0; i < sparql.length; i++) {
+				data_stream.put_int32 ((int32) sparql[i].length);
+				data_stream.put_string (sparql[i]);
+			}
+			data_stream = null;
+
+			// wait for D-Bus reply
+			sent_update = true;
+			if (dbus_res == null) {
+				yield;
+			}
+
+			// process results (errors)
+			var result = new GenericArray<Error?> ();
+			Variant resultv;
 			if (priority >= GLib.Priority.DEFAULT) {
-				result = yield tracker_bus_fd_sparql_update_array_async (connection, sparql, cancellable);
+				resultv = steroids_object.update_array.end (dbus_res);
 			} else {
-				result = yield tracker_bus_fd_sparql_batch_update_array_async (connection, sparql, cancellable);
+				resultv = steroids_object.batch_update_array.end (dbus_res);
+			}
+			var iter = resultv.iterator ();
+			string code, message;
+			while (iter.next ("s", out code)) {
+				if (iter.next ("s", out message)) {
+					if (code != "" && message != "") {
+						result.add (new Sparql.Error.INTERNAL (message));
+					} else {
+						result.add (null);
+					}
+				}
 			}
 			return result;
-		} catch (DBus.Error e) {
+		} catch (DBusError e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
 	}
 
 	public override GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
-		try {
-			GLib.Variant res = null;
-			res = tracker_bus_fd_sparql_update_blank (connection, sparql);
-			return res;
-		} catch (DBus.Error e) {
-			throw new Sparql.Error.INTERNAL (e.message);
-		}
+		// use separate main context for sync operation
+		var context = new MainContext ();
+		var loop = new MainLoop (context, false);
+		context.push_thread_default ();
+		AsyncResult async_res = null;
+		update_blank_async.begin (sparql, priority, cancellable, (o, res) => {
+			async_res = res;
+			loop.quit ();
+		});
+		loop.run ();
+		context.pop_thread_default ();
+		return update_blank_async.end (async_res);
 	}
 
 	public async override GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
-			GLib.Variant res = null;
-			res = yield tracker_bus_fd_sparql_update_blank_async (connection, sparql, cancellable);
-			return res;
-		} catch (DBus.Error e) {
+			UnixInputStream input;
+			UnixOutputStream output;
+			pipe (out input, out output);
+
+			// send D-Bus request
+			AsyncResult dbus_res = null;
+			bool sent_update = false;
+			steroids_object.update_blank.begin (input, cancellable, (o, res) => {
+				dbus_res = res;
+				if (sent_update) {
+					update_blank_async.callback ();
+				}
+			});
+
+			// send sparql strings via fd
+			var data_stream = new DataOutputStream (output);
+			data_stream.set_byte_order (DataStreamByteOrder.HOST_ENDIAN);
+			data_stream.put_int32 ((int32) sparql.length);
+			data_stream.put_string (sparql);
+			data_stream = null;
+
+			// wait for D-Bus reply
+			sent_update = true;
+			if (dbus_res == null) {
+				yield;
+			}
+
+			return steroids_object.update_blank.end (dbus_res);
+		} catch (DBusError e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
 	}
 
 	public override void load (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
-			resources_object.load (file.get_uri ());
+			resources_object.load (file.get_uri (), cancellable);
 
 			if (cancellable != null && cancellable.is_cancelled ()) {
 				throw new IOError.CANCELLED ("Operation was cancelled");
 			}
-		} catch (DBus.Error e) {
+		} catch (DBusError e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
 	}
 	public async override void load_async (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
-			yield resources_object.load_async (file.get_uri ());
+			yield resources_object.load_async (file.get_uri (), cancellable);
 
 			if (cancellable != null && cancellable.is_cancelled ()) {
 				throw new IOError.CANCELLED ("Operation was cancelled");
 			}
-		} catch (DBus.Error e) {
+		} catch (DBusError e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
 	}
 
 	public override Sparql.Cursor? statistics (Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
-			string[,] results = statistics_object.Get ();
+			string[,] results = statistics_object.Get (cancellable);
 			Sparql.ValueType[] types = new Sparql.ValueType[2];
 			string[] var_names = new string[2];
 
-			if (cancellable != null && cancellable.is_cancelled ()) {
-				throw new IOError.CANCELLED ("Operation was cancelled");
-			}
-
 			var_names[0] = "class";
 			var_names[1] = "count";
 			types[0] = Sparql.ValueType.STRING;
@@ -185,21 +355,17 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 			                                    results.length[1],
 			                                    var_names,
 			                                    types);
-		} catch (DBus.Error e) {
+		} catch (DBusError e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
 	}
 
 	public async override Sparql.Cursor? statistics_async (Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
-			string[,] results = yield statistics_object.Get_async ();
+			string[,] results = yield statistics_object.Get_async (cancellable);
 			Sparql.ValueType[] types = new Sparql.ValueType[2];
 			string[] var_names = new string[2];
 
-			if (cancellable != null && cancellable.is_cancelled ()) {
-				throw new IOError.CANCELLED ("Operation was cancelled");
-			}
-
 			var_names[0] = "class";
 			var_names[1] = "count";
 			types[0] = Sparql.ValueType.STRING;
@@ -210,7 +376,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 			                                    results.length[1],
 			                                    var_names,
 			                                    types);
-		} catch (DBus.Error e) {
+		} catch (DBusError e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
 	}
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index 7890b03..3053df3 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -179,6 +179,7 @@ void             tracker_dbus_request_unblock_hooks  (void);
 
 void             tracker_dbus_enable_client_lookup   (gboolean                    enable);
 
+#ifndef NO_LIBDBUS
 /* File descriptor convenience API */
 gboolean         tracker_dbus_send_and_splice        (DBusConnection             *connection,
                                                       DBusMessage                *message,
@@ -196,6 +197,7 @@ gboolean         tracker_dbus_send_and_splice_async  (DBusConnection
                                                       GCancellable               *cancellable,
                                                       TrackerDBusSendAndSpliceCallback callback,
                                                       gpointer                    user_data);
+#endif
 
 G_END_DECLS
 
diff --git a/src/libtracker-direct/Makefile.am b/src/libtracker-direct/Makefile.am
index 148a81e..cabf419 100644
--- a/src/libtracker-direct/Makefile.am
+++ b/src/libtracker-direct/Makefile.am
@@ -10,8 +10,8 @@ INCLUDES =								\
 	-I$(top_srcdir)/src/libtracker-data				\
 	-I$(top_builddir)/src						\
 	$(WARN_CFLAGS)							\
-	$(DBUS_CFLAGS)							\
 	$(GLIB2_CFLAGS)							\
+	$(GIO_CFLAGS)							\
 	$(GCOV_CFLAGS)
 
 modules_LTLIBRARIES = libtracker-direct.la
@@ -37,7 +37,7 @@ vapi_sources =						\
 	$(top_srcdir)/src/libtracker-data/tracker-sparql-query.vapi
 
 libtracker-direct.vala.stamp: $(libtracker_direct_la_VALASOURCES) $(vapi_sources)
-	$(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 -H tracker-direct.h --vapi tracker-direct.vapi $^
+	$(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 -H tracker-direct.h --vapi tracker-direct.vapi $^
 	$(AM_V_GEN)touch $@
 
 BUILT_SOURCES = libtracker-direct.vala.stamp
@@ -45,7 +45,7 @@ BUILT_SOURCES = libtracker-direct.vala.stamp
 libtracker_direct_la_LIBADD = 						\
 	$(top_builddir)/src/libtracker-data/libtracker-data.la	\
 	$(GLIB2_LIBS)						\
-	$(DBUS_LIBS) \
+	$(GIO_LIBS)						\
 	$(GCOV_LIBS)
 
 MAINTAINERCLEANFILES =					\
diff --git a/src/libtracker-sparql/Makefile.am b/src/libtracker-sparql/Makefile.am
index 7d872a0..88fd19b 100644
--- a/src/libtracker-sparql/Makefile.am
+++ b/src/libtracker-sparql/Makefile.am
@@ -9,8 +9,8 @@ INCLUDES =								\
 	-I$(top_srcdir)/src						\
 	-I$(top_builddir)/src						\
 	$(WARN_CFLAGS)							\
-	$(DBUS_CFLAGS)							\
 	$(GLIB2_CFLAGS)							\
+	$(GIO_CFLAGS)							\
 	$(GCOV_CFLAGS)
 
 lib_LTLIBRARIES = libtracker-sparql- TRACKER_API_VERSION@.la
@@ -44,7 +44,7 @@ vapi_sources =								\
 	$(top_srcdir)/src/vapi/glib-2.0-fixes.vapi
 
 libtracker-sparql.vala.stamp: $(libtracker_sparql_la_VALASOURCES) $(vapi_sources)
-	$(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg gmodule-2.0 --pkg dbus-glib-1 -H tracker-sparql.h --vapi tracker-sparql-$(TRACKER_API_VERSION).vapi $^
+	$(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg gmodule-2.0 -H tracker-sparql.h --vapi tracker-sparql-$(TRACKER_API_VERSION).vapi $^
 	$(AM_V_GEN)touch $@
 
 tracker-sparql-$(TRACKER_API_VERSION).deps: tracker-sparql.deps
@@ -60,7 +60,6 @@ vapi_DATA =						\
 
 libtracker_sparql_ TRACKER_API_VERSION@_la_LIBADD = 	\
 	$(GLIB2_LIBS)					\
-	$(DBUS_LIBS) 					\
 	$(GCOV_LIBS)					\
 	$(GIO_LIBS)
 
diff --git a/src/libtracker-sparql/tracker-backend.vala b/src/libtracker-sparql/tracker-backend.vala
index 8595596..71706ad 100644
--- a/src/libtracker-sparql/tracker-backend.vala
+++ b/src/libtracker-sparql/tracker-backend.vala
@@ -17,11 +17,11 @@
  * Boston, MA  02110-1301, USA.
  */
 
-[DBus (name = "org.freedesktop.Tracker1.Status", timeout = 2147483647 /* INT_MAX */)]
-interface Tracker.Backend.Status : GLib.Object {
-	public abstract void wait () throws DBus.Error;
+[DBus (name = "org.freedesktop.Tracker1.Status")]
+interface Tracker.Backend.Status : DBusProxy {
+	public abstract void wait () throws DBusError;
 	[DBus (name = "Wait")]
-	public abstract async void wait_async () throws DBus.Error;
+	public abstract async void wait_async () throws DBusError;
 }
 
 class Tracker.Sparql.Backend : Connection {
@@ -60,16 +60,16 @@ class Tracker.Sparql.Backend : Connection {
 	public override void init () throws Sparql.Error
 	requires (is_constructed) {
 		try {
-			var connection = DBus.Bus.get (DBus.BusType.SESSION);
-			var status = (Tracker.Backend.Status) connection.get_object (TRACKER_DBUS_SERVICE,
-			                                                             TRACKER_DBUS_OBJECT_STATUS,
-			                                                             TRACKER_DBUS_INTERFACE_STATUS);
+			Tracker.Backend.Status status = Bus.get_proxy_sync (BusType.SESSION,
+			                                                    TRACKER_DBUS_SERVICE,
+			                                                    TRACKER_DBUS_OBJECT_STATUS);
+			status.set_default_timeout (int.MAX);
 
 			// Makes sure the sevice is available
 			debug ("Waiting for service to become available synchronously...");
 			status.wait ();
 			debug ("Service is ready");
-		} catch (DBus.Error e) {
+		} catch (DBusError e) {
 			warning ("Could not connect to D-Bus service:'%s': %s", TRACKER_DBUS_INTERFACE_RESOURCES, e.message);
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
@@ -80,16 +80,16 @@ class Tracker.Sparql.Backend : Connection {
 	public async override void init_async () throws Sparql.Error
 	requires (is_constructed) {
 		try {
-			var connection = DBus.Bus.get (DBus.BusType.SESSION);
-			var status = (Tracker.Backend.Status) connection.get_object (TRACKER_DBUS_SERVICE,
-			                                                             TRACKER_DBUS_OBJECT_STATUS,
-			                                                             TRACKER_DBUS_INTERFACE_STATUS);
+			Tracker.Backend.Status status = Bus.get_proxy_sync (BusType.SESSION,
+			                                                    TRACKER_DBUS_SERVICE,
+			                                                    TRACKER_DBUS_OBJECT_STATUS);
+			status.set_default_timeout (int.MAX);
 
 			// Makes sure the sevice is available
 			debug ("Waiting for service to become available asynchronously...");
 			yield status.wait_async ();
 			debug ("Service is ready");
-		} catch (DBus.Error e) {
+		} catch (DBusError e) {
 			warning ("Could not connect to D-Bus service:'%s': %s", TRACKER_DBUS_INTERFACE_RESOURCES, e.message);
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
@@ -135,7 +135,7 @@ class Tracker.Sparql.Backend : Connection {
 		yield bus.update_async (sparql, priority, cancellable);
 	}
 
-	public async override GLib.PtrArray? update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError
+	public async override GenericArray<Error?> update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError
 	requires (bus != null) {
 		return yield bus.update_array_async (sparql, priority, cancellable);
 	}
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index f1f030a..a48ef60 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -60,7 +60,7 @@ public const string TRACKER_DBUS_OBJECT_STEROIDS = "/org/freedesktop/Tracker1/St
  *
  * Since: 0.10
  */
-[DBus (name = "org.freedesktop.DBus.GLib.UnmappedError.TrackerSparqlErrorQuark")]
+[DBus (name = "org.freedesktop.Tracker1.SparqlError")]
 public errordomain Tracker.Sparql.Error {
 	PARSE,
 	UNKNOWN_CLASS,
@@ -487,7 +487,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 *
 	 * Since: 0.10
 	 */
-	public async virtual GLib.PtrArray? update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
+	public async virtual GenericArray<Error?> update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		warning ("Interface 'update_array_async' not implemented");
 		return null;
 	}



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