[tracker/return-types] tracker-store, libtracker-bus, -client, -common, -data: Implement get_variable_names



commit 5b743991b6087c4fe9bac48c58ce90d56ffb8e05
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Sep 9 16:17:02 2010 +0200

    tracker-store, libtracker-bus, -client, -common, -data: Implement get_variable_names
    
    This is untested, and tracker_db_cursor_get_variable_names doesn't always work atm

 src/libtracker-bus/tracker-bus-fd-cursor.c        |   10 ++-----
 src/libtracker-client/tracker.c                   |    1 +
 src/libtracker-common/tracker-dbus.c              |   27 +++++++++++++++++++++
 src/libtracker-common/tracker-dbus.h              |    1 +
 src/libtracker-data/tracker-db-interface-sqlite.c |   25 ++++++++++++++-----
 src/libtracker-data/tracker-db-interface.h        |    1 +
 src/tracker-store/tracker-steroids.c              |   19 ++++++++++++++-
 7 files changed, 69 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.c b/src/libtracker-bus/tracker-bus-fd-cursor.c
index 44b4363..7cd7874 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.c
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.c
@@ -53,6 +53,7 @@ struct TrackerBusFDCursor {
 	int *offsets;
 	int *types;
 	char *data;
+	GStrv variable_names;
 };
 
 struct TrackerBusFDCursorClass {
@@ -177,13 +178,7 @@ tracker_bus_fd_cursor_get_value_type (TrackerBusFDCursor *cursor,  guint column)
 static const gchar*
 tracker_bus_fd_cursor_get_variable_name (TrackerBusFDCursor *cursor,  guint column)
 {
-	/* TODO: Implement */
-
-	g_critical ("Unimplemented");
-
-	g_return_val_if_reached (NULL);
-
-	return NULL;
+	return cursor->variable_names[column - 1];
 }
 
 static const gchar *
@@ -295,6 +290,7 @@ tracker_bus_fd_query (DBusGConnection  *gconnection,
 	                              cancellable,
 	                              (void **) &cursor->buffer,
 	                              (gssize *) &cursor->buffer_size,
+	                              &cursor->variable_names,
 	                              &inner_error);
 	/* message is destroyed by tracker_dbus_send_and_splice */
 
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index 081b43e..e31016f 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -1813,6 +1813,7 @@ tracker_resources_sparql_query_iterate (TrackerClient  *client,
 	                              NULL,
 	                              (void **) &iterator->buffer,
 	                              &iterator->buffer_size,
+	                              NULL /* Not interested in variable_names */,
 	                              &inner_error);
 	/* message is destroyed by tracker_dbus_send_and_splice */
 
diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index c670539..e07a90c 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -718,6 +718,7 @@ tracker_dbus_send_and_splice (DBusConnection  *connection,
                               GCancellable    *cancellable,
                               void           **dest_buffer,
                               gssize          *dest_buffer_size,
+                              GStrv           *variable_names,
                               GError         **error)
 {
 	DBusPendingCall *call;
@@ -784,6 +785,32 @@ tracker_dbus_send_and_splice (DBusConnection  *connection,
 				*dest_buffer_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (output_stream));
 			}
 
+			if (variable_names) {
+				GStrv v_names;
+				guint i;
+				GPtrArray *found = g_ptr_array_new ();
+				DBusMessageIter iter, arr;
+
+				dbus_message_iter_init (reply, &iter);
+				dbus_message_iter_recurse (&iter, &arr);
+
+				while (dbus_message_iter_has_next(&arr)) {
+					gchar *str;
+
+					dbus_message_iter_get_basic (&arr, &str);
+					g_ptr_array_add (found, str);
+					dbus_message_iter_next (&arr);
+				}
+
+				v_names = g_new0 (gchar *, found->len + 1);
+				for (i = 0; i < found->len; i++) {
+					v_names[i] = g_ptr_array_index (found, i);
+				}
+
+				*variable_names = v_names;
+				g_ptr_array_free (found, FALSE);
+			}
+
 			ret_value = TRUE;
 		}
 	} else {
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index b97cde9..f2dd4f5 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -185,6 +185,7 @@ gboolean         tracker_dbus_send_and_splice        (DBusConnection
                                                       GCancellable               *cancellable,
                                                       void                      **dest_buffer,
                                                       gssize                     *dest_buffer_size,
+                                                      GStrv                      *variable_names,
                                                       GError                    **error);
 
 gboolean         tracker_dbus_send_and_splice_async  (DBusConnection             *connection,
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 28f0a70..5b2fee5 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1312,7 +1312,7 @@ tracker_db_cursor_get_value_type (TrackerDBCursor *cursor,  guint column)
 {
 	gint n_columns = sqlite3_column_count (cursor->stmt);
 
-	g_return_val_if_fail (column >= 0 && column < n_columns, TRACKER_SPARQL_VALUE_TYPE_UNBOUND);
+	g_return_val_if_fail (column < n_columns, TRACKER_SPARQL_VALUE_TYPE_UNBOUND);
 
 	if (sqlite3_column_type (cursor->stmt, column) == SQLITE_NULL) {
 		return TRACKER_SPARQL_VALUE_TYPE_UNBOUND;
@@ -1334,20 +1334,18 @@ tracker_db_cursor_get_value_type (TrackerDBCursor *cursor,  guint column)
 	}
 }
 
-const gchar*
-tracker_db_cursor_get_variable_name (TrackerDBCursor *cursor, guint column)
+const gchar**
+tracker_db_cursor_get_variable_names (TrackerDBCursor *cursor)
 {
 	gint n_columns = sqlite3_column_count (cursor->stmt);
 
-	g_return_val_if_fail (column >= 0 && column < n_columns, NULL);
-
 	if (cursor->variable_names == NULL) {
 		gint i;
 
 		cursor->variable_names = g_new0 (gchar *, n_columns);
 
 		for (i = 0 ; i < n_columns; i++) {
-			const char *sqlite_name = sqlite3_column_name (cursor->stmt, column);
+			const char *sqlite_name = sqlite3_column_name (cursor->stmt, i);
 			if (g_str_has_suffix (sqlite_name, "_u")) {
 				/* SPARQL variable */
 				cursor->variable_names[i] = g_strndup (sqlite_name, strlen (sqlite_name - strlen ("_u")));
@@ -1355,7 +1353,20 @@ tracker_db_cursor_get_variable_name (TrackerDBCursor *cursor, guint column)
 		}
 	}
 
-	return cursor->variable_names[column];
+	return (const gchar **) cursor->variable_names;
+}
+
+const gchar*
+tracker_db_cursor_get_variable_name (TrackerDBCursor *cursor, guint column)
+{
+	const gchar **variable_names;
+	gint n_columns = sqlite3_column_count (cursor->stmt);
+
+	g_return_val_if_fail (column < n_columns, NULL);
+
+	variable_names = tracker_db_cursor_get_variable_names (cursor);
+
+	return variable_names[column];
 }
 
 const gchar*
diff --git a/src/libtracker-data/tracker-db-interface.h b/src/libtracker-data/tracker-db-interface.h
index d63e1b1..78d5734 100644
--- a/src/libtracker-data/tracker-db-interface.h
+++ b/src/libtracker-data/tracker-db-interface.h
@@ -148,6 +148,7 @@ gboolean                tracker_db_cursor_iter_next             (TrackerDBCursor
 guint                   tracker_db_cursor_get_n_columns         (TrackerDBCursor     *cursor);
 const gchar*            tracker_db_cursor_get_variable_name     (TrackerDBCursor     *cursor,
                                                                  guint                column);
+const gchar**           tracker_db_cursor_get_variable_names    (TrackerDBCursor     *cursor);
 TrackerSparqlValueType  tracker_db_cursor_get_value_type        (TrackerDBCursor     *cursor,
                                                                  guint                column);
 void                    tracker_db_cursor_get_value             (TrackerDBCursor     *cursor,
diff --git a/src/tracker-store/tracker-steroids.c b/src/tracker-store/tracker-steroids.c
index c32bcf0..285b5f8 100644
--- a/src/tracker-store/tracker-steroids.c
+++ b/src/tracker-store/tracker-steroids.c
@@ -32,7 +32,7 @@
 #include "tracker-store.h"
 
 #define UNKNOWN_METHOD_MESSAGE "Method \"%s\" with signature \"%s\" on " \
-	                       "interface \"%s\" doesn't exist, expected \"%s\""
+                               "interface \"%s\" doesn't exist, expected \"%s\""
 
 /**
  * /!\ IMPORTANT WARNING /!\
@@ -56,6 +56,7 @@ typedef struct {
 typedef struct {
 	GError *error;
 	gpointer user_data;
+	GStrv variable_names;
 } InThreadPtr;
 
 static void
@@ -118,9 +119,23 @@ query_callback (gpointer  inthread_data,
 		dbus_connection_send (info->connection, reply, NULL);
 		dbus_message_unref (reply);
 	} else {
+		GStrv variable_names = ptr->variable_names;
+		DBusMessageIter iter, subiter;
+		guint i;
+
 		tracker_dbus_request_success (info->request_id,
 		                              NULL);
 		reply = dbus_message_new_method_return (info->call_message);
+
+		dbus_message_iter_init_append (reply, &iter);
+
+		dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &subiter);
+		for (i = 0; variable_names[i] != NULL; i++) {
+			gchar *variable_name = variable_names[i];
+			dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &variable_name);
+		}
+		dbus_message_iter_close_container (&iter, &subiter);
+
 		dbus_connection_send (info->connection, reply, NULL);
 		dbus_message_unref (reply);
 	}
@@ -355,6 +370,8 @@ end_query_inthread:
 
 	if (loop_error) {
 		ptr->error = loop_error;
+	} else {
+		ptr->variable_names = g_strdupv ((gchar **) tracker_db_cursor_get_variable_names (cursor));
 	}
 
 	return ptr;



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