[tracker/gdbus-porting-rebased: 49/65] tracker-extract: GDBus porting of GetMetadataFast in extract service



commit 06c063614721e933304a0f07b86b7d889434d703
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Jan 6 13:03:09 2011 +0100

    tracker-extract: GDBus porting of GetMetadataFast in extract service

 src/tracker-extract/tracker-extract.c |  108 ++++++++++++++-------------------
 1 files changed, 46 insertions(+), 62 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 3a88077..dede7a6 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -59,6 +59,11 @@ static const gchar introspection_xml[] =
   "      <arg type='s' name='preupdate' direction='out' />"
   "      <arg type='s' name='embedded' direction='out' />"
   "    </method>"
+  "    <method name='GetMetadataFast'>"
+  "      <arg type='s' name='uri' direction='in' />"
+  "      <arg type='s' name='mime' direction='in' />"
+  "      <arg type='h' name='fd' direction='in' />"
+  "    </method>"
   "  </interface>"
   "</node>";
 
@@ -759,19 +764,15 @@ handle_method_call_get_metadata (TrackerExtract        *object,
 	}
 }
 
-#if 0
 static void
-get_metadata_fast (TrackerExtract *object,
-                   DBusConnection *connection,
-                   DBusMessage    *message)
+handle_method_call_get_metadata_fast (TrackerExtract        *object,
+                                      GDBusMethodInvocation *invocation,
+                                      GVariant              *parameters)
 {
-	// todo: port to GDBus
-
 	TrackerDBusRequest *request;
 	const gchar *expected_signature;
 	TrackerExtractPrivate *priv;
-	DBusError dbus_error;
-	DBusMessage *reply;
+	GDBusMessage *reply;
 	const gchar *uri, *mime;
 	int fd;
 	GOutputStream *unix_output_stream;
@@ -780,51 +781,38 @@ get_metadata_fast (TrackerExtract *object,
 	GError *error = NULL;
 	TrackerSparqlBuilder *sparql, *preupdate;
 	gboolean extracted = FALSE;
+	GDBusMessage *method_message;
+	GDBusConnection *connection;
 
+	connection = g_dbus_method_invocation_get_connection (invocation);
+	method_message = g_dbus_method_invocation_get_message (invocation);
 
-	expected_signature = DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UNIX_FD_AS_STRING;
+	expected_signature = "ssh";
 
-	if (g_strcmp0 (dbus_message_get_signature (message), expected_signature)) {
-		gchar *error_message = g_strdup_printf (UNKNOWN_METHOD_MESSAGE,
-		                                        "GetMetadataFast",
-		                                        dbus_message_get_signature (message),
-		                                        dbus_message_get_interface (message),
-		                                        expected_signature);
-		reply = dbus_message_new_error (message,
-		                                DBUS_ERROR_UNKNOWN_METHOD,
-		                                error_message);
-		dbus_connection_send (connection, reply, NULL);
+	if (g_strcmp0 (g_dbus_message_get_signature (method_message), expected_signature)) {
+		reply = g_dbus_message_new_method_error (method_message,
+		                                         "Unknown method",
+		                                         UNKNOWN_METHOD_MESSAGE,
+		                                         g_dbus_message_get_signature (method_message),
+		                                         g_dbus_message_get_interface (method_message),
+		                                         expected_signature);
 
-		dbus_message_unref (reply);
-		g_free (error_message);
+		g_dbus_connection_send_message (connection, reply,
+		                                G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+		                                NULL, NULL);
 
+		g_object_unref (reply);
 		return;
 	}
 
-	dbus_error_init (&dbus_error);
-
-	dbus_message_get_args (message,
-	                       &dbus_error,
-	                       DBUS_TYPE_STRING, &uri,
-	                       DBUS_TYPE_STRING, &mime,
-	                       DBUS_TYPE_UNIX_FD, &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);
+	g_variant_get (parameters, "(&s&sh)", &uri, &mime, &fd);
 
-		dbus_message_unref (reply);
-		dbus_error_free (&dbus_error);
 
-		return;
-	}
-
-	request = tracker_dbus_request_begin (dbus_message_get_sender (message),
-	                                      "%s(uri:'%s', mime:%s)",
-	                                      __FUNCTION__,
-	                                      uri,
-	                                      mime);
+	request = tracker_g_dbus_request_begin (invocation,
+	                                        "%s(uri:'%s', mime:%s)",
+	                                        __FUNCTION__,
+	                                        uri,
+	                                        mime);
 
 	tracker_dbus_request_debug (request,
 	                            "  Resetting shutdown timeout");
@@ -888,37 +876,36 @@ get_metadata_fast (TrackerExtract *object,
 
 		if (error) {
 			tracker_dbus_request_end (request, error);
-			reply = dbus_message_new_error (message,
-			                                TRACKER_EXTRACT_SERVICE ".GetMetadataFastError",
-			                                error->message);
-			dbus_connection_send (connection, reply, NULL);
-			dbus_message_unref (reply);
+			reply = g_dbus_message_new_method_error_literal (method_message,
+			                                                 TRACKER_EXTRACT_SERVICE ".GetMetadataFastError",
+			                                                 error->message);
 			g_error_free (error);
 		} else {
 			tracker_dbus_request_end (request, NULL);
-			reply = dbus_message_new_method_return (message);
-			dbus_connection_send (connection, reply, NULL);
-			dbus_message_unref (reply);
+			reply = g_dbus_message_new_method_reply (method_message);
 		}
 	} else {
 		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);
-		close (fd);
-		dbus_connection_send (connection, reply, NULL);
-		dbus_message_unref (reply);
+		reply = g_dbus_message_new_method_error_literal (method_message,
+		                                                 TRACKER_EXTRACT_SERVICE ".GetMetadataFastError",
+		                                                 error->message);
 		g_error_free (error);
+		close (fd);
 	}
 
+	g_dbus_connection_send_message (connection, reply,
+	                                G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+	                                NULL, NULL);
+
+	g_object_unref (reply);
+
 	if (!priv->disable_shutdown) {
 		/* Unset alarm so the extractor doesn't die when it's idle */
 		alarm (0);
 	}
 }
-#endif
 
 static void
 handle_method_call (GDBusConnection       *connection,
@@ -936,10 +923,7 @@ handle_method_call (GDBusConnection       *connection,
 		handle_method_call_get_pid (extract, invocation, parameters);
 	} else
 	if (g_strcmp0 (method_name, "GetMetadataFast") == 0) {
-#if 0
-		// todo
-		get_metadata_fast (extract, connection, message);
-#endif
+		handle_method_call_get_metadata_fast (extract, invocation, parameters);
 	} else
 	if (g_strcmp0 (method_name, "GetMetadata") == 0) {
 		handle_method_call_get_metadata (extract, invocation, parameters);



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