[tracker/dbus-fd-experiment: 21/49] libtracker-client, tracker-store: Handling D-Bus errors right



commit c02ce45957aa0a64a53242d28354065bc7af3617
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Jun 15 16:23:40 2010 +0200

    libtracker-client, tracker-store: Handling D-Bus errors right

 src/libtracker-client/tracker.c      |   32 +++++++++++++++++++-------------
 src/tracker-store/tracker-steroids.c |   19 ++++++++++++++++++-
 2 files changed, 37 insertions(+), 14 deletions(-)
---
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index 610bbb3..54f8a85 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -43,6 +43,7 @@
 
 #include "tracker-resources-glue.h"
 #include "tracker-statistics-glue.h"
+#define HAVE_DBUS_FD_PASSING
 
 /* sleep delay to emulate dbus_pending_call_block, in us */
 #define NOT_TOO_SHORT_DELAY 1000
@@ -513,15 +514,12 @@ fast_async_callback_iterator (GObject      *source_object,
                               gpointer      user_data)
 {
 	DBusMessage *reply;
-	DBusError dbus_error;
 	GError *inner_error = NULL;
 	GError *error = NULL;
 	FastAsyncData *data = user_data;
 	TrackerResultIterator *iterator = data->result_iterator;
 	GInputStream *base_input_stream;
 
-	dbus_error_init (&dbus_error);
-
 	iterator->buffer_size = g_output_stream_splice_finish (data->output_stream,
 	                                                       result,
 	                                                       &inner_error);
@@ -562,10 +560,16 @@ fast_async_callback_iterator (GObject      *source_object,
 	g_assert (reply);
 
 	if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		DBusError dbus_error;
+
+		dbus_error_init (&dbus_error);
+
 		dbus_set_error_from_message (&dbus_error, reply);
 		dbus_set_g_error (&error, &dbus_error);
 		dbus_pending_call_unref (data->dbus_call);
 		(* data->iterator_callback) (NULL, error, data->user_data);
+		dbus_error_free (&dbus_error);
+
 		return ;
 	}
 
@@ -888,20 +892,22 @@ sparql_update_fast_callback (DBusPendingCall *call,
 {
 	FastAsyncData *data = user_data;
 	DBusMessage *reply;
-	DBusError dbus_error;
 	GError *error = NULL;
 	DBusMessageIter iter, subiter, subsubiter;
 	GPtrArray *result;
 
-	dbus_error_init (&dbus_error);
 
 	reply = dbus_pending_call_steal_reply (call);
 
 	g_assert (reply);
 
 	if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		DBusError dbus_error;
+
+		dbus_error_init (&dbus_error);
 		dbus_set_error_from_message (&dbus_error, reply);
 		dbus_set_g_error (&error, &dbus_error);
+		dbus_error_free (&dbus_error);
 
 		switch (data->operation) {
 		case FAST_UPDATE:
@@ -966,7 +972,7 @@ sparql_update_fast_send (TrackerClient      *client,
 {
 	TrackerClientPrivate *private;
 	DBusConnection *connection;
-	gchar *dbus_method;
+	const gchar *dbus_method;
 	DBusMessage *message;
 	DBusMessageIter iter;
 	DBusPendingCall *call;
@@ -1086,10 +1092,11 @@ sparql_update_fast (TrackerClient      *client,
 		DBusError dbus_error;
 
 		dbus_error_init (&dbus_error);
-
 		dbus_set_error_from_message (&dbus_error, reply);
 		dbus_set_g_error (error, &dbus_error);
 		dbus_pending_call_unref (call);
+		dbus_error_free (&dbus_error);
+
 		return NULL;
 	}
 
@@ -1563,7 +1570,6 @@ tracker_resources_sparql_query_iterate (TrackerClient  *client,
 	DBusMessageIter iter;
 	DBusMessage *reply;
 	DBusPendingCall *call;
-	DBusError dbus_error;
 	TrackerResultIterator *iterator;
 	int pipefd[2];
 	GInputStream *input_stream;
@@ -1586,8 +1592,6 @@ tracker_resources_sparql_query_iterate (TrackerClient  *client,
 
 	connection = dbus_g_connection_get_connection (private->connection);
 
-	dbus_error_init (&dbus_error);
-
 	message = dbus_message_new_method_call (TRACKER_STEROIDS_SERVICE,
 	                                        TRACKER_STEROIDS_PATH,
 	                                        TRACKER_STEROIDS_INTERFACE,
@@ -1655,9 +1659,14 @@ tracker_resources_sparql_query_iterate (TrackerClient  *client,
 	g_assert (reply);
 
 	if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		DBusError dbus_error;
+
+		dbus_error_init (&dbus_error);
 		dbus_set_error_from_message (&dbus_error, reply);
 		dbus_set_g_error (error, &dbus_error);
 		dbus_pending_call_unref (call);
+		dbus_error_free (&dbus_error);
+
 		return NULL;
 	}
 
@@ -2204,7 +2213,6 @@ tracker_resources_sparql_query_iterate_async (TrackerClient         *client,
 	DBusMessage *message;
 	DBusMessageIter iter;
 	DBusPendingCall *call;
-	DBusError dbus_error;
 	TrackerResultIterator *iterator;
 	int pipefd[2];
 	GInputStream *input_stream;
@@ -2224,8 +2232,6 @@ tracker_resources_sparql_query_iterate_async (TrackerClient         *client,
 
 	connection = dbus_g_connection_get_connection (private->connection);
 
-	dbus_error_init (&dbus_error);
-
 	message = dbus_message_new_method_call (TRACKER_STEROIDS_SERVICE,
 	                                        TRACKER_STEROIDS_PATH,
 	                                        TRACKER_STEROIDS_INTERFACE,
diff --git a/src/tracker-store/tracker-steroids.c b/src/tracker-store/tracker-steroids.c
index 47a46ba..a0f94b7 100644
--- a/src/tracker-store/tracker-steroids.c
+++ b/src/tracker-store/tracker-steroids.c
@@ -412,6 +412,15 @@ tracker_steroids_query (TrackerSteroids *steroids,
 	                       DBUS_TYPE_UNIX_FD, &info->fd,
 	                       DBUS_TYPE_INVALID);
 
+	if (dbus_error_is_set (&dbus_error)) {
+		reply = dbus_message_new_error (message, dbus_error.name, dbus_error.message);
+		dbus_connection_send (connection, reply, NULL);
+		dbus_message_unref (reply);
+		dbus_error_free (&dbus_error);
+		destroy_client_info (info);
+		return;
+	}
+
 	sender = dbus_message_get_sender (message);
 
 	tracker_store_sparql_query (query, TRACKER_STORE_PRIORITY_HIGH,
@@ -460,6 +469,7 @@ tracker_steroids_update (TrackerSteroids *steroids,
 	info = g_slice_new0 (ClientInfo);
 	info->connection = dbus_connection_ref (connection);
 	info->call_message = dbus_message_ref (message);
+	info->request_id = request_id;
 
 	dbus_error_init (&dbus_error);
 
@@ -468,7 +478,14 @@ tracker_steroids_update (TrackerSteroids *steroids,
 	                       DBUS_TYPE_UNIX_FD, &info->fd,
 	                       DBUS_TYPE_INVALID);
 
-	info->request_id = request_id;
+	if (dbus_error_is_set (&dbus_error)) {
+		reply = dbus_message_new_error (message, dbus_error.name, dbus_error.message);
+		dbus_connection_send (connection, reply, NULL);
+		dbus_message_unref (reply);
+		dbus_error_free (&dbus_error);
+		destroy_client_info (info);
+		return;
+	}
 
 	sender = dbus_message_get_sender (message);
 



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