[tracker/rss-enclosures] tracker-store: Fill up the DBusMessage manually, avoiding memory copying



commit 0418f629a5b96f4e32c15c2231d6914fdd868a5c
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Apr 19 16:19:48 2010 +0200

    tracker-store: Fill up the DBusMessage manually, avoiding memory copying

 src/tracker-store/tracker-resources.c |   35 ++++++++++++++++++++++++++++----
 src/tracker-store/tracker-store.c     |   12 +++++-----
 src/tracker-store/tracker-store.h     |    2 +-
 3 files changed, 37 insertions(+), 12 deletions(-)
---
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 4f2e437..c568c27 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -179,10 +179,12 @@ tracker_resources_load (TrackerResources         *object,
 }
 
 static void
-query_callback (TrackerDBResultSet *result_set, GError *error, gpointer user_data)
+query_callback (TrackerDBCursor *cursor, GError *error, gpointer user_data)
 {
 	TrackerDBusMethodInfo *info = user_data;
-	GPtrArray *values;
+	DBusMessage *reply;
+	DBusMessageIter iter, rows_iter;
+	guint cols;
 
 	if (error) {
 		tracker_dbus_request_failed (info->request_id,
@@ -196,11 +198,34 @@ query_callback (TrackerDBResultSet *result_set, GError *error, gpointer user_dat
 	tracker_dbus_request_success (info->request_id,
 	                              info->context);
 
-	values = tracker_dbus_query_result_to_ptr_array (result_set);
+	reply = dbus_g_method_get_reply (info->context);
 
-	dbus_g_method_return (info->context, values);
+	dbus_message_iter_init_append (reply, &iter);
 
-	tracker_dbus_results_ptr_array_free (&values);
+	cols = tracker_db_cursor_get_n_columns (cursor);
+
+	dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, 
+	                                  "as", &rows_iter);
+
+	while (tracker_db_cursor_iter_next (cursor)) {
+		DBusMessageIter cols_iter;
+		guint i;
+
+		dbus_message_iter_open_container (&rows_iter, DBUS_TYPE_ARRAY, 
+		                                  "s", &cols_iter);
+
+		for (i = 0; i < cols; i++) {
+			const gchar *result_str;
+			result_str = tracker_db_cursor_get_string (cursor, i);
+			dbus_message_iter_append_basic (&cols_iter, DBUS_TYPE_STRING, &result_str);
+		}
+
+		dbus_message_iter_close_container (&rows_iter, &cols_iter);
+	}
+
+	dbus_message_iter_close_container (&iter, &rows_iter);
+
+	dbus_g_method_send_reply (info->context, reply);
 }
 
 void
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index ceff3a5..539293c 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -68,7 +68,7 @@ typedef struct {
 	union {
 		struct {
 			gchar                   *query;
-			TrackerDBResultSet      *result_set;
+			TrackerDBCursor         *cursor;
 			GThread			*running_thread;
 			GTimer			*timer;
 		} query;
@@ -331,12 +331,12 @@ task_finish_cb (gpointer data)
 
 	if (task->type == TRACKER_STORE_TASK_TYPE_QUERY) {
 		if (task->callback.query_callback) {
-			task->callback.query_callback (task->data.query.result_set, task->error, task->user_data);
+			task->callback.query_callback (task->data.query.cursor, task->error, task->user_data);
 		}
 
-		if (task->data.query.result_set) {
-			g_object_unref (task->data.query.result_set);
-			task->data.query.result_set = NULL;
+		if (task->data.query.cursor) {
+			g_object_unref (task->data.query.cursor);
+			task->data.query.cursor = NULL;
 		}
 
 		if (task->error) {
@@ -422,7 +422,7 @@ pool_dispatch_cb (gpointer data,
 
 	if (task->type == TRACKER_STORE_TASK_TYPE_QUERY) {
 		task->data.query.running_thread = g_thread_self ();
-		task->data.query.result_set = tracker_data_query_sparql (task->data.query.query, &task->error);
+		task->data.query.cursor = tracker_data_query_sparql_cursor (task->data.query.query, &task->error);
 		task->data.query.running_thread = NULL;
 	} else if (task->type == TRACKER_STORE_TASK_TYPE_UPDATE) {
 		if (task->data.update.batch) {
diff --git a/src/tracker-store/tracker-store.h b/src/tracker-store/tracker-store.h
index 28368eb..87ca4d4 100644
--- a/src/tracker-store/tracker-store.h
+++ b/src/tracker-store/tracker-store.h
@@ -35,7 +35,7 @@ typedef enum {
 	TRACKER_STORE_N_PRIORITIES
 } TrackerStorePriority;
 
-typedef void (* TrackerStoreSparqlQueryCallback)       (TrackerDBResultSet *result_set,
+typedef void (* TrackerStoreSparqlQueryCallback)       (TrackerDBCursor *cursor,
                                                         GError          *error,
                                                         gpointer         user_data);
 typedef void (* TrackerStoreSparqlUpdateCallback)      (GError          *error,



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