[tracker/gdbus: 68/92] libtracker-common, miner-fs: Move uniquely called API to unique user



commit 650dc0ebc59fbe842391d7c092ae8b58fb497223
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Jan 7 13:13:44 2011 +0100

    libtracker-common, miner-fs: Move uniquely called API to unique user

 src/libtracker-common/tracker-dbus.c |  149 ------------------------------
 src/libtracker-common/tracker-dbus.h |   12 ---
 src/miners/fs/tracker-miner-files.c  |  166 ++++++++++++++++++++++++++++++++--
 3 files changed, 160 insertions(+), 167 deletions(-)
---
diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index 93cfead..25f01ad 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -46,15 +46,6 @@ struct _TrackerDBusRequest {
 	ClientData *cd;
 };
 
-typedef struct {
-	GInputStream *unix_input_stream;
-	GInputStream *buffered_input_stream;
-	GOutputStream *output_stream;
-	TrackerDBusSendAndSpliceCallback callback;
-	GCancellable *cancellable;
-	gpointer user_data;
-} SendAndSpliceData;
-
 static gboolean client_lookup_enabled;
 static DBusGConnection *freedesktop_connection;
 static DBusGProxy *freedesktop_proxy;
@@ -462,143 +453,3 @@ tracker_dbus_g_request_begin (DBusGMethodInvocation *context,
 
 	return request;
 }
-
-static SendAndSpliceData *
-send_and_splice_data_new (GInputStream                     *unix_input_stream,
-                          GInputStream                     *buffered_input_stream,
-                          GOutputStream                    *output_stream,
-                          GCancellable                     *cancellable,
-                          TrackerDBusSendAndSpliceCallback  callback,
-                          gpointer                          user_data)
-{
-	SendAndSpliceData *data;
-
-	data = g_slice_new0 (SendAndSpliceData);
-	data->unix_input_stream = unix_input_stream;
-	data->buffered_input_stream = buffered_input_stream;
-	data->output_stream = output_stream;
-	if (cancellable) {
-		data->cancellable = g_object_ref (cancellable);
-	}
-	data->callback = callback;
-	data->user_data = user_data;
-
-	return data;
-}
-
-static void
-send_and_splice_data_free (SendAndSpliceData *data)
-{
-	g_object_unref (data->unix_input_stream);
-	g_object_unref (data->buffered_input_stream);
-	g_object_unref (data->output_stream);
-	if (data->cancellable) {
-		g_object_unref (data->cancellable);
-	}
-	g_slice_free (SendAndSpliceData, data);
-}
-
-static void
-send_and_splice_async_callback (GObject      *source,
-                                GAsyncResult *result,
-                                gpointer      user_data)
-{
-	GError *error = NULL;
-
-	g_output_stream_splice_finish (G_OUTPUT_STREAM (source), result, &error);
-
-	if (error) {
-		g_critical ("Error while splicing: %s",
-		            error ? error->message : "Error not specified");
-		g_error_free (error);
-	}
-}
-
-static void
-tracker_dbus_send_and_splice_async_finish (GObject      *source,
-                                           GAsyncResult *result,
-                                           gpointer      user_data)
-{
-	SendAndSpliceData *data = user_data;
-	GDBusMessage *reply;
-	GError *error = NULL;
-
-	reply = g_dbus_connection_send_message_with_reply_finish (G_DBUS_CONNECTION (source),
-	                                                          result, &error);
-
-	if (!error) {
-		if (g_dbus_message_get_message_type (reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
-
-			g_dbus_message_to_gerror (reply, &error);
-			g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)));
-			(* data->callback) (NULL, -1, error, data->user_data);
-			g_error_free (error);
-		} else {
-			(* data->callback) (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
-			                    g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
-			                    NULL,
-			                    data->user_data);
-		}
-	} else {
-		g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)));
-		(* data->callback) (NULL, -1, error, data->user_data);
-		g_error_free (error);
-	}
-
-	if (reply) {
-		g_object_unref (reply);
-	}
-
-	send_and_splice_data_free (data);
-}
-
-gboolean
-tracker_dbus_send_and_splice_async (GDBusConnection                  *connection,
-                                    GDBusMessage                     *message,
-                                    int                               fd,
-                                    GCancellable                     *cancellable,
-                                    TrackerDBusSendAndSpliceCallback  callback,
-                                    gpointer                          user_data)
-{
-	SendAndSpliceData *data;
-	GInputStream *unix_input_stream;
-	GInputStream *buffered_input_stream;
-	GOutputStream *output_stream;
-
-	g_return_val_if_fail (connection != NULL, FALSE);
-	g_return_val_if_fail (message != NULL, FALSE);
-	g_return_val_if_fail (fd > 0, FALSE);
-	g_return_val_if_fail (callback != NULL, FALSE);
-
-	unix_input_stream = g_unix_input_stream_new (fd, TRUE);
-	buffered_input_stream = g_buffered_input_stream_new_sized (unix_input_stream,
-	                                                           TRACKER_DBUS_PIPE_BUFFER_SIZE);
-	output_stream = g_memory_output_stream_new (NULL, 0, g_realloc, NULL);
-
-	data = send_and_splice_data_new (unix_input_stream,
-	                                 buffered_input_stream,
-	                                 output_stream,
-	                                 cancellable,
-	                                 callback,
-	                                 user_data);
-
-	g_dbus_connection_send_message_with_reply (connection,
-	                                           message,
-	                                           G_DBUS_SEND_MESSAGE_FLAGS_NONE,
-	                                           -1,
-	                                           NULL,
-	                                           cancellable,
-	                                           tracker_dbus_send_and_splice_async_finish,
-	                                           data);
-
-	g_output_stream_splice_async (data->output_stream,
-	                              data->buffered_input_stream,
-	                              G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
-	                              G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
-	                              0,
-	                              data->cancellable,
-	                              send_and_splice_async_callback,
-	                              data);
-
-	return TRUE;
-}
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index 5f6830f..6391a5b 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -117,11 +117,6 @@ G_BEGIN_DECLS
 #define TRACKER_DBUS_PATH_EXTRACT      "/org/freedesktop/Tracker1/Extract"
 #define TRACKER_DBUS_INTERFACE_EXTRACT "org.freedesktop.Tracker1.Extract"
 
-typedef void (*TrackerDBusSendAndSpliceCallback) (void     *buffer,
-                                                  gssize    buffer_size,
-                                                  GError   *error, /* Don't free */
-                                                  gpointer  user_data);
-
 typedef struct _TrackerDBusRequest TrackerDBusRequest;
 
 typedef enum {
@@ -169,13 +164,6 @@ TrackerDBusRequest *tracker_dbus_g_request_begin       (DBusGMethodInvocation
                                                         const gchar                *format,
                                                         ...);
 
-gboolean            tracker_dbus_send_and_splice_async (GDBusConnection            *connection,
-                                                        GDBusMessage               *message,
-                                                        int                         fd,
-                                                        GCancellable               *cancellable,
-                                                        TrackerDBusSendAndSpliceCallback callback,
-                                                        gpointer                    user_data);
-
 G_END_DECLS
 
 #endif /* __LIBTRACKER_COMMON_DBUS_H__ */
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index f5268bd..63ac81d 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -81,6 +81,20 @@ typedef void (*fast_async_cb) (gchar    *preupdate,
                                GError   *error,
                                gpointer  user_data);
 
+typedef void (*TrackerDBusSendAndSpliceCallback) (void     *buffer,
+                                                  gssize    buffer_size,
+                                                  GError   *error, /* Don't free */
+                                                  gpointer  user_data);
+
+typedef struct {
+	GInputStream *unix_input_stream;
+	GInputStream *buffered_input_stream;
+	GOutputStream *output_stream;
+	TrackerDBusSendAndSpliceCallback callback;
+	GCancellable *cancellable;
+	gpointer user_data;
+} SendAndSpliceData;
+
 typedef struct {
 	fast_async_cb callback;
 	gpointer user_data;
@@ -1945,6 +1959,146 @@ extractor_get_embedded_metadata_cancel (GCancellable    *cancellable,
 	g_error_free (error);
 }
 
+static SendAndSpliceData *
+send_and_splice_data_new (GInputStream                     *unix_input_stream,
+                          GInputStream                     *buffered_input_stream,
+                          GOutputStream                    *output_stream,
+                          GCancellable                     *cancellable,
+                          TrackerDBusSendAndSpliceCallback  callback,
+                          gpointer                          user_data)
+{
+	SendAndSpliceData *data;
+
+	data = g_slice_new0 (SendAndSpliceData);
+	data->unix_input_stream = unix_input_stream;
+	data->buffered_input_stream = buffered_input_stream;
+	data->output_stream = output_stream;
+	if (cancellable) {
+		data->cancellable = g_object_ref (cancellable);
+	}
+	data->callback = callback;
+	data->user_data = user_data;
+
+	return data;
+}
+
+static void
+send_and_splice_data_free (SendAndSpliceData *data)
+{
+	g_object_unref (data->unix_input_stream);
+	g_object_unref (data->buffered_input_stream);
+	g_object_unref (data->output_stream);
+	if (data->cancellable) {
+		g_object_unref (data->cancellable);
+	}
+	g_slice_free (SendAndSpliceData, data);
+}
+
+static void
+send_and_splice_async_callback (GObject      *source,
+                                GAsyncResult *result,
+                                gpointer      user_data)
+{
+	GError *error = NULL;
+
+	g_output_stream_splice_finish (G_OUTPUT_STREAM (source), result, &error);
+
+	if (error) {
+		g_critical ("Error while splicing: %s",
+		            error ? error->message : "Error not specified");
+		g_error_free (error);
+	}
+}
+
+static void
+dbus_send_and_splice_async_finish (GObject      *source,
+                                   GAsyncResult *result,
+                                   gpointer      user_data)
+{
+	SendAndSpliceData *data = user_data;
+	GDBusMessage *reply;
+	GError *error = NULL;
+
+	reply = g_dbus_connection_send_message_with_reply_finish (G_DBUS_CONNECTION (source),
+	                                                          result, &error);
+
+	if (!error) {
+		if (g_dbus_message_get_message_type (reply) == G_DBUS_MESSAGE_TYPE_ERROR) {
+
+			g_dbus_message_to_gerror (reply, &error);
+			g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)));
+			(* data->callback) (NULL, -1, error, data->user_data);
+			g_error_free (error);
+		} else {
+			(* data->callback) (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
+			                    g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
+			                    NULL,
+			                    data->user_data);
+		}
+	} else {
+		g_free (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)));
+		(* data->callback) (NULL, -1, error, data->user_data);
+		g_error_free (error);
+	}
+
+	if (reply) {
+		g_object_unref (reply);
+	}
+
+	send_and_splice_data_free (data);
+}
+
+static gboolean
+dbus_send_and_splice_async (GDBusConnection                  *connection,
+                            GDBusMessage                     *message,
+                            int                               fd,
+                            GCancellable                     *cancellable,
+                            TrackerDBusSendAndSpliceCallback  callback,
+                            gpointer                          user_data)
+{
+	SendAndSpliceData *data;
+	GInputStream *unix_input_stream;
+	GInputStream *buffered_input_stream;
+	GOutputStream *output_stream;
+
+	g_return_val_if_fail (connection != NULL, FALSE);
+	g_return_val_if_fail (message != NULL, FALSE);
+	g_return_val_if_fail (fd > 0, FALSE);
+	g_return_val_if_fail (callback != NULL, FALSE);
+
+	unix_input_stream = g_unix_input_stream_new (fd, TRUE);
+	buffered_input_stream = g_buffered_input_stream_new_sized (unix_input_stream,
+	                                                           TRACKER_DBUS_PIPE_BUFFER_SIZE);
+	output_stream = g_memory_output_stream_new (NULL, 0, g_realloc, NULL);
+
+	data = send_and_splice_data_new (unix_input_stream,
+	                                 buffered_input_stream,
+	                                 output_stream,
+	                                 cancellable,
+	                                 callback,
+	                                 user_data);
+
+	g_dbus_connection_send_message_with_reply (connection,
+	                                           message,
+	                                           G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+	                                           -1,
+	                                           NULL,
+	                                           cancellable,
+	                                           dbus_send_and_splice_async_finish,
+	                                           data);
+
+	g_output_stream_splice_async (data->output_stream,
+	                              data->buffered_input_stream,
+	                              G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
+	                              G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+	                              0,
+	                              data->cancellable,
+	                              send_and_splice_async_callback,
+	                              data);
+
+	return TRUE;
+}
+
 static FastAsyncData*
 fast_async_data_new (fast_async_cb  callback,
                      gpointer       user_data)
@@ -2044,12 +2198,12 @@ get_metadata_fast_async (GDBusConnection *connection,
 	data = fast_async_data_new (callback,
 	                            user_data);
 
-	tracker_dbus_send_and_splice_async (connection,
-	                                    message,
-	                                    pipefd[0],
-	                                    cancellable,
-	                                    get_metadata_fast_cb,
-	                                    data);
+	dbus_send_and_splice_async (connection,
+	                            message,
+	                            pipefd[0],
+	                            cancellable,
+	                            get_metadata_fast_cb,
+	                            data);
 }
 
 static void



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