[tracker] libtracker-common: Improve tracker_dbus_request_* API



commit 2fa39f629e59ea69c9f240d20f99af0b086fcc9c
Author: Jürg Billeter <j bitron ch>
Date:   Wed Jan 5 15:58:37 2011 +0100

    libtracker-common: Improve tracker_dbus_request_* API
    
    This makes it simpler to use and does no longer require D-Bus GLib.

 src/libtracker-common/tracker-dbus.c        |  174 +++++++++++-------------
 src/libtracker-common/tracker-dbus.h        |   88 ++++++------
 src/libtracker-miner/tracker-miner-object.c |   83 ++++--------
 src/miners/fs/tracker-miner-files-index.c   |   51 +++----
 src/tracker-extract/tracker-extract.c       |  163 ++++++++---------------
 src/tracker-store/tracker-backup.c          |   44 ++----
 src/tracker-store/tracker-resources.c       |  145 ++++++++-------------
 src/tracker-store/tracker-statistics.c      |   12 +-
 src/tracker-store/tracker-status.c          |   12 +-
 src/tracker-store/tracker-steroids.c        |  193 ++++++---------------------
 tests/libtracker-common/tracker-dbus-test.c |   95 +++++--------
 11 files changed, 388 insertions(+), 672 deletions(-)
---
diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index bedb350..cc072dd 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -41,6 +41,11 @@ typedef struct {
 	guint clean_up_id;
 } ClientData;
 
+struct _TrackerDBusRequest {
+	guint request_id;
+	ClientData *cd;
+};
+
 typedef struct {
 	GInputStream *unix_input_stream;
 	GInputStream *buffered_input_stream;
@@ -211,10 +216,9 @@ client_clean_up_cb (gpointer data)
 }
 
 static ClientData *
-client_get_for_context (DBusGMethodInvocation *context)
+client_get_for_sender (const gchar *sender)
 {
 	ClientData *cd;
-	gchar *sender;
 
 	if (!client_lookup_enabled) {
 		return NULL;
@@ -223,25 +227,22 @@ client_get_for_context (DBusGMethodInvocation *context)
 	/* Only really done with tracker-extract where we use
 	 * functions from the command line with dbus code in them.
 	 */
-	if (!context) {
+	if (!sender) {
 		return NULL;
 	}
 
-	/* Shame we have to allocate memory in any condition here,
-	 * sucky glib D-Bus API is to blame here :/
-	 */
-	sender = dbus_g_method_get_sender (context);
-
 	if (G_UNLIKELY (!clients)) {
 		clients_init ();
 	}
 
 	cd = g_hash_table_lookup (clients, sender);
 	if (!cd) {
-		cd = client_data_new (sender);
-		g_hash_table_insert (clients, sender, cd);
+		gchar *sender_dup;
+
+		sender_dup = g_strdup (sender);
+		cd = client_data_new (sender_dup);
+		g_hash_table_insert (clients, sender_dup, cd);
 	} else {
-		g_free (sender);
 		g_source_remove (cd->clean_up_id);
 	}
 
@@ -282,21 +283,20 @@ tracker_dbus_slist_to_strv (GSList *list)
 	return strv;
 }
 
-guint
-tracker_dbus_get_next_request_id (void)
+static guint
+get_next_request_id (void)
 {
 	static guint request_id = 1;
 
 	return request_id++;
 }
 
-void
-tracker_dbus_request_new (gint                   request_id,
-                          DBusGMethodInvocation *context,
-                          const gchar           *format,
-                          ...)
+TrackerDBusRequest *
+tracker_dbus_request_begin (const gchar *sender,
+                            const gchar *format,
+                            ...)
 {
-	ClientData *cd;
+	TrackerDBusRequest *request;
 	gchar *str;
 	va_list args;
 
@@ -304,75 +304,49 @@ tracker_dbus_request_new (gint                   request_id,
 	str = g_strdup_vprintf (format, args);
 	va_end (args);
 
-	cd = client_get_for_context (context);
+	request = g_slice_new (TrackerDBusRequest);
+	request->request_id = get_next_request_id ();
+	request->cd = client_get_for_sender (sender);
 
 	g_debug ("<--- [%d%s%s|%lu] %s",
-	         request_id,
-	         cd ? "|" : "",
-	         cd ? cd->binary : "",
-	         cd ? cd->pid : 0,
+	         request->request_id,
+	         request->cd ? "|" : "",
+	         request->cd ? request->cd->binary : "",
+	         request->cd ? request->cd->pid : 0,
 	         str);
 
 	g_free (str);
-}
-
-void
-tracker_dbus_request_success (gint                   request_id,
-                              DBusGMethodInvocation *context)
-{
-	ClientData *cd;
 
-	cd = client_get_for_context (context);
-
-	g_debug ("---> [%d%s%s|%lu] Success, no error given",
-	         request_id,
-	         cd ? "|" : "",
-	         cd ? cd->binary : "",
-	         cd ? cd->pid : 0);
+	return request;
 }
 
 void
-tracker_dbus_request_failed (gint                    request_id,
-                             DBusGMethodInvocation  *context,
-                             GError                **error,
-                             const gchar            *format,
-                             ...)
+tracker_dbus_request_end (TrackerDBusRequest *request,
+                          GError             *error)
 {
-	ClientData *cd;
-	gchar *str;
-	va_list args;
-
-	if (format) {
-		va_start (args, format);
-		str = g_strdup_vprintf (format, args);
-		va_end (args);
-
-		g_set_error (error, TRACKER_DBUS_ERROR, 0, "%s", str);
-	} else if (*error != NULL) {
-		str = g_strdup ((*error)->message);
+	if (!error) {
+		g_debug ("---> [%d%s%s|%lu] Success, no error given",
+			 request->request_id,
+			 request->cd ? "|" : "",
+			 request->cd ? request->cd->binary : "",
+			 request->cd ? request->cd->pid : 0);
 	} else {
-		str = g_strdup (_("No error given"));
-		g_warning ("Unset error and no error message.");
+		g_message ("---> [%d%s%s|%lu] Failed, %s",
+			   request->request_id,
+			   request->cd ? "|" : "",
+			   request->cd ? request->cd->binary : "",
+			   request->cd ? request->cd->pid : 0,
+			   error->message);
 	}
 
-	cd = client_get_for_context (context);
-
-	g_message ("---> [%d%s%s|%lu] Failed, %s",
-	           request_id,
-	           cd ? "|" : "",
-	           cd ? cd->binary : "",
-	           cd ? cd->pid : 0,
-	           str);
-	g_free (str);
+	g_slice_free (TrackerDBusRequest, request);
 }
 
 void
-tracker_dbus_request_info (gint                   request_id,
-                           DBusGMethodInvocation *context,
+tracker_dbus_request_info (TrackerDBusRequest    *request,
                            const gchar           *format,
                            ...)
 {
-	ClientData *cd;
 	gchar *str;
 	va_list args;
 
@@ -380,24 +354,20 @@ tracker_dbus_request_info (gint                   request_id,
 	str = g_strdup_vprintf (format, args);
 	va_end (args);
 
-	cd = client_get_for_context (context);
-
 	tracker_info ("---- [%d%s%s|%lu] %s",
-	              request_id,
-	              cd ? "|" : "",
-	              cd ? cd->binary : "",
-	              cd ? cd->pid : 0,
+	              request->request_id,
+	              request->cd ? "|" : "",
+	              request->cd ? request->cd->binary : "",
+	              request->cd ? request->cd->pid : 0,
 	              str);
 	g_free (str);
 }
 
 void
-tracker_dbus_request_comment (gint                   request_id,
-                              DBusGMethodInvocation *context,
+tracker_dbus_request_comment (TrackerDBusRequest    *request,
                               const gchar           *format,
                               ...)
 {
-	ClientData *cd;
 	gchar *str;
 	va_list args;
 
@@ -405,24 +375,20 @@ tracker_dbus_request_comment (gint                   request_id,
 	str = g_strdup_vprintf (format, args);
 	va_end (args);
 
-	cd = client_get_for_context (context);
-
 	g_message ("---- [%d%s%s|%lu] %s",
-	           request_id,
-	           cd ? "|" : "",
-	           cd ? cd->binary : "",
-	           cd ? cd->pid : 0,
+	           request->request_id,
+	           request->cd ? "|" : "",
+	           request->cd ? request->cd->binary : "",
+	           request->cd ? request->cd->pid : 0,
 	           str);
 	g_free (str);
 }
 
 void
-tracker_dbus_request_debug (gint                   request_id,
-                            DBusGMethodInvocation *context,
+tracker_dbus_request_debug (TrackerDBusRequest    *request,
                             const gchar           *format,
                             ...)
 {
-	ClientData *cd;
 	gchar *str;
 	va_list args;
 
@@ -430,13 +396,11 @@ tracker_dbus_request_debug (gint                   request_id,
 	str = g_strdup_vprintf (format, args);
 	va_end (args);
 
-	cd = client_get_for_context (context);
-
 	g_debug ("---- [%d%s%s|%lu] %s",
-	         request_id,
-	         cd ? "|" : "",
-	         cd ? cd->binary : "",
-	         cd ? cd->pid : 0,
+	         request->request_id,
+	         request->cd ? "|" : "",
+	         request->cd ? request->cd->binary : "",
+	         request->cd ? request->cd->pid : 0,
 	         str);
 	g_free (str);
 }
@@ -454,6 +418,30 @@ tracker_dbus_enable_client_lookup (gboolean enabled)
 	client_lookup_enabled = enabled;
 }
 
+TrackerDBusRequest *
+tracker_dbus_g_request_begin (DBusGMethodInvocation *context,
+                              const gchar           *format,
+                              ...)
+{
+	TrackerDBusRequest *request;
+	gchar *str, *sender;
+	va_list args;
+
+	va_start (args, format);
+	str = g_strdup_vprintf (format, args);
+	va_end (args);
+
+	sender = dbus_g_method_get_sender (context);
+
+	request = tracker_dbus_request_begin (sender, "%s", str);
+
+	g_free (sender);
+
+	g_free (str);
+
+	return request;
+}
+
 static GStrv
 dbus_send_and_splice_get_variable_names (DBusMessage *message,
                                          gboolean     copy_strings)
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index 50b70f5..0d9c5ca 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -104,6 +104,8 @@ typedef void (*TrackerDBusSendAndSpliceCallback) (void     *buffer,
                                                   GError   *error,
                                                   gpointer  user_data);
 
+typedef struct _TrackerDBusRequest TrackerDBusRequest;
+
 typedef enum {
 	TRACKER_DBUS_EVENTS_TYPE_ADD,
 	TRACKER_DBUS_EVENTS_TYPE_UPDATE,
@@ -116,58 +118,54 @@ typedef enum {
 	TRACKER_DBUS_ERROR_BROKEN_PIPE
 } TrackerDBusError;
 
-GQuark           tracker_dbus_error_quark            (void);
+GQuark              tracker_dbus_error_quark           (void);
 
 /* Utils */
-gchar **         tracker_dbus_slist_to_strv          (GSList                     *list);
+gchar **            tracker_dbus_slist_to_strv         (GSList                     *list);
 
 /* Requests */
-guint            tracker_dbus_get_next_request_id    (void);
-
-void             tracker_dbus_request_new            (gint                        request_id,
-                                                      DBusGMethodInvocation      *context,
-                                                      const gchar                *format,
-                                                      ...);
-void             tracker_dbus_request_success        (gint                        request_id,
-                                                      DBusGMethodInvocation      *context);
-void             tracker_dbus_request_failed         (gint                        request_id,
-                                                      DBusGMethodInvocation      *context,
-                                                      GError                    **error,
-                                                      const gchar                *format,
-                                                      ...);
-void             tracker_dbus_request_comment        (gint                        request_id,
-                                                      DBusGMethodInvocation      *context,
-                                                      const gchar                *format,
-                                                      ...);
-void             tracker_dbus_request_info           (gint                        request_id,
-                                                      DBusGMethodInvocation      *context,
-                                                      const gchar                *format,
-                                                      ...);
-void             tracker_dbus_request_debug          (gint                        request_id,
-                                                      DBusGMethodInvocation      *context,
-                                                      const gchar                *format,
-                                                      ...);
-
-void             tracker_dbus_enable_client_lookup   (gboolean                    enable);
+
+TrackerDBusRequest *tracker_dbus_request_begin         (const gchar                *sender,
+                                                        const gchar                *format,
+                                                        ...);
+void                tracker_dbus_request_end           (TrackerDBusRequest         *request,
+                                                        GError                     *error);
+void                tracker_dbus_request_comment       (TrackerDBusRequest         *request,
+                                                        const gchar                *format,
+                                                        ...);
+void                tracker_dbus_request_info          (TrackerDBusRequest         *request,
+                                                        const gchar                *format,
+                                                        ...);
+void                tracker_dbus_request_debug         (TrackerDBusRequest         *request,
+                                                        const gchar                *format,
+                                                        ...);
+
+void                tracker_dbus_enable_client_lookup  (gboolean                    enable);
+
 
 #ifndef NO_LIBDBUS
+/* dbus-glib convenience API */
+TrackerDBusRequest *tracker_dbus_g_request_begin       (DBusGMethodInvocation      *context,
+                                                        const gchar                *format,
+                                                        ...);
+
 /* File descriptor convenience API */
-gboolean         tracker_dbus_send_and_splice        (DBusConnection             *connection,
-                                                      DBusMessage                *message,
-                                                      int                         fd,
-                                                      GCancellable               *cancellable,
-                                                      void                      **dest_buffer,
-                                                      gssize                     *dest_buffer_size,
-                                                      GStrv                      *variable_names,
-                                                      GError                    **error);
-
-gboolean         tracker_dbus_send_and_splice_async  (DBusConnection             *connection,
-                                                      DBusMessage                *message,
-                                                      int                         fd,
-                                                      gboolean                    expect_variable_names,
-                                                      GCancellable               *cancellable,
-                                                      TrackerDBusSendAndSpliceCallback callback,
-                                                      gpointer                    user_data);
+gboolean            tracker_dbus_send_and_splice       (DBusConnection             *connection,
+                                                        DBusMessage                *message,
+                                                        int                         fd,
+                                                        GCancellable               *cancellable,
+                                                        void                      **dest_buffer,
+                                                        gssize                     *dest_buffer_size,
+                                                        GStrv                      *variable_names,
+                                                        GError                    **error);
+
+gboolean            tracker_dbus_send_and_splice_async (DBusConnection             *connection,
+                                                        DBusMessage                *message,
+                                                        int                         fd,
+                                                        gboolean                    expect_variable_names,
+                                                        GCancellable               *cancellable,
+                                                        TrackerDBusSendAndSpliceCallback callback,
+                                                        gpointer                    user_data);
 #endif
 
 G_END_DECLS
diff --git a/src/libtracker-miner/tracker-miner-object.c b/src/libtracker-miner/tracker-miner-object.c
index 2e8a9ee..7c7e786 100644
--- a/src/libtracker-miner/tracker-miner-object.c
+++ b/src/libtracker-miner/tracker-miner-object.c
@@ -656,15 +656,13 @@ _tracker_miner_dbus_get_status (TrackerMiner           *miner,
                                 DBusGMethodInvocation  *context,
                                 GError                **error)
 {
-	guint request_id;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusRequest *request;
 
 	tracker_dbus_async_return_if_fail (miner != NULL, context);
 
-	tracker_dbus_request_new (request_id, context, "%s()", __PRETTY_FUNCTION__);
+	request = tracker_dbus_g_request_begin (context, "%s()", __PRETTY_FUNCTION__);
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context, miner->private->status);
 }
 
@@ -673,15 +671,13 @@ _tracker_miner_dbus_get_progress (TrackerMiner           *miner,
                                   DBusGMethodInvocation  *context,
                                   GError                **error)
 {
-	guint request_id;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusRequest *request;
 
 	tracker_dbus_async_return_if_fail (miner != NULL, context);
 
-	tracker_dbus_request_new (request_id, context, "%s()", __PRETTY_FUNCTION__);
+	request = tracker_dbus_g_request_begin (context, "%s()", __PRETTY_FUNCTION__);
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context, miner->private->progress);
 }
 
@@ -694,13 +690,11 @@ _tracker_miner_dbus_get_pause_details (TrackerMiner           *miner,
 	GStrv applications_strv, reasons_strv;
 	GHashTableIter iter;
 	gpointer key, value;
-	guint request_id;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusRequest *request;
 
 	tracker_dbus_async_return_if_fail (miner != NULL, context);
 
-	tracker_dbus_request_new (request_id, context, "%s()", __PRETTY_FUNCTION__);
+	request = tracker_dbus_g_request_begin (context, "%s()", __PRETTY_FUNCTION__);
 
 	applications = NULL;
 	reasons = NULL;
@@ -719,7 +713,7 @@ _tracker_miner_dbus_get_pause_details (TrackerMiner           *miner,
 	applications_strv = tracker_gslist_to_string_list (applications);
 	reasons_strv = tracker_gslist_to_string_list (reasons);
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context, applications_strv, reasons_strv);
 
 	g_strfreev (applications_strv);
@@ -737,38 +731,30 @@ _tracker_miner_dbus_pause (TrackerMiner           *miner,
                            GError                **error)
 {
 	GError *local_error = NULL;
-	guint request_id;
+	TrackerDBusRequest *request;
 	gint cookie;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
 	tracker_dbus_async_return_if_fail (miner != NULL, context);
 	tracker_dbus_async_return_if_fail (application != NULL, context);
 	tracker_dbus_async_return_if_fail (reason != NULL, context);
 
-	tracker_dbus_request_new (request_id, context,
-	                          "%s(application:'%s', reason:'%s')",
-	                          __PRETTY_FUNCTION__,
-	                          application,
-	                          reason);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s(application:'%s', reason:'%s')",
+	                                        __PRETTY_FUNCTION__,
+	                                        application,
+	                                        reason);
 
 	cookie = tracker_miner_pause_internal (miner, application, reason, &local_error);
 	if (cookie == -1) {
-		GError *actual_error = NULL;
+		tracker_dbus_request_end (request, local_error);
+		dbus_g_method_return_error (context, local_error);
 
-		tracker_dbus_request_failed (request_id,
-		                             context,
-		                             &actual_error,
-		                             local_error ? local_error->message : NULL);
-		dbus_g_method_return_error (context, actual_error);
-
-		g_error_free (actual_error);
 		g_error_free (local_error);
 
 		return;
 	}
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context, cookie);
 }
 
@@ -779,34 +765,25 @@ _tracker_miner_dbus_resume (TrackerMiner           *miner,
                             GError                **error)
 {
 	GError *local_error = NULL;
-	guint request_id;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusRequest *request;
 
 	tracker_dbus_async_return_if_fail (miner != NULL, context);
 
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "%s(cookie:%d)",
-	                          __PRETTY_FUNCTION__,
-	                          cookie);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s(cookie:%d)",
+	                                        __PRETTY_FUNCTION__,
+	                                        cookie);
 
 	if (!tracker_miner_resume (miner, cookie, &local_error)) {
-		GError *actual_error = NULL;
+		tracker_dbus_request_end (request, local_error);
+		dbus_g_method_return_error (context, local_error);
 
-		tracker_dbus_request_failed (request_id,
-		                             context,
-		                             &actual_error,
-		                             local_error ? local_error->message : NULL);
-		dbus_g_method_return_error (context, actual_error);
-
-		g_error_free (actual_error);
 		g_error_free (local_error);
 
 		return;
 	}
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context);
 }
 
@@ -816,16 +793,14 @@ _tracker_miner_dbus_ignore_next_update (TrackerMiner           *miner,
                                         DBusGMethodInvocation  *context,
                                         GError                **error)
 {
-	guint request_id;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusRequest *request;
 
 	tracker_dbus_async_return_if_fail (miner != NULL, context);
 
-	tracker_dbus_request_new (request_id, context, "%s()", __PRETTY_FUNCTION__);
+	request = tracker_dbus_g_request_begin (context, "%s()", __PRETTY_FUNCTION__);
 
 	tracker_miner_ignore_next_update (miner, urls);
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context);
 }
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index ef724a3..467ba6f 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -35,7 +35,7 @@
 #undef REQUIRE_LOCATION_IN_CONFIG
 
 typedef struct {
-	guint request_id;
+	TrackerDBusRequest *request;
 	DBusGMethodInvocation *context;
 	TrackerSparqlConnection *connection;
 	TrackerMinerFiles *miner_files;
@@ -140,7 +140,7 @@ tracker_miner_files_index_init (TrackerMinerFilesIndex *object)
 }
 
 static MimeTypesData *
-mime_types_data_new (guint                    request_id,
+mime_types_data_new (TrackerDBusRequest      *request,
                      DBusGMethodInvocation   *context,
                      TrackerSparqlConnection *connection,
                      TrackerMinerFiles       *miner_files)
@@ -150,7 +150,7 @@ mime_types_data_new (guint                    request_id,
 	mtd = g_slice_new0 (MimeTypesData);
 
 	mtd->miner_files = g_object_ref (miner_files);
-	mtd->request_id = request_id;
+	mtd->request = request;
 	mtd->context = context;
 	mtd->connection = g_object_ref (connection);
 
@@ -184,7 +184,7 @@ mime_types_cb (GObject      *object,
 	                                                 &error);
 
 	if (cursor) {
-		tracker_dbus_request_comment (mtd->request_id, mtd->context,
+		tracker_dbus_request_comment (mtd->request,
 		                              "Found files that will need reindexing");
 
 		while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
@@ -197,13 +197,10 @@ mime_types_cb (GObject      *object,
 			g_object_unref (file);
 		}
 
-		tracker_dbus_request_success (mtd->request_id, mtd->context);
+		tracker_dbus_request_end (mtd->request, NULL);
 		dbus_g_method_return (mtd->context);
 	} else {
-		tracker_dbus_request_failed (mtd->request_id,
-		                             mtd->context,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (mtd->request, error);
 		dbus_g_method_return_error (mtd->context, error);
 	}
 
@@ -228,33 +225,28 @@ tracker_miner_files_index_reindex_mime_types (TrackerMinerFilesIndex  *object,
 	GString *query;
 	GError *inner_error = NULL;
 	TrackerSparqlConnection *connection;
-	guint request_id;
+	TrackerDBusRequest *request;
 	gint len, i;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
 	tracker_dbus_async_return_if_fail (mime_types != NULL, context);
 
 	len = g_strv_length (mime_types);
 	tracker_dbus_async_return_if_fail (len > 0, context);
 
-	tracker_dbus_request_new (request_id, context, "%s(%d mime types)",
-	                          __FUNCTION__,
-	                          len);
+	request = tracker_dbus_g_request_begin (context, "%s(%d mime types)",
+	                                        __FUNCTION__,
+	                                        len);
 
 	connection = tracker_sparql_connection_get (NULL, &inner_error);
 
 	if (!connection) {
-		tracker_dbus_request_failed (request_id,
-		                             context,
-		                             &inner_error,
-		                             NULL);
+		tracker_dbus_request_end (request, inner_error);
 		dbus_g_method_return_error (context, inner_error);
 		g_error_free (inner_error);
 		return;
 	}
 
-	tracker_dbus_request_comment (request_id, context,
+	tracker_dbus_request_comment (request,
 	                              "Attempting to reindex the following mime types:");
 
 
@@ -265,7 +257,7 @@ tracker_miner_files_index_reindex_mime_types (TrackerMinerFilesIndex  *object,
 	                      "  FILTER(");
 
 	for (i = 0; i < len; i++) {
-		tracker_dbus_request_comment (request_id, context, "  %s", mime_types[i]);
+		tracker_dbus_request_comment (request, "  %s", mime_types[i]);
 		g_string_append_printf (query, "?mime = '%s'", mime_types[i]);
 
 		if (i < len - 1) {
@@ -282,7 +274,7 @@ tracker_miner_files_index_reindex_mime_types (TrackerMinerFilesIndex  *object,
 	                                       query->str,
 	                                       NULL,
 	                                       mime_types_cb,
-	                                       mime_types_data_new (request_id,
+	                                       mime_types_data_new (request,
 	                                                            context,
 	                                                            connection,
 	                                                            priv->files_miner));
@@ -299,7 +291,7 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 {
 	TrackerMinerFilesIndexPrivate *priv;
 	TrackerConfig *config;
-	guint request_id;
+	TrackerDBusRequest *request;
 	GFile *file, *dir;
 	GFileInfo *file_info;
 	gboolean is_dir;
@@ -308,8 +300,7 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 
 	tracker_dbus_async_return_if_fail (file_uri != NULL, context);
 
-	request_id = tracker_dbus_get_next_request_id ();
-	tracker_dbus_request_new (request_id, context, "%s(uri:'%s')", __FUNCTION__, file_uri);
+	request = tracker_dbus_g_request_begin (context, "%s(uri:'%s')", __FUNCTION__, file_uri);
 
 	priv = TRACKER_MINER_FILES_INDEX_GET_PRIVATE (object);
 	file = g_file_new_for_uri (file_uri);
@@ -325,7 +316,7 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 
 	if (!file_info) {
 		internal_error = g_error_new_literal (1, 0, "File does not exist");
-		tracker_dbus_request_failed (request_id, context, &internal_error, NULL);
+		tracker_dbus_request_end (request, internal_error);
 		dbus_g_method_return_error (context, internal_error);
 
 		g_error_free (internal_error);
@@ -348,7 +339,7 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 		                                     tracker_config_get_ignored_file_paths (config),
 		                                     tracker_config_get_ignored_file_patterns (config))) {
 			internal_error = g_error_new_literal (1, 0, "File is not eligible to be indexed");
-			tracker_dbus_request_failed (request_id, context, &internal_error, NULL);
+			tracker_dbus_request_end (request, internal_error);
 			dbus_g_method_return_error (context, internal_error);
 
 			g_error_free (internal_error);
@@ -371,7 +362,7 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 		                                          tracker_config_get_ignored_directory_paths (config),
 		                                          tracker_config_get_ignored_directory_patterns (config))) {
 			internal_error = g_error_new_literal (1, 0, "File is not eligible to be indexed");
-			tracker_dbus_request_failed (request_id, context, &internal_error, NULL);
+			tracker_dbus_request_end (request, internal_error);
 			dbus_g_method_return_error (context, internal_error);
 
 			g_error_free (internal_error);
@@ -412,7 +403,7 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 
 		if (!found) {
 			internal_error = g_error_new_literal (1, 0, "File is not eligible to be indexed");
-			tracker_dbus_request_failed (request_id, context, &internal_error, NULL);
+			tracker_dbus_request_end (request, internal_error);
 			dbus_g_method_return_error (context, internal_error);
 
 			g_error_free (internal_error);
@@ -430,7 +421,7 @@ tracker_miner_files_index_index_file (TrackerMinerFilesIndex  *object,
 		tracker_miner_fs_check_file (TRACKER_MINER_FS (priv->files_miner), file, do_checks);
 	}
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context);
 
 	g_object_unref (file);
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index bc72b48..48827cc 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -368,7 +368,7 @@ tracker_extract_new (gboolean     disable_shutdown,
 
 static gboolean
 get_file_metadata (TrackerExtract         *extract,
-                   guint                   request_id,
+                   TrackerDBusRequest     *request,
                    DBusGMethodInvocation  *context,
                    const gchar            *uri,
                    const gchar            *mime,
@@ -393,7 +393,7 @@ get_file_metadata (TrackerExtract         *extract,
 
 #ifdef HAVE_LIBSTREAMANALYZER
 	if (!priv->force_internal_extractors) {
-		tracker_dbus_request_comment (request_id, context,
+		tracker_dbus_request_comment (request,
 		                              "  Extracting with libstreamanalyzer...");
 
 		tracker_topanalyzer_extract (uri, statements, &content_type);
@@ -407,7 +407,7 @@ get_file_metadata (TrackerExtract         *extract,
 			return TRUE;
 		}
 	} else {
-		tracker_dbus_request_comment (request_id, context,
+		tracker_dbus_request_comment (request,
 		                              "  Extracting with internal extractors ONLY...");
 	}
 #endif /* HAVE_LIBSTREAMANALYZER */
@@ -445,8 +445,7 @@ get_file_metadata (TrackerExtract         *extract,
 		                          &error);
 
 		if (error || !info) {
-			tracker_dbus_request_comment (request_id,
-			                              context,
+			tracker_dbus_request_comment (request,
 			                              "  Could not create GFileInfo for file size check, %s",
 			                              error ? error->message : "no error given");
 			g_error_free (error);
@@ -464,8 +463,7 @@ get_file_metadata (TrackerExtract         *extract,
 
 		mime_used = g_strdup (g_file_info_get_content_type (info));
 
-		tracker_dbus_request_comment (request_id,
-		                              context,
+		tracker_dbus_request_comment (request,
 		                              "  Guessing mime type as '%s' for uri:'%s'",
 		                              mime_used,
 		                              uri);
@@ -500,8 +498,7 @@ get_file_metadata (TrackerExtract         *extract,
 			if (g_pattern_match (mdata->pattern, length, mime_used, reversed)) {
 				gint items;
 
-				tracker_dbus_request_comment (request_id,
-				                              context,
+				tracker_dbus_request_comment (request,
 				                              "  Extracting with module:'%s'",
 				                              g_module_name ((GModule*) mdata->module));
 
@@ -509,8 +506,7 @@ get_file_metadata (TrackerExtract         *extract,
 
 				items = tracker_sparql_builder_get_length (statements);
 
-				tracker_dbus_request_comment (request_id,
-				                              context,
+				tracker_dbus_request_comment (request,
 				                              "  Found %d metadata items",
 				                              items);
 
@@ -542,8 +538,7 @@ get_file_metadata (TrackerExtract         *extract,
 			if (g_pattern_match (mdata->pattern, length, mime_used, reversed)) {
 				gint items;
 
-				tracker_dbus_request_comment (request_id,
-				                              context,
+				tracker_dbus_request_comment (request,
 				                              "  Extracting with module:'%s'",
 				                              g_module_name ((GModule*) mdata->module));
 
@@ -551,8 +546,7 @@ get_file_metadata (TrackerExtract         *extract,
 
 				items = tracker_sparql_builder_get_length (statements);
 
-				tracker_dbus_request_comment (request_id,
-				                              context,
+				tracker_dbus_request_comment (request,
 				                              "  Found %d metadata items",
 				                              items);
 
@@ -575,8 +569,7 @@ get_file_metadata (TrackerExtract         *extract,
 			}
 		}
 
-		tracker_dbus_request_comment (request_id,
-		                              context,
+		tracker_dbus_request_comment (request,
 		                              "  Could not find any extractors to handle metadata type "
 		                              "(mime: %s)",
 		                              mime_used);
@@ -584,8 +577,7 @@ get_file_metadata (TrackerExtract         *extract,
 		g_free (mime_used);
 		g_free (reversed);
 	} else {
-		tracker_dbus_request_comment (request_id,
-		                              context,
+		tracker_dbus_request_comment (request,
 		                              "  No mime available, not extracting data");
 	}
 
@@ -604,27 +596,24 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
                                          const gchar    *uri,
                                          const gchar    *mime)
 {
-	guint request_id;
+	TrackerDBusRequest *request;
 	TrackerSparqlBuilder *statements, *preupdate;
 	TrackerExtractPrivate *priv;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
 	priv = TRACKER_EXTRACT_GET_PRIVATE (object);
 	priv->disable_summary_on_finalize = TRUE;
 
 	g_return_if_fail (uri != NULL);
 
-	tracker_dbus_request_new (request_id,
-	                          NULL,
-	                          "%s(uri:'%s', mime:%s)",
-	                          __FUNCTION__,
-	                          uri,
-	                          mime);
+	request = tracker_dbus_request_begin (NULL,
+	                                      "%s(uri:'%s', mime:%s)",
+	                                      __FUNCTION__,
+	                                      uri,
+	                                      mime);
 
 	/* NOTE: Don't reset the timeout to shutdown here */
 
-	if (get_file_metadata (object, request_id,
+	if (get_file_metadata (object, request,
 			       NULL, uri, mime,
 			       &preupdate, &statements)) {
 		const gchar *preupdate_str, *statements_str;
@@ -639,16 +628,16 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 			preupdate_str = tracker_sparql_builder_get_result (preupdate);
 		}
 
-		tracker_dbus_request_info (request_id, NULL, "%s",
+		tracker_dbus_request_info (request, "%s",
 					   preupdate_str ? preupdate_str : "");
-		tracker_dbus_request_info (request_id, NULL, "%s",
+		tracker_dbus_request_info (request, "%s",
 					   statements_str ? statements_str : "");
 
 		g_object_unref (statements);
 		g_object_unref (preupdate);
 	}
 
-	tracker_dbus_request_success (request_id, NULL);
+	tracker_dbus_request_end (request, NULL);
 }
 
 void
@@ -656,23 +645,19 @@ tracker_extract_get_pid (TrackerExtract         *object,
                          DBusGMethodInvocation  *context,
                          GError                **error)
 {
-	guint request_id;
+	TrackerDBusRequest *request;
 	pid_t value;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "%s()",
-	                          __FUNCTION__);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s()",
+	                                        __FUNCTION__);
 
 	value = getpid ();
-	tracker_dbus_request_debug (request_id,
-	                            context,
+	tracker_dbus_request_debug (request,
 	                            "PID is %d",
 	                            value);
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context, value);
 }
 
@@ -683,24 +668,21 @@ tracker_extract_get_metadata (TrackerExtract         *object,
                               DBusGMethodInvocation  *context,
                               GError                **error)
 {
-	guint request_id;
+	TrackerDBusRequest *request;
 	TrackerExtractPrivate *priv;
 	TrackerSparqlBuilder *sparql, *preupdate;
 	gboolean extracted = FALSE;
 
-	request_id = tracker_dbus_get_next_request_id ();
 
 	tracker_dbus_async_return_if_fail (uri != NULL, context);
 
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "%s(uri:'%s', mime:%s)",
-	                          __FUNCTION__,
-	                          uri,
-	                          mime);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s(uri:'%s', mime:%s)",
+	                                        __FUNCTION__,
+	                                        uri,
+	                                        mime);
 
-	tracker_dbus_request_debug (request_id,
-	                            context,
+	tracker_dbus_request_debug (request,
 	                            "  Resetting shutdown timeout");
 
 	priv = TRACKER_EXTRACT_GET_PRIVATE (object);
@@ -710,10 +692,10 @@ tracker_extract_get_metadata (TrackerExtract         *object,
 		alarm (MAX_EXTRACT_TIME);
 	}
 
-	extracted = get_file_metadata (object, request_id, context, uri, mime, &preupdate, &sparql);
+	extracted = get_file_metadata (object, request, context, uri, mime, &preupdate, &sparql);
 
 	if (extracted) {
-		tracker_dbus_request_success (request_id, context);
+		tracker_dbus_request_end (request, NULL);
 
 		if (tracker_sparql_builder_get_length (sparql) > 0) {
 			const gchar *preupdate_str = NULL;
@@ -732,14 +714,13 @@ tracker_extract_get_metadata (TrackerExtract         *object,
 		g_object_unref (sparql);
 		g_object_unref (preupdate);
 	} else {
-		GError *actual_error = NULL;
-
-		tracker_dbus_request_failed (request_id,
-		                             context,
-		                             &actual_error,
-		                             "Could not get any metadata for uri:'%s' and mime:'%s'",
-		                             uri,
-		                             mime);
+		GError *actual_error;
+
+		actual_error = g_error_new (TRACKER_DBUS_ERROR, 0,
+		                            "Could not get any metadata for uri:'%s' and mime:'%s'",
+		                            uri,
+		                            mime);
+		tracker_dbus_request_end (request, actual_error);
 		dbus_g_method_return_error (context, actual_error);
 		g_error_free (actual_error);
 	}
@@ -755,7 +736,7 @@ get_metadata_fast (TrackerExtract *object,
                    DBusConnection *connection,
                    DBusMessage    *message)
 {
-	guint request_id;
+	TrackerDBusRequest *request;
 	const gchar *expected_signature;
 	TrackerExtractPrivate *priv;
 	DBusError dbus_error;
@@ -769,7 +750,6 @@ get_metadata_fast (TrackerExtract *object,
 	TrackerSparqlBuilder *sparql, *preupdate;
 	gboolean extracted = FALSE;
 
-	request_id = tracker_dbus_get_next_request_id ();
 
 	expected_signature = DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UNIX_FD_AS_STRING;
 
@@ -779,21 +759,11 @@ get_metadata_fast (TrackerExtract *object,
 		                                        dbus_message_get_signature (message),
 		                                        dbus_message_get_interface (message),
 		                                        expected_signature);
-		tracker_dbus_request_new (request_id,
-		                          NULL,
-		                          "%s()",
-		                          __FUNCTION__);
-
 		reply = dbus_message_new_error (message,
 		                                DBUS_ERROR_UNKNOWN_METHOD,
 		                                error_message);
 		dbus_connection_send (connection, reply, NULL);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             error_message);
-
 		dbus_message_unref (reply);
 		g_free (error_message);
 
@@ -810,34 +780,22 @@ get_metadata_fast (TrackerExtract *object,
 	                       DBUS_TYPE_INVALID);
 
 	if (dbus_error_is_set (&dbus_error)) {
-		tracker_dbus_request_new (request_id,
-		                          NULL,
-		                          "%s()",
-		                          __FUNCTION__);
-
 		reply = dbus_message_new_error (message, dbus_error.name, dbus_error.message);
 		dbus_connection_send (connection, reply, NULL);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             dbus_error.message);
-
 		dbus_message_unref (reply);
 		dbus_error_free (&dbus_error);
 
 		return;
 	}
 
-	tracker_dbus_request_new (request_id,
-	                          NULL,
-	                          "%s(uri:'%s', mime:%s)",
-	                          __FUNCTION__,
-	                          uri,
-	                          mime);
+	request = tracker_dbus_request_begin (dbus_message_get_sender (message),
+	                                      "%s(uri:'%s', mime:%s)",
+	                                      __FUNCTION__,
+	                                      uri,
+	                                      mime);
 
-	tracker_dbus_request_debug (request_id,
-	                            NULL,
+	tracker_dbus_request_debug (request,
 	                            "  Resetting shutdown timeout");
 
 	priv = TRACKER_EXTRACT_GET_PRIVATE (object);
@@ -847,7 +805,7 @@ get_metadata_fast (TrackerExtract *object,
 		alarm (MAX_EXTRACT_TIME);
 	}
 
-	extracted = get_file_metadata (object, request_id, NULL, uri, mime, &preupdate, &sparql);
+	extracted = get_file_metadata (object, request, NULL, uri, mime, &preupdate, &sparql);
 
 	if (extracted) {
 		unix_output_stream = g_unix_output_stream_new (fd, TRUE);
@@ -898,10 +856,7 @@ get_metadata_fast (TrackerExtract *object,
 		g_object_unref (unix_output_stream);
 
 		if (error) {
-			tracker_dbus_request_failed (request_id,
-			                             NULL,
-			                             &error,
-			                             NULL);
+			tracker_dbus_request_end (request, error);
 			reply = dbus_message_new_error (message,
 			                                TRACKER_EXTRACT_SERVICE ".GetMetadataFastError",
 			                                error->message);
@@ -909,24 +864,22 @@ get_metadata_fast (TrackerExtract *object,
 			dbus_message_unref (reply);
 			g_error_free (error);
 		} else {
-			tracker_dbus_request_success (request_id, NULL);
+			tracker_dbus_request_end (request, NULL);
 			reply = dbus_message_new_method_return (message);
 			dbus_connection_send (connection, reply, NULL);
 			dbus_message_unref (reply);
 		}
 	} else {
-		gchar *error_message = g_strdup_printf ("Could not get any metadata for uri:'%s' and mime:'%s'", uri, mime);
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             error_message);
+		error = g_error_new (TRACKER_DBUS_ERROR, 0,
+		                     "Could not get any metadata for uri:'%s' and mime:'%s'", uri, mime);
+		tracker_dbus_request_end (request, error);
 		reply = dbus_message_new_error (message,
 		                                TRACKER_EXTRACT_SERVICE ".GetMetadataFastError",
-		                                error_message);
+		                                error->message);
 		close (fd);
 		dbus_connection_send (connection, reply, NULL);
 		dbus_message_unref (reply);
-		g_free (error_message);
+		g_error_free (error);
 	}
 
 	if (!priv->disable_shutdown) {
diff --git a/src/tracker-store/tracker-backup.c b/src/tracker-store/tracker-backup.c
index d30eb4b..fdb4e71 100644
--- a/src/tracker-store/tracker-backup.c
+++ b/src/tracker-store/tracker-backup.c
@@ -35,7 +35,7 @@
 
 typedef struct {
 	DBusGMethodInvocation *context;
-	guint request_id;
+	TrackerDBusRequest *request;
 	gchar *journal_uri;
 	TrackerResources *resources;
 	TrackerNotifyClassGetter getter;
@@ -66,16 +66,12 @@ backup_callback (GError *error, gpointer user_data)
 	TrackerDBusMethodInfo *info = user_data;
 
 	if (error) {
-		tracker_dbus_request_failed (info->request_id,
-		                             info->context,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, error);
 		dbus_g_method_return_error (info->context, error);
 		return;
 	}
 
-	tracker_dbus_request_success (info->request_id,
-	                              info->context);
+	tracker_dbus_request_end (info->request, NULL);
 
 	dbus_g_method_return (info->context);
 
@@ -94,16 +90,12 @@ restore_callback (GError *error, gpointer user_data)
 	TrackerDBusMethodInfo *info = user_data;
 
 	if (error) {
-		tracker_dbus_request_failed (info->request_id,
-		                             info->context,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, error);
 		dbus_g_method_return_error (info->context, error);
 		return;
 	}
 
-	tracker_dbus_request_success (info->request_id,
-	                              info->context);
+	tracker_dbus_request_end (info->request, NULL);
 
 	dbus_g_method_return (info->context);
 
@@ -136,20 +128,17 @@ tracker_backup_save (TrackerBackup          *object,
                      DBusGMethodInvocation  *context,
                      GError                **error)
 {
-	guint request_id;
+	TrackerDBusRequest *request;
 	TrackerDBusMethodInfo *info;
 	gpointer resources;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "D-Bus request to save backup into '%s'",
-	                          destination_uri);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "D-Bus request to save backup into '%s'",
+	                                        destination_uri);
 
 	info = g_new0 (TrackerDBusMethodInfo, 1);
 
-	info->request_id = request_id;
+	info->request = request;
 	info->context = context;
 	info->destination = g_file_new_for_uri (destination_uri);
 
@@ -200,19 +189,16 @@ tracker_backup_restore (TrackerBackup          *object,
                         DBusGMethodInvocation  *context,
                         GError                **error)
 {
-	guint request_id;
+	TrackerDBusRequest *request;
 	TrackerDBusMethodInfo *info;
 	gpointer resources;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "D-Bus request to restore backup from '%s'",
-	                          journal_uri);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "D-Bus request to restore backup from '%s'",
+	                                        journal_uri);
 
 	info = g_new0 (TrackerDBusMethodInfo, 1);
-	info->request_id = request_id;
+	info->request = request;
 	info->context = context;
 	info->journal_uri = g_strdup (journal_uri);
 	resources = tracker_dbus_get_object (TRACKER_TYPE_RESOURCES);
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 06fcb47..b81721f 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -89,7 +89,7 @@ typedef struct {
 
 typedef struct {
 	DBusGMethodInvocation *context;
-	guint request_id;
+	TrackerDBusRequest *request;
 	DBusMessage *reply;
 } TrackerDBusMethodInfo;
 
@@ -172,16 +172,12 @@ turtle_import_callback (GError *error, gpointer user_data)
 	TrackerDBusMethodInfo *info = user_data;
 
 	if (error) {
-		tracker_dbus_request_failed (info->request_id,
-		                             info->context,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, error);
 		dbus_g_method_return_error (info->context, error);
 		return;
 	}
 
-	tracker_dbus_request_success (info->request_id,
-	                              info->context);
+	tracker_dbus_request_end (info->request, NULL);
 	dbus_g_method_return (info->context);
 }
 
@@ -191,26 +187,23 @@ tracker_resources_load (TrackerResources         *object,
                         DBusGMethodInvocation    *context,
                         GError                  **error)
 {
-	TrackerDBusMethodInfo   *info;
-	guint                    request_id;
+	TrackerDBusMethodInfo *info;
+	TrackerDBusRequest *request;
 	GFile  *file;
 	gchar *sender;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
 	tracker_dbus_async_return_if_fail (uri != NULL, context);
 
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "%s(): uri:'%s'",
-	                          __FUNCTION__,
-	                          uri);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s(): uri:'%s'",
+	                                        __FUNCTION__,
+	                                        uri);
 
 	file = g_file_new_for_uri (uri);
 
 	info = g_slice_new (TrackerDBusMethodInfo);
 
-	info->request_id = request_id;
+	info->request = request;
 	info->context = context;
 
 	sender = dbus_g_method_get_sender (context);
@@ -229,21 +222,14 @@ query_callback (gpointer inthread_data, GError *error, gpointer user_data)
 	TrackerDBusMethodInfo *info = user_data;
 
 	if (ptr && ptr->error) {
-		tracker_dbus_request_failed (info->request_id,
-		                             info->context,
-		                             &ptr->error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, ptr->error);
 		dbus_g_method_return_error (info->context, ptr->error);
 		g_error_free (ptr->error);
 	} else if (error) {
-		tracker_dbus_request_failed (info->request_id,
-		                             info->context,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, error);
 		dbus_g_method_return_error (info->context, error);
 	} else if (ptr) {
-		tracker_dbus_request_success (info->request_id,
-		                              info->context);
+		tracker_dbus_request_end (info->request, NULL);
 
 		dbus_g_method_send_reply (info->context, ptr->reply);
 	} /* else, !ptr && !error... shouldn't happen */
@@ -336,23 +322,20 @@ tracker_resources_sparql_query (TrackerResources         *self,
                                 DBusGMethodInvocation    *context,
                                 GError                  **error)
 {
-	TrackerDBusMethodInfo   *info;
-	guint                 request_id;
-	gchar                 *sender;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusMethodInfo *info;
+	TrackerDBusRequest *request;
+	gchar *sender;
 
 	tracker_dbus_async_return_if_fail (query != NULL, context);
 
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "%s(): '%s'",
-	                          __FUNCTION__,
-	                          query);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s(): '%s'",
+	                                        __FUNCTION__,
+	                                        query);
 
 	info = g_slice_new (TrackerDBusMethodInfo);
 
-	info->request_id = request_id;
+	info->request = request;
 	info->context = context;
 	info->reply = dbus_g_method_get_reply (context);
 
@@ -371,16 +354,12 @@ update_callback (GError *error, gpointer user_data)
 	TrackerDBusMethodInfo *info = user_data;
 
 	if (error) {
-		tracker_dbus_request_failed (info->request_id,
-		                             info->context,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, error);
 		dbus_g_method_return_error (info->context, error);
 		return;
 	}
 
-	tracker_dbus_request_success (info->request_id,
-	                              info->context);
+	tracker_dbus_request_end (info->request, NULL);
 	dbus_g_method_return (info->context);
 }
 
@@ -390,23 +369,20 @@ tracker_resources_sparql_update (TrackerResources        *self,
                                  DBusGMethodInvocation   *context,
                                  GError                 **error)
 {
-	TrackerDBusMethodInfo   *info;
-	guint                 request_id;
-	gchar                 *sender;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusMethodInfo *info;
+	TrackerDBusRequest *request;
+	gchar *sender;
 
 	tracker_dbus_async_return_if_fail (update != NULL, context);
 
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "%s(): '%s'",
-	                          __FUNCTION__,
-	                          update);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s(): '%s'",
+	                                        __FUNCTION__,
+	                                        update);
 
 	info = g_slice_new (TrackerDBusMethodInfo);
 
-	info->request_id = request_id;
+	info->request = request;
 	info->context = context;
 
 	sender = dbus_g_method_get_sender (context);
@@ -424,16 +400,12 @@ update_blank_callback (GPtrArray *blank_nodes, GError *error, gpointer user_data
 	TrackerDBusMethodInfo *info = user_data;
 
 	if (error) {
-		tracker_dbus_request_failed (info->request_id,
-		                             info->context,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, error);
 		dbus_g_method_return_error (info->context, error);
 		return;
 	}
 
-	tracker_dbus_request_success (info->request_id,
-	                              info->context);
+	tracker_dbus_request_end (info->request, NULL);
 	dbus_g_method_return (info->context, blank_nodes);
 }
 
@@ -443,23 +415,20 @@ tracker_resources_sparql_update_blank (TrackerResources       *self,
                                        DBusGMethodInvocation  *context,
                                        GError                **error)
 {
-	TrackerDBusMethodInfo   *info;
-	guint                 request_id;
-	gchar                 *sender;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusMethodInfo *info;
+	TrackerDBusRequest *request;
+	gchar *sender;
 
 	tracker_dbus_async_return_if_fail (update != NULL, context);
 
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "%s(): '%s'",
-	                          __FUNCTION__,
-	                          update);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s(): '%s'",
+	                                        __FUNCTION__,
+	                                        update);
 
 	info = g_slice_new (TrackerDBusMethodInfo);
 
-	info->request_id = request_id;
+	info->request = request;
 	info->context = context;
 
 	sender = dbus_g_method_get_sender (context);
@@ -476,18 +445,15 @@ tracker_resources_sync (TrackerResources        *self,
                         DBusGMethodInvocation   *context,
                         GError                 **error)
 {
-	guint request_id;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusRequest *request;
 
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "%s()",
-	                          __FUNCTION__);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s()",
+	                                        __FUNCTION__);
 
 	tracker_data_sync ();
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context);
 }
 
@@ -497,23 +463,20 @@ tracker_resources_batch_sparql_update (TrackerResources          *self,
                                        DBusGMethodInvocation     *context,
                                        GError                   **error)
 {
-	TrackerDBusMethodInfo   *info;
-	guint                 request_id;
-	gchar                 *sender;
-
-	request_id = tracker_dbus_get_next_request_id ();
+	TrackerDBusMethodInfo *info;
+	TrackerDBusRequest *request;
+	gchar *sender;
 
 	tracker_dbus_async_return_if_fail (update != NULL, context);
 
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "%s(): '%s'",
-	                          __FUNCTION__,
-	                          update);
+	request = tracker_dbus_g_request_begin (context,
+	                                        "%s(): '%s'",
+	                                        __FUNCTION__,
+	                                        update);
 
 	info = g_slice_new (TrackerDBusMethodInfo);
 
-	info->request_id = request_id;
+	info->request = request;
 	info->context = context;
 
 	sender = dbus_g_method_get_sender (context);
diff --git a/src/tracker-store/tracker-statistics.c b/src/tracker-store/tracker-statistics.c
index 4080acd..c497328 100644
--- a/src/tracker-store/tracker-statistics.c
+++ b/src/tracker-store/tracker-statistics.c
@@ -75,13 +75,11 @@ tracker_statistics_get (TrackerStatistics      *object,
                         GError                **error)
 {
 	TrackerClass **classes, *cl;
-	guint                     request_id;
-	GPtrArray                *values;
-	guint                     i, n_classes;
+	TrackerDBusRequest *request;
+	GPtrArray *values;
+	guint i, n_classes;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
-	tracker_dbus_request_new (request_id, context, "%s()", __FUNCTION__);
+	request = tracker_dbus_g_request_begin (context, "%s()", __FUNCTION__);
 
 	values = g_ptr_array_new ();
 
@@ -108,7 +106,7 @@ tracker_statistics_get (TrackerStatistics      *object,
 	/* Sort result so it is alphabetical */
 	g_ptr_array_sort (values, cache_sort_func);
 
-	tracker_dbus_request_success (request_id, context);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context, values);
 
 	g_ptr_array_foreach (values, (GFunc) g_strfreev, NULL);
diff --git a/src/tracker-store/tracker-status.c b/src/tracker-store/tracker-status.c
index 418139d..5567644 100644
--- a/src/tracker-store/tracker-status.c
+++ b/src/tracker-store/tracker-status.c
@@ -189,10 +189,10 @@ tracker_status_get_progress  (TrackerStatus    *object,
                               GError                **error)
 {
 	TrackerStatusPrivate *priv = TRACKER_STATUS_GET_PRIVATE (object);
-	guint request_id;
+	TrackerDBusRequest *request;
 
-	request_id = tracker_dbus_get_next_request_id ();
-	tracker_dbus_request_success (request_id, context);
+	request = tracker_dbus_g_request_begin (context, "%s()", __FUNCTION__);
+	tracker_dbus_request_end (request, NULL);
 	dbus_g_method_return (context, priv->progress);
 
 	return;
@@ -205,10 +205,10 @@ tracker_status_get_status  (TrackerStatus    *object,
                             GError                **error)
 {
 	TrackerStatusPrivate *priv = TRACKER_STATUS_GET_PRIVATE (object);
-	guint request_id;
+	TrackerDBusRequest *request;
 
-	request_id = tracker_dbus_get_next_request_id ();
-	tracker_dbus_request_success (request_id, context);
+	request = tracker_dbus_g_request_begin (context, "%s()", __FUNCTION__);
+	tracker_dbus_request_end (request, NULL);
 
 	dbus_g_method_return (context, priv->status);
 
diff --git a/src/tracker-store/tracker-steroids.c b/src/tracker-store/tracker-steroids.c
index c7e3402..5cf3cd0 100644
--- a/src/tracker-store/tracker-steroids.c
+++ b/src/tracker-store/tracker-steroids.c
@@ -51,7 +51,7 @@ G_DEFINE_TYPE (TrackerSteroids, tracker_steroids, G_TYPE_OBJECT)
 typedef struct {
 	DBusMessage *call_message;
 	int fd;
-	guint request_id;
+	TrackerDBusRequest *request;
 	DBusConnection *connection;
 	struct {
 		int query_count;
@@ -104,10 +104,7 @@ query_callback (gpointer  inthread_data,
 
 	if (ptr && ptr->error) {
 		/* Client is still there, but query failed */
-		tracker_dbus_request_failed (info->request_id,
-		                             NULL,
-		                             &ptr->error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, ptr->error);
 		reply = dbus_message_new_error (info->call_message,
 		                                TRACKER_SPARQL_DBUS_ERROR,
 		                                ptr->error->message);
@@ -116,10 +113,7 @@ query_callback (gpointer  inthread_data,
 		g_error_free (ptr->error);
 	} else if (error) {
 		/* Client has disappeared */
-		tracker_dbus_request_failed (info->request_id,
-		                             NULL,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, error);
 		reply = dbus_message_new_error (info->call_message,
 		                                TRACKER_SPARQL_DBUS_ERROR,
 		                                error->message);
@@ -130,8 +124,7 @@ query_callback (gpointer  inthread_data,
 		DBusMessageIter iter, subiter;
 		guint i;
 
-		tracker_dbus_request_success (info->request_id,
-		                              NULL);
+		tracker_dbus_request_end (info->request, NULL);
 		reply = dbus_message_new_method_return (info->call_message);
 
 		dbus_message_iter_init_append (reply, &iter);
@@ -162,10 +155,7 @@ update_callback (GError *error, gpointer user_data)
 	DBusMessage *reply;
 
 	if (error) {
-		tracker_dbus_request_failed (info->request_id,
-		                             NULL,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, error);
 		reply = dbus_message_new_error (info->call_message,
 		                                TRACKER_SPARQL_DBUS_ERROR,
 		                                error->message);
@@ -174,7 +164,7 @@ update_callback (GError *error, gpointer user_data)
 		return;
 	}
 
-	tracker_dbus_request_success (info->request_id, NULL);
+	tracker_dbus_request_end (info->request, NULL);
 	reply = dbus_message_new_method_return (info->call_message);
 	dbus_connection_send (info->connection, reply, NULL);
 	dbus_message_unref (reply);
@@ -202,7 +192,7 @@ update_array_callback (GError *error, gpointer user_data)
 		guint i;
 		DBusMessageIter iter, subiter;
 
-		tracker_dbus_request_success (info->request_id, NULL);
+		tracker_dbus_request_end (info->request, NULL);
 		reply = dbus_message_new_method_return (info->call_message);
 
 		dbus_message_iter_init_append (reply, &iter);
@@ -277,10 +267,7 @@ update_blank_callback (GPtrArray *blank_nodes,
 	info = user_data;
 
 	if (error) {
-		tracker_dbus_request_failed (info->request_id,
-		                             NULL,
-		                             &error,
-		                             NULL);
+		tracker_dbus_request_end (info->request, error);
 		reply = dbus_message_new_error (info->call_message,
 		                                TRACKER_SPARQL_DBUS_ERROR,
 		                                error->message);
@@ -289,7 +276,7 @@ update_blank_callback (GPtrArray *blank_nodes,
 		return;
 	}
 
-	tracker_dbus_request_success (info->request_id, NULL);
+	tracker_dbus_request_end (info->request, NULL);
 	reply = dbus_message_new_method_return (info->call_message);
 	dbus_message_iter_init_append (reply, &iter);
 
@@ -463,7 +450,7 @@ steroids_query (TrackerSteroids *steroids,
                 DBusMessage     *message)
 {
 	ClientInfo *info;
-	guint request_id;
+	TrackerDBusRequest *request;
 	const gchar *sender;
 	const gchar *expected_signature;
 	DBusMessage *reply;
@@ -471,16 +458,9 @@ steroids_query (TrackerSteroids *steroids,
 	gchar *query;
 	int fd;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
 	expected_signature = DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UNIX_FD_AS_STRING;
 
 	if (g_strcmp0 (dbus_message_get_signature (message), expected_signature)) {
-		tracker_dbus_request_new (request_id,
-		                          NULL,
-		                          "%s()",
-		                          __FUNCTION__);
-
 		reply = dbus_message_new_error_printf (message,
 		                                       DBUS_ERROR_UNKNOWN_METHOD,
 		                                       UNKNOWN_METHOD_MESSAGE,
@@ -490,15 +470,6 @@ steroids_query (TrackerSteroids *steroids,
 		                                       expected_signature);
 		dbus_connection_send (connection, reply, NULL);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             UNKNOWN_METHOD_MESSAGE,
-		                             "Query",
-		                             dbus_message_get_signature (message),
-		                             dbus_message_get_interface (message),
-		                             expected_signature);
-
 		dbus_message_unref (reply);
 
 		return;
@@ -513,39 +484,28 @@ steroids_query (TrackerSteroids *steroids,
 	                       DBUS_TYPE_INVALID);
 
 	if (dbus_error_is_set (&dbus_error)) {
-		tracker_dbus_request_new (request_id,
-		                          NULL,
-		                          "%s()",
-		                          __FUNCTION__);
-
 		reply = dbus_message_new_error (message, dbus_error.name, dbus_error.message);
 		dbus_connection_send (connection, reply, NULL);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             dbus_error.message);
-
 		dbus_message_unref (reply);
 		dbus_error_free (&dbus_error);
 
 		return;
 	}
 
+	sender = dbus_message_get_sender (message);
+
+	request = tracker_dbus_request_begin (sender,
+	                                      "%s(query:'%s')",
+	                                      __FUNCTION__,
+	                                      query);
+
 	info = g_slice_new0 (ClientInfo);
 	info->connection = dbus_connection_ref (connection);
 	info->call_message = dbus_message_ref (message);
-	info->request_id = request_id;
+	info->request = request;
 	info->fd = fd;
 
-	tracker_dbus_request_new (request_id,
-	                          NULL,
-	                          "%s(query:'%s')",
-	                          __FUNCTION__,
-	                          query);
-
-	sender = dbus_message_get_sender (message);
-
 	tracker_store_sparql_query (query,
 	                            TRACKER_STORE_PRIORITY_HIGH,
 	                            query_inthread,
@@ -568,21 +528,14 @@ steroids_update (TrackerSteroids *steroids,
 	GDataInputStream *data_input_stream;
 	GError *error = NULL;
 	gsize bytes_read;
-	guint request_id;
+	TrackerDBusRequest *request;
 	const gchar *sender;
 	int query_size;
 	DBusMessage *reply;
 	gchar *query;
 	int fd;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
 	if (g_strcmp0 (dbus_message_get_signature (message), DBUS_TYPE_UNIX_FD_AS_STRING)) {
-		tracker_dbus_request_new (request_id,
-		                          NULL,
-		                          "%s()",
-		                          __FUNCTION__);
-
 		reply = dbus_message_new_error_printf (message,
 		                                       DBUS_ERROR_UNKNOWN_METHOD,
 		                                       UNKNOWN_METHOD_MESSAGE,
@@ -593,15 +546,6 @@ steroids_update (TrackerSteroids *steroids,
 		dbus_connection_send (connection, reply, NULL);
 		dbus_message_unref (reply);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             UNKNOWN_METHOD_MESSAGE,
-		                             "Update",
-		                             dbus_message_get_signature (message),
-		                             dbus_message_get_interface (message),
-		                             DBUS_TYPE_UNIX_FD_AS_STRING);
-
 		return;
 	}
 
@@ -613,39 +557,28 @@ steroids_update (TrackerSteroids *steroids,
 	                       DBUS_TYPE_INVALID);
 
 	if (dbus_error_is_set (&dbus_error)) {
-		tracker_dbus_request_new (request_id,
-		                          NULL,
-		                          "%s()",
-		                          __FUNCTION__);
-
 		reply = dbus_message_new_error (message, dbus_error.name, dbus_error.message);
 		dbus_connection_send (connection, reply, NULL);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             dbus_error.message);
-
 		dbus_message_unref (reply);
 		dbus_error_free (&dbus_error);
 
 		return;
 	}
 
-	tracker_dbus_request_new (request_id,
-	                          NULL,
-	                          "%s(fd:%d)",
-	                          __FUNCTION__,
-	                          fd);
+	sender = dbus_message_get_sender (message);
+
+	request = tracker_dbus_request_begin (sender,
+	                                      "%s(fd:%d)",
+	                                      __FUNCTION__,
+	                                      fd);
 
 	info = g_slice_new0 (ClientInfo);
 	info->connection = dbus_connection_ref (connection);
 	info->call_message = dbus_message_ref (message);
-	info->request_id = request_id;
+	info->request = request;
 	info->fd = fd;
 
-	sender = dbus_message_get_sender (message);
-
 	input_stream = g_unix_input_stream_new (info->fd, TRUE);
 	data_input_stream = g_data_input_stream_new (input_stream);
 	g_buffered_input_stream_set_buffer_size (G_BUFFERED_INPUT_STREAM (data_input_stream),
@@ -663,10 +596,7 @@ steroids_update (TrackerSteroids *steroids,
 		dbus_connection_send (connection, reply, NULL);
 		dbus_message_unref (reply);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             error->message);
+		tracker_dbus_request_end (request, error);
 
 		g_object_unref (data_input_stream);
 		g_object_unref (input_stream);
@@ -693,10 +623,7 @@ steroids_update (TrackerSteroids *steroids,
 		dbus_connection_send (connection, reply, NULL);
 		dbus_message_unref (reply);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             error->message);
+		tracker_dbus_request_end (request, error);
 
 		g_free (query);
 		g_object_unref (data_input_stream);
@@ -707,8 +634,7 @@ steroids_update (TrackerSteroids *steroids,
 		return;
 	}
 
-	tracker_dbus_request_debug (request_id,
-	                            NULL,
+	tracker_dbus_request_debug (request,
 	                            "query: '%s'",
 	                            query);
 
@@ -746,21 +672,14 @@ steroids_update_array (TrackerSteroids *steroids,
 	GInputStream *input_stream;
 	GDataInputStream *data_input_stream;
 	GError *error = NULL;
-	guint request_id;
+	TrackerDBusRequest *request;
 	const gchar *sender;
 	int i;
 	DBusMessage *reply;
 	int fd;
 	gchar **query_array;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
 	if (g_strcmp0 (dbus_message_get_signature (message), DBUS_TYPE_UNIX_FD_AS_STRING)) {
-		tracker_dbus_request_new (request_id,
-		                          NULL,
-		                          "%s()",
-		                          __FUNCTION__);
-
 		reply = dbus_message_new_error_printf (message,
 		                                       DBUS_ERROR_UNKNOWN_METHOD,
 		                                       UNKNOWN_METHOD_MESSAGE,
@@ -771,15 +690,6 @@ steroids_update_array (TrackerSteroids *steroids,
 		dbus_connection_send (connection, reply, NULL);
 		dbus_message_unref (reply);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             UNKNOWN_METHOD_MESSAGE,
-		                             "Update",
-		                             dbus_message_get_signature (message),
-		                             dbus_message_get_interface (message),
-		                             DBUS_TYPE_UNIX_FD_AS_STRING);
-
 		return;
 	}
 
@@ -791,39 +701,28 @@ steroids_update_array (TrackerSteroids *steroids,
 	                       DBUS_TYPE_INVALID);
 
 	if (dbus_error_is_set (&dbus_error)) {
-		tracker_dbus_request_new (request_id,
-		                          NULL,
-		                          "%s()",
-		                          __FUNCTION__);
-
 		reply = dbus_message_new_error (message, dbus_error.name, dbus_error.message);
 		dbus_connection_send (connection, reply, NULL);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             dbus_error.message);
-
 		dbus_message_unref (reply);
 		dbus_error_free (&dbus_error);
 
 		return;
 	}
 
-	tracker_dbus_request_new (request_id,
-	                          NULL,
-	                          "%s(fd:%d)",
-	                          __FUNCTION__,
-	                          fd);
+	sender = dbus_message_get_sender (message);
+
+	request = tracker_dbus_request_begin (sender,
+	                                      "%s(fd:%d)",
+	                                      __FUNCTION__,
+	                                      fd);
 
 	info = g_slice_new0 (ClientInfo);
 	info->connection = dbus_connection_ref (connection);
 	info->call_message = dbus_message_ref (message);
-	info->request_id = request_id;
+	info->request = request;
 	info->fd = fd;
 
-	sender = dbus_message_get_sender (message);
-
 	input_stream = g_unix_input_stream_new (info->fd, TRUE);
 	data_input_stream = g_data_input_stream_new (input_stream);
 	g_data_input_stream_set_byte_order (data_input_stream, G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN);
@@ -841,10 +740,7 @@ steroids_update_array (TrackerSteroids *steroids,
 		dbus_connection_send (connection, reply, NULL);
 		dbus_message_unref (reply);
 
-		tracker_dbus_request_failed (request_id,
-		                             NULL,
-		                             NULL,
-		                             error->message);
+		tracker_dbus_request_end (request, error);
 
 		g_object_unref (data_input_stream);
 		g_object_unref (input_stream);
@@ -872,10 +768,7 @@ steroids_update_array (TrackerSteroids *steroids,
 			dbus_connection_send (connection, reply, NULL);
 			dbus_message_unref (reply);
 
-			tracker_dbus_request_failed (request_id,
-			                             NULL,
-			                             NULL,
-			                             error->message);
+			tracker_dbus_request_end (request, error);
 
 			g_strfreev (query_array);
 			g_object_unref (data_input_stream);
@@ -903,10 +796,7 @@ steroids_update_array (TrackerSteroids *steroids,
 			dbus_connection_send (connection, reply, NULL);
 			dbus_message_unref (reply);
 
-			tracker_dbus_request_failed (request_id,
-			                             NULL,
-			                             NULL,
-			                             error->message);
+			tracker_dbus_request_end (request, error);
 
 			g_strfreev (query_array);
 			g_object_unref (data_input_stream);
@@ -924,8 +814,7 @@ steroids_update_array (TrackerSteroids *steroids,
 
 	for (i = 0; query_array[i] != NULL; i++) {
 
-		tracker_dbus_request_debug (request_id,
-		                            NULL,
+		tracker_dbus_request_debug (request,
 		                            "query: '%s'",
 		                            query_array[i]);
 
diff --git a/tests/libtracker-common/tracker-dbus-test.c b/tests/libtracker-common/tracker-dbus-test.c
index c34c2bb..730e464 100644
--- a/tests/libtracker-common/tracker-dbus-test.c
+++ b/tests/libtracker-common/tracker-dbus-test.c
@@ -88,6 +88,7 @@ test_async_queue_to_strv_nonutf8 (void)
 static void
 test_dbus_request_failed (void)
 {
+	TrackerDBusRequest *request;
 	GError *error = NULL;
 
         /* 
@@ -95,63 +96,39 @@ test_dbus_request_failed (void)
          * coverage evaluation.
          */
 
-	/* Default case: we set the error */
-	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-		tracker_dbus_request_failed (1, NULL, &error, "Test Error message");
-	}
-	g_test_trap_assert_stderr ("*Test Error message*");
+	request = tracker_dbus_request_begin (NULL, "%s()", __PRETTY_FUNCTION__);
 
-	/* Second common case: we have already the error and want only the log line */
+	/* We have already the error and want only the log line */
 	error = g_error_new (1000, -1, "The indexer founded an error");
 	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-		tracker_dbus_request_failed (1, NULL, &error, NULL);
+		tracker_dbus_request_end (request, error);
 	}
 	g_test_trap_assert_stderr ("*The indexer founded an error*");
 	g_error_free (error);
-
-
-	/* Wrong use: error set and we add a new message */
-	error = g_error_new (1000, -1, "The indexer founded an error");
-	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-		tracker_dbus_request_failed (1, NULL, &error, "Dont do this");
-	}
-	g_test_trap_assert_stderr ("*GError set over the top of a previous GError or uninitialized memory*");
-	g_error_free (error);
-
-	error = NULL;
-	/* Wrong use: no error, no message */
-	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-		tracker_dbus_request_failed (1, NULL, &error, NULL);
-	}
-
-	g_test_trap_assert_stderr ("*Unset error and no error message*");
 }
 
 static void
 test_dbus_request ()
 {
-        guint request_id, next_request_id;
+        TrackerDBusRequest *request;
         DBusGMethodInvocation *context = (DBusGMethodInvocation *)g_strdup ("aaa");
 
         tracker_dbus_enable_client_lookup (FALSE);
 
-        /* Ridicoulos but well... */
-        request_id = tracker_dbus_get_next_request_id ();
-        next_request_id = tracker_dbus_get_next_request_id ();
-        g_assert_cmpint (next_request_id, >, request_id);
-
         /* Checking the logging output */
         if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-                tracker_dbus_request_new (request_id, context, 
-                                          "Test request (%s))", "--TestNewOK--");
+                tracker_dbus_g_request_begin (context,
+                                                        "Test request (%s))", "--TestNewOK--");
                 exit (0);
         }
         g_test_trap_assert_passed ();
         g_test_trap_assert_stdout ("*TestNewOK*");
 
+        request = tracker_dbus_g_request_begin (context,
+                                                "Test request (%s))", "--TestNewOK--");
 
         if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-                tracker_dbus_request_comment (request_id, context, 
+                tracker_dbus_request_comment (request,
                                               "Well (%s)", "--TestCommentOK--");
                 exit (0);
         }
@@ -160,7 +137,7 @@ test_dbus_request ()
 
           
         if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-                tracker_dbus_request_success (request_id, context);
+                tracker_dbus_request_end (request, NULL);
                 exit (0);
         }
         g_test_trap_assert_passed ();
@@ -170,25 +147,27 @@ test_dbus_request ()
 static void
 test_dbus_request_client_lookup ()
 {
-        guint request_id;
+        TrackerDBusRequest *request;
         DBusGMethodInvocation *context = (DBusGMethodInvocation *)g_strdup ("aaa");
 
         tracker_dbus_enable_client_lookup (TRUE);
 
-        request_id = tracker_dbus_get_next_request_id ();
 
         /* Checking the logging output */
         if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-                tracker_dbus_request_new (request_id, context, 
-                                          "Test request (%s))", "--TestNewOK--");
+                tracker_dbus_g_request_begin (context,
+                                              "Test request (%s))", "--TestNewOK--");
                 exit (0);
         }
         g_test_trap_assert_passed ();
         g_test_trap_assert_stdout ("*TestNewOK*");
         g_test_trap_assert_stdout ("*lt-tracker-dbus*");
 
+        request = tracker_dbus_g_request_begin (context,
+                                                "Test request (%s))", "--TestNewOK--");
+
         if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-                tracker_dbus_request_comment (request_id, context, 
+                tracker_dbus_request_comment (request,
                                               "Well (%s)", "--TestCommentOK--");
                 exit (0);
         }
@@ -198,7 +177,7 @@ test_dbus_request_client_lookup ()
 
 
         if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-                tracker_dbus_request_info (request_id, context, 
+                tracker_dbus_request_info (request,
                                            "Test info %s", "--TestInfoOK--");
                 exit (0);
         }
@@ -207,7 +186,7 @@ test_dbus_request_client_lookup ()
         g_test_trap_assert_stdout ("*lt-tracker-dbus*");
 
         if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-                tracker_dbus_request_debug (request_id, context, 
+                tracker_dbus_request_debug (request,
                                             "Test debug %s", "--TestDebugOK--");
                 exit (0);
         }
@@ -216,7 +195,7 @@ test_dbus_request_client_lookup ()
         g_test_trap_assert_stdout ("*lt-tracker-dbus*");
 
         if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-                tracker_dbus_request_success (request_id, context);
+                tracker_dbus_request_end (request, NULL);
                 exit (0);
         }
         g_test_trap_assert_passed ();
@@ -231,7 +210,7 @@ test_dbus_request_client_lookup ()
 static void
 test_dbus_request_client_lookup_monothread ()
 {
-        guint request_id;
+        TrackerDBusRequest *request;
         DBusGMethodInvocation *context = (DBusGMethodInvocation *)g_strdup ("aaa");
 
         /*
@@ -242,18 +221,17 @@ test_dbus_request_client_lookup_monothread ()
         
                 tracker_dbus_enable_client_lookup (TRUE);
 
-                request_id = tracker_dbus_get_next_request_id ();
-                tracker_dbus_request_new (request_id, context, 
-                                          "Test request (%s))", "--TestNewOK--");
-                tracker_dbus_request_comment (request_id, context, 
+                request = tracker_dbus_g_request_begin (context,
+                                                        "Test request (%s))", "--TestNewOK--");
+                tracker_dbus_request_comment (request,
                                               "Well (%s)", "--TestCommentOK--");
 /*
-                tracker_dbus_request_failed (request_id, context, NULL,
+                tracker_dbus_request_end (request, NULL,
                                              "--TestFailedOK--");
                 tracker_quark = tracker_dbus_error_quark ();
                 error = g_error_new (tracker_quark, -1, "test_using_g_error");
-                tracker_dbus_request_failed (tracker_quark, error);
-*/                tracker_dbus_request_success (request_id, context);
+                tracker_dbus_request_end (tracker_quark, error);
+*/                tracker_dbus_request_end (request, NULL);
                 
                 /* Force client shutdown */
                 tracker_dbus_enable_client_lookup (FALSE);
@@ -266,7 +244,7 @@ static void
 test_dbus_request_failed_coverage ()
 {
         GQuark tracker_quark;
-        guint request_id;
+        TrackerDBusRequest *request;
         GError *error = NULL;
         DBusGMethodInvocation *context = (DBusGMethodInvocation *)g_strdup ("aaa");
 
@@ -278,19 +256,16 @@ test_dbus_request_failed_coverage ()
         
                 tracker_dbus_enable_client_lookup (TRUE);
 
-                request_id = tracker_dbus_get_next_request_id ();
-                tracker_dbus_request_new (request_id, context, 
-                                          "Test request (%s))", "--TestNewOK--");
-                /* direct message */
-                tracker_dbus_request_failed (request_id, context, NULL,
-                                             "--TestFailedOK--");
-
                 /* Using GError */
+                request = tracker_dbus_g_request_begin (context,
+                                                        "Test request (%s))", "--TestNewOK--");
                 tracker_quark = tracker_dbus_error_quark ();
                 error = g_error_new (tracker_quark, -1, "test_using_g_error");
-                tracker_dbus_request_failed (request_id, context, &error, NULL);
+                tracker_dbus_request_end (request, error);
 
-                tracker_dbus_request_success (request_id, context);
+                request = tracker_dbus_g_request_begin (context,
+                                                        "Test request (%s))", "--TestNewOK--");
+                tracker_dbus_request_end (request, NULL);
                 
                 /* Force client shutdown */
                 tracker_dbus_enable_client_lookup (FALSE);



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