[tracker/dbus-fd-experiment: 11/13] Steroids: Simplify query
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/dbus-fd-experiment: 11/13] Steroids: Simplify query
- Date: Thu, 3 Jun 2010 14:43:28 +0000 (UTC)
commit 0cf7ab98462f0a2c65211685c8cc24bd9dd2c4f6
Author: Adrien Bustany <abustany gnome org>
Date: Thu Jun 3 10:22:57 2010 -0400
Steroids: Simplify query
This commit simplifies queries dones using DBus FD passing the same way
as the following commit: the client passes the server the query, and a
FD where to write the results.
src/libtracker-client/tracker.c | 52 +++-----
src/tracker-store/tracker-steroids.c | 246 +++++++++++++---------------------
2 files changed, 113 insertions(+), 185 deletions(-)
---
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index 60d6cba..98db7da 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -1320,17 +1320,26 @@ tracker_resources_sparql_query_iterate (TrackerClient *client,
TrackerClientPrivate *private;
DBusConnection *connection;
DBusMessage *message;
+ DBusMessageIter iter;
DBusMessage *reply;
DBusPendingCall *call;
- guint query_id;
DBusError dbus_error;
TrackerResultIterator *iterator;
+ int pipefd[2];
g_return_val_if_fail (TRACKER_IS_CLIENT (client), NULL);
g_return_val_if_fail (query, NULL);
private = TRACKER_CLIENT_GET_PRIVATE (client);
+ if (pipe (pipefd) < 0) {
+ g_set_error (error,
+ TRACKER_CLIENT_ERROR,
+ TRACKER_CLIENT_ERROR_UNSUPPORTED,
+ "Cannot open pipe");
+ return NULL;
+ }
+
connection = dbus_g_connection_get_connection (private->connection);
dbus_error_init (&dbus_error);
@@ -1338,42 +1347,18 @@ tracker_resources_sparql_query_iterate (TrackerClient *client,
message = dbus_message_new_method_call (TRACKER_STEROIDS_SERVICE,
TRACKER_STEROIDS_PATH,
TRACKER_STEROIDS_INTERFACE,
- "PrepareQuery");
- dbus_message_append_args (message,
- DBUS_TYPE_STRING, &query,
- DBUS_TYPE_INVALID);
- reply = dbus_connection_send_with_reply_and_block (connection,
- message,
- -1,
- &dbus_error);
- dbus_message_unref (message);
-
- if (!reply) {
- dbus_set_g_error (error, &dbus_error);
- return NULL;
- }
-
- iterator = g_slice_new0 (TrackerResultIterator);
- iterator->buffer_size = TRACKER_STEROIDS_BUFFER_SIZE;
+ "Query");
- dbus_message_get_args (reply,
- &dbus_error,
- DBUS_TYPE_UNIX_FD, &iterator->fd,
- DBUS_TYPE_UINT32, &query_id,
- DBUS_TYPE_INVALID);
- dbus_message_unref (reply);
+ dbus_message_iter_init_append (message, &iter);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &query);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD, &pipefd[1]);
- message = dbus_message_new_method_call (TRACKER_STEROIDS_SERVICE,
- TRACKER_STEROIDS_PATH,
- TRACKER_STEROIDS_INTERFACE,
- "Fetch");
- dbus_message_append_args (message,
- DBUS_TYPE_UINT32, &query_id,
- DBUS_TYPE_INVALID);
dbus_connection_send_with_reply (connection,
message,
&call,
-1);
+ dbus_message_unref (message);
+ close (pipefd[1]);
if (!call) {
g_set_error (error,
@@ -1383,7 +1368,11 @@ tracker_resources_sparql_query_iterate (TrackerClient *client,
return NULL;
}
+ iterator = g_slice_new0 (TrackerResultIterator);
+ iterator->fd = pipefd[0];
+ iterator->buffer_size = TRACKER_STEROIDS_BUFFER_SIZE;
iterator->buffer = g_malloc (TRACKER_STEROIDS_BUFFER_SIZE);
+
if (iterator_buffer_fill (iterator) < 0) {
g_set_error (error,
TRACKER_CLIENT_ERROR,
@@ -1392,6 +1381,7 @@ tracker_resources_sparql_query_iterate (TrackerClient *client,
tracker_result_iterator_free (iterator);
return NULL;
}
+
iterator->buffer_index = 0;
iterator->rc = iterator_buffer_read_int (iterator);
diff --git a/src/tracker-store/tracker-steroids.c b/src/tracker-store/tracker-steroids.c
index 9456834..5cda6cf 100644
--- a/src/tracker-store/tracker-steroids.c
+++ b/src/tracker-store/tracker-steroids.c
@@ -196,42 +196,48 @@ query_callback (gpointer inthread_data,
GError *error,
gpointer user_data)
{
-// InThreadPtr *ptr = inthread_data;
-// ClientInfo *info = user_data;
-// TrackerSteroidsPrivate *priv = TRACKER_STEROIDS_GET_PRIVATE (info->parent);
-// DBusMessage *reply;
-//
-// if (info->fd) {
-// close (info->fd);
-// }
-//
-// if (ptr && ptr->error) {
-// /* Client is still there, but query failed */
-// tracker_dbus_request_failed (info->request_id,
-// info->context,
-// &ptr->error,
-// NULL);
-// dbus_g_method_return_error (info->context, ptr->error);
-// g_error_free (ptr->error);
-// } else if (error) {
-// /* Client has disappeared */
-// tracker_dbus_request_failed (info->request_id,
-// info->context,
-// &error,
-// NULL);
-// dbus_g_method_return_error (info->context, error);
-// } else {
-// tracker_dbus_request_success (info->request_id,
-// info->context);
-// reply = dbus_g_method_get_reply (info->context);
-// dbus_g_method_send_reply (info->context, reply);
-// }
-//
-// if (ptr) {
-// g_slice_free (InThreadPtr, ptr);
-// }
-//
-// g_hash_table_remove (priv->clients, info);
+ InThreadPtr *ptr = inthread_data;
+ ClientInfo *info = user_data;
+ DBusMessage *reply;
+
+ if (info->fd) {
+ close (info->fd);
+ }
+
+ if (ptr && ptr->error) {
+ /* Client is still there, but query failed */
+ tracker_dbus_request_failed (info->request_id,
+ NULL,
+ &ptr->error,
+ NULL);
+ reply = dbus_message_new_error (info->call_message,
+ TRACKER_STEROIDS_INTERFACE ".QueryError",
+ ptr->error->message);
+ dbus_connection_send (info->connection, reply, NULL);
+ dbus_message_unref (reply);
+ g_error_free (ptr->error);
+ } else if (error) {
+ /* Client has disappeared */
+ tracker_dbus_request_failed (info->request_id,
+ NULL,
+ &error,
+ NULL);
+ reply = dbus_message_new_error (info->call_message,
+ TRACKER_STEROIDS_INTERFACE ".QueryError",
+ error->message);
+ dbus_connection_send (info->connection, reply, NULL);
+ dbus_message_unref (reply);
+ } else {
+ tracker_dbus_request_success (info->request_id,
+ NULL);
+ reply = dbus_message_new_method_return (info->call_message);
+ dbus_connection_send (info->connection, reply, NULL);
+ dbus_message_unref (reply);
+ }
+
+ if (ptr) {
+ g_slice_free (InThreadPtr, ptr);
+ }
}
static void
@@ -393,128 +399,55 @@ query_inthread (TrackerDBCursor *cursor,
return ptr;
}
-//static ClientInfo*
-//tracker_steroids_prepare (TrackerSteroids *steroids,
-// DBusGMethodInvocation *context,
-// gboolean read,
-// GError **error)
-//{
-// TrackerSteroidsPrivate *priv = TRACKER_STEROIDS_GET_PRIVATE (steroids);
-// guint request_id;
-// gchar *sender;
-// int pipefd[2];
-// DBusMessage *reply;
-// DBusMessageIter iter;
-// GError *inner_error = NULL;
-// ClientInfo *info;
-//
-// request_id = tracker_dbus_get_next_request_id ();
-//
-// tracker_dbus_request_new (request_id,
-// context,
-// "%s()",
-// __FUNCTION__);
-//
-// if (pipe (pipefd) < 0) {
-// g_set_error (&inner_error, TRACKER_DBUS_ERROR, 0, "Cannot open pipe");
-//
-// tracker_dbus_request_failed (request_id,
-// context,
-// &inner_error,
-// NULL);
-// dbus_g_method_return_error (context, inner_error);
-// g_propagate_error (error, inner_error);
-//
-// return NULL;
-// }
-//
-// info = g_slice_new0 (ClientInfo);
-// info->parent = steroids;
-// info->fd = pipefd[1 - read];
-//
-// sender = dbus_g_method_get_sender (context);
-//
-// reply = dbus_g_method_get_reply (context);
-//
-// dbus_message_iter_init_append (reply, &iter);
-//
-// if (!dbus_message_iter_append_basic (&iter,
-// DBUS_TYPE_UNIX_FD,
-// &pipefd[read])) {
-// g_critical ("FD passing not supported");
-//
-// g_set_error (&inner_error, TRACKER_DBUS_ERROR, 0, "FD passing not supported");
-//
-// tracker_dbus_request_failed (request_id,
-// context,
-// &inner_error,
-// NULL);
-// dbus_g_method_return_error (context, inner_error);
-// g_propagate_error (error, inner_error);
-//
-// g_slice_free (ClientInfo, info);
-// g_free (sender);
-// return NULL;
-// }
-//
-// dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &request_id);
-//
-// g_hash_table_insert (priv->clients,
-// GUINT_TO_POINTER (request_id),
-// info);
-//
-// tracker_dbus_request_success (request_id, context);
-// dbus_g_method_send_reply (context, reply);
-//
-// g_free (sender);
-//
-// return info;
-//}
-
static void
-tracker_steroids_fetch (TrackerSteroids *steroids,
+tracker_steroids_query (TrackerSteroids *steroids,
DBusConnection *connection,
DBusMessage *message)
{
-// TrackerSteroidsPrivate *priv = TRACKER_STEROIDS_GET_PRIVATE (steroids);
-// ClientInfo *info;
-// guint request_id;
-// gchar *sender;
-// GError *inner_error = NULL;
-//
-// request_id = tracker_dbus_get_next_request_id ();
-//
-// tracker_dbus_request_new (request_id,
-// context,
-// "%s(): %u",
-// __FUNCTION__,
-// query_id);
-//
-// info = g_hash_table_lookup (priv->clients,
-// GUINT_TO_POINTER (query_id));
-//
-// if (!info) {
-// g_set_error (&inner_error, TRACKER_DBUS_ERROR, 0, "Wrong query id");
-// tracker_dbus_request_failed (request_id,
-// context,
-// &inner_error,
-// NULL);
-// dbus_g_method_return_error (info->context, inner_error);
-// g_propagate_error (error, inner_error);
-//
-// return;
-// }
-//
-// info->request_id = request_id;
-// info->context = context;
-//
-// sender = dbus_g_method_get_sender (context);
-//
-// tracker_store_sparql_query (info->query, TRACKER_STORE_PRIORITY_HIGH,
-// query_inthread, query_callback, sender,
-// info, destroy_client_info);
-//
-// g_free (sender);
+ ClientInfo *info;
+ guint request_id;
+ const gchar *sender;
+ DBusMessage *reply;
+ DBusError dbus_error;
+
+ if (g_strcmp0 (dbus_message_get_signature (message), DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UNIX_FD_AS_STRING)) {
+ reply = dbus_message_new_error_printf (message,
+ DBUS_ERROR_UNKNOWN_METHOD_NAME,
+ DBUS_ERROR_UNKNOWN_METHOD_MESSAGE,
+ "Query",
+ dbus_message_get_signature (message),
+ dbus_message_get_interface (message));
+ dbus_connection_send (connection, message, NULL);
+ dbus_message_unref (reply);
+ return;
+ }
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_request_new (request_id,
+ NULL,
+ "%s()",
+ __FUNCTION__);
+
+ info = g_slice_new0 (ClientInfo);
+ info->parent = steroids;
+ info->connection = dbus_connection_ref (connection);
+ info->call_message = dbus_message_ref (message);
+ info->request_id = request_id;
+
+ dbus_error_init (&dbus_error);
+
+ dbus_message_get_args (message,
+ &dbus_error,
+ DBUS_TYPE_STRING, &info->query,
+ DBUS_TYPE_UNIX_FD, &info->fd,
+ DBUS_TYPE_INVALID);
+
+ sender = dbus_message_get_sender (message);
+
+ tracker_store_sparql_query (info->query, TRACKER_STORE_PRIORITY_HIGH,
+ query_inthread, query_callback, sender,
+ info, destroy_client_info);
}
static void
@@ -598,6 +531,11 @@ tracker_steroids_connection_filter (DBusConnection *connection,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
+ if (!g_strcmp0 ("Query", dbus_message_get_member (message))) {
+ tracker_steroids_query (steroids, connection, message);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
if (!g_strcmp0 ("Update", dbus_message_get_member (message))) {
tracker_steroids_update (steroids, connection, message);
return DBUS_HANDLER_RESULT_HANDLED;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]