[tracker/dbus-fd-experiment: 14/15] Steroids client: Implement SparqlUpdateBlank
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/dbus-fd-experiment: 14/15] Steroids client: Implement SparqlUpdateBlank
- Date: Thu, 3 Jun 2010 17:03:20 +0000 (UTC)
commit e7cd2e8c089af8ab0f860c703f103978bab7b4bd
Author: Adrien Bustany <abustany gnome org>
Date: Thu Jun 3 12:59:53 2010 -0400
Steroids client: Implement SparqlUpdateBlank
src/libtracker-client/tracker.c | 254 ++++++++++++++++++++++++++-------------
src/libtracker-client/tracker.h | 3 +
2 files changed, 174 insertions(+), 83 deletions(-)
---
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index 98db7da..b760112 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -874,6 +874,127 @@ end_of_results:
return rows;
}
+static DBusMessage*
+sparql_update_blank_fast (TrackerClient *client,
+ const gchar *query,
+ GError **error)
+{
+ TrackerClientPrivate *private;
+ DBusConnection *connection;
+ DBusMessage *message;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ DBusPendingCall *call;
+ DBusError dbus_error;
+ int pipefd[2];
+ char *query_size_buffer;
+ int query_len;
+ int query_index;
+
+ g_return_val_if_fail (TRACKER_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (query != NULL, 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);
+
+ message = dbus_message_new_method_call (TRACKER_STEROIDS_SERVICE,
+ TRACKER_STEROIDS_PATH,
+ TRACKER_STEROIDS_INTERFACE,
+ "UpdateBlank");
+ dbus_message_iter_init_append (message, &iter);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD, &pipefd[0]);
+ dbus_connection_send_with_reply (connection,
+ message,
+ &call,
+ -1);
+ dbus_message_unref (message);
+ close (pipefd[0]);
+
+ if (!call) {
+ g_set_error (error,
+ TRACKER_CLIENT_ERROR,
+ TRACKER_CLIENT_ERROR_UNSUPPORTED,
+ "FD passing unsupported or connection disconnected");
+ return NULL;
+ }
+
+ query_size_buffer = g_malloc (sizeof (int));
+
+ /* We don't need to null terminate, the store will do it for us */
+ query_len = strlen (query);
+ query_index = 0;
+ buffer_write_int (query_size_buffer, query_len);
+
+ pipe_write (pipefd[1], query_size_buffer, sizeof (int));
+
+ if ((sizeof (int) + query_len) > TRACKER_STEROIDS_BUFFER_SIZE) {
+ pipe_write (pipefd[1], query, TRACKER_STEROIDS_BUFFER_SIZE - sizeof (int));
+ query_index += TRACKER_STEROIDS_BUFFER_SIZE - sizeof (int);
+ }
+
+ while (query_index < query_len) {
+ int to_send = MIN(TRACKER_STEROIDS_BUFFER_SIZE, query_len - query_index);
+ pipe_write (pipefd[1], query + query_index, to_send);
+ query_index += to_send;
+ }
+
+ close (pipefd[1]);
+
+ g_free (query_size_buffer);
+
+ dbus_pending_call_block (call);
+
+ reply = dbus_pending_call_steal_reply (call);
+
+ g_assert (reply);
+
+ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
+ dbus_set_error_from_message (&dbus_error, reply);
+ dbus_set_g_error (error, &dbus_error);
+ dbus_pending_call_unref (call);
+ return NULL;
+ }
+
+ dbus_pending_call_unref (call);
+
+ return reply;
+}
+
+static GHashTable*
+unmarshall_hash_table (DBusMessageIter *iter) {
+ GHashTable *result;
+ DBusMessageIter subiter, subsubiter;
+
+ result = g_hash_table_new (g_str_hash, g_str_equal);
+
+ dbus_message_iter_recurse (iter, &subiter);
+
+ while (dbus_message_iter_get_arg_type (&subiter) != DBUS_TYPE_INVALID) {
+ const gchar *key, *value;
+
+ dbus_message_iter_recurse (&subiter, &subsubiter);
+ dbus_message_iter_get_basic (&subsubiter, &key);
+ dbus_message_iter_next (&subsubiter);
+ dbus_message_iter_get_basic (&subsubiter, &value);
+ g_hash_table_insert (result, g_strdup (key), g_strdup (value));
+
+ dbus_message_iter_next (&subiter);
+ }
+
+ return result;
+}
+
#endif
/**
@@ -1646,96 +1767,15 @@ tracker_resources_sparql_update_fast (TrackerClient *client,
const gchar *query,
GError **error)
{
- TrackerClientPrivate *private;
- DBusConnection *connection;
- DBusMessage *message;
- DBusMessageIter iter;
DBusMessage *reply;
- DBusPendingCall *call;
- DBusError dbus_error;
- int pipefd[2];
- char *query_size_buffer;
- int query_len;
- int query_index;
-
- g_return_if_fail (TRACKER_IS_CLIENT (client));
- g_return_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;
- }
-
- connection = dbus_g_connection_get_connection (private->connection);
-
- dbus_error_init (&dbus_error);
-
- message = dbus_message_new_method_call (TRACKER_STEROIDS_SERVICE,
- TRACKER_STEROIDS_PATH,
- TRACKER_STEROIDS_INTERFACE,
- "Update");
- dbus_message_iter_init_append (message, &iter);
- dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD, &pipefd[0]);
- dbus_connection_send_with_reply (connection,
- message,
- &call,
- -1);
- dbus_message_unref (message);
- close (pipefd[0]);
-
- if (!call) {
- g_set_error (error,
- TRACKER_CLIENT_ERROR,
- TRACKER_CLIENT_ERROR_UNSUPPORTED,
- "FD passing unsupported or connection disconnected");
- return;
- }
-
- query_size_buffer = g_malloc (sizeof (int));
-
- /* We don't need to null terminate, the store will do it for us */
- query_len = strlen (query);
- query_index = 0;
- buffer_write_int (query_size_buffer, query_len);
-
- pipe_write (pipefd[1], query_size_buffer, sizeof (int));
- if ((sizeof (int) + query_len) > TRACKER_STEROIDS_BUFFER_SIZE) {
- pipe_write (pipefd[1], query, TRACKER_STEROIDS_BUFFER_SIZE - sizeof (int));
- query_index += TRACKER_STEROIDS_BUFFER_SIZE - sizeof (int);
- }
-
- while (query_index < query_len) {
- int to_send = MIN(TRACKER_STEROIDS_BUFFER_SIZE, query_len - query_index);
- pipe_write (pipefd[1], query + query_index, to_send);
- query_index += to_send;
- }
-
- close (pipefd[1]);
-
- g_free (query_size_buffer);
-
- dbus_pending_call_block (call);
-
- reply = dbus_pending_call_steal_reply (call);
-
- g_assert (reply);
+ reply = sparql_update_blank_fast (client, query, error);
- if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
- dbus_set_error_from_message (&dbus_error, reply);
- dbus_set_g_error (error, &dbus_error);
- dbus_pending_call_unref (call);
+ if (!reply) {
return;
}
dbus_message_unref (reply);
-
- dbus_pending_call_unref (call);
}
GPtrArray *
@@ -1761,6 +1801,54 @@ tracker_resources_sparql_update_blank (TrackerClient *client,
return result;
}
+GPtrArray*
+tracker_resources_sparql_update_blank_fast (TrackerClient *client,
+ const gchar *query,
+ GError **error)
+{
+ DBusMessage *reply;
+ DBusMessageIter iter, subiter, subsubiter;
+ GPtrArray *result;
+
+ reply = sparql_update_blank_fast (client, query, error);
+
+ if (!reply) {
+ return NULL;
+ }
+
+ if (g_strcmp0 (dbus_message_get_signature (reply), "aaa{ss}")) {
+ g_set_error (error,
+ TRACKER_CLIENT_ERROR,
+ TRACKER_CLIENT_ERROR_UNSUPPORTED,
+ "Server returned invalid results");
+ dbus_message_unref (reply);
+ return NULL;
+ }
+
+ result = g_ptr_array_new ();
+ dbus_message_iter_init (reply, &iter);
+ dbus_message_iter_recurse (&iter, &subiter);
+
+ while (dbus_message_iter_get_arg_type (&subiter) != DBUS_TYPE_INVALID) {
+ GPtrArray *inner_array;
+
+ inner_array = g_ptr_array_new ();
+ g_ptr_array_add (result, inner_array);
+ dbus_message_iter_recurse (&subiter, &subsubiter);
+
+ while (dbus_message_iter_get_arg_type (&subsubiter) != DBUS_TYPE_INVALID) {
+ g_ptr_array_add (inner_array, unmarshall_hash_table (&subsubiter));
+ dbus_message_iter_next (&subsubiter);
+ }
+
+ dbus_message_iter_next (&subiter);
+ }
+
+ dbus_message_unref (reply);
+
+ return result;
+}
+
/**
* tracker_resources_batch_sparql_update:
* @client: a #TrackerClient.
diff --git a/src/libtracker-client/tracker.h b/src/libtracker-client/tracker.h
index 7b4ec65..12dff2c 100644
--- a/src/libtracker-client/tracker.h
+++ b/src/libtracker-client/tracker.h
@@ -152,6 +152,9 @@ void tracker_resources_sparql_update_fast (TrackerClient
GPtrArray * tracker_resources_sparql_update_blank (TrackerClient *client,
const gchar *query,
GError **error);
+GPtrArray * tracker_resources_sparql_update_blank_fast (TrackerClient *client,
+ const gchar *query,
+ GError **error);
void tracker_resources_batch_sparql_update (TrackerClient *client,
const gchar *query,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]