[tracker/libtracker-bus: 44/51] libtracker-bus: Support for normal dbus updateblank (untested)
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/libtracker-bus: 44/51] libtracker-bus: Support for normal dbus updateblank (untested)
- Date: Wed, 11 Aug 2010 15:37:26 +0000 (UTC)
commit 553b985145c2cff8b90cf7f923b6aa56001a06d1
Author: Philip Van Hoof <philip codeminded be>
Date: Fri Jul 23 15:41:36 2010 +0200
libtracker-bus: Support for normal dbus updateblank (untested)
src/libtracker-bus/tracker-bus-array-update.c | 140 ++++++++++++++++++++++++-
src/libtracker-bus/tracker-bus-fd-update.c | 2 +-
src/libtracker-bus/tracker-bus-shared.c | 2 +
3 files changed, 139 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus-array-update.c b/src/libtracker-bus/tracker-bus-array-update.c
index 1bf43d4..d9701a7 100644
--- a/src/libtracker-bus/tracker-bus-array-update.c
+++ b/src/libtracker-bus/tracker-bus-array-update.c
@@ -35,6 +35,104 @@
#include "tracker-bus.h"
#include "tracker-bus-shared.h"
+typedef struct {
+ DBusConnection *connection;
+ GCancellable *cancellable;
+ DBusPendingCall *dbus_call;
+ GSimpleAsyncResult *res;
+ gpointer user_data;
+ gulong cancelid;
+} AsyncData;
+
+
+static void
+async_data_free (gpointer data)
+{
+ AsyncData *fad = data;
+
+ if (fad) {
+ if (fad->cancellable) {
+ if (fad->cancelid != 0)
+ g_cancellable_disconnect (fad->cancellable, fad->cancelid);
+ g_object_unref (fad->cancellable);
+ }
+
+ if (fad->connection) {
+ dbus_connection_unref (fad->connection);
+ }
+
+ if (fad->res) {
+ /* Don't free, weak */
+ }
+
+ g_slice_free (AsyncData, fad);
+ }
+}
+
+static AsyncData *
+async_data_new (DBusConnection *connection,
+ GCancellable *cancellable,
+ gpointer user_data)
+{
+ AsyncData *fad = g_slice_new0 (AsyncData);
+
+ fad->connection = dbus_connection_ref (connection);
+ fad->cancellable = g_object_ref (connection);
+ fad->user_data = user_data;
+
+ return fad;
+}
+
+
+
+static void
+sparql_update_callback (DBusPendingCall *call,
+ void *user_data)
+{
+ AsyncData *fad = user_data;
+ DBusMessage *reply;
+ GError *error = NULL;
+ GVariant *result;
+
+ /* Check for errors */
+ reply = dbus_pending_call_steal_reply (call);
+
+ if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
+ DBusError dbus_error;
+
+ dbus_error_init (&dbus_error);
+ dbus_set_error_from_message (&dbus_error, reply);
+ dbus_set_g_error (&error, &dbus_error);
+ dbus_error_free (&dbus_error);
+
+ g_simple_async_result_set_from_error (fad->res, error);
+
+ dbus_message_unref (reply);
+
+ g_simple_async_result_complete (fad->res);
+
+ async_data_free (fad);
+
+ dbus_pending_call_unref (call);
+
+ return;
+ }
+
+ result = tracker_bus_message_to_variant (reply);
+ g_simple_async_result_set_op_res_gpointer (fad->res, result, NULL);
+ g_simple_async_result_complete (fad->res);
+ dbus_message_unref (reply);
+ g_variant_unref (result);
+
+
+ /* Clean up */
+ dbus_message_unref (reply);
+
+ async_data_free (fad);
+
+ dbus_pending_call_unref (call);
+}
+
void
tracker_bus_array_sparql_update_blank_async (DBusGConnection *connection,
const gchar *query,
@@ -43,9 +141,42 @@ tracker_bus_array_sparql_update_blank_async (DBusGConnection *connection,
gpointer user_data)
{
#ifdef HAVE_DBUS_FD_PASSING
+ DBusPendingCall *call;
+ DBusMessage *message;
+ AsyncData *fad;
+ DBusMessageIter iter;
+ DBusConnection *con;
+
+ g_return_if_fail (query != NULL);
+
+ con = dbus_g_connection_get_connection (connection);
+ fad = async_data_new (con, cancellable, user_data);
+
+ fad->res = g_simple_async_result_new (NULL, callback, user_data,
+ tracker_bus_array_sparql_update_blank_async);
+
+
+ message = dbus_message_new_method_call (TRACKER_DBUS_SERVICE,
+ TRACKER_DBUS_OBJECT_RESOURCES,
+ TRACKER_DBUS_INTERFACE_RESOURCES,
+ "UpdateBlank");
+
+ dbus_message_iter_init_append (message, &iter);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &query);
+ dbus_connection_send_with_reply (con, message, &call, -1);
+ dbus_message_unref (message);
+
+ if (!call) {
+ g_critical ("Could not initiate update: UpdateBlank Unsupported or connection disconnected");
+ g_object_unref (fad->res);
+ async_data_free (fad);
+ return;
+ }
+
+ fad->dbus_call = call;
+
+ dbus_pending_call_set_notify (call, sparql_update_callback, fad, NULL);
- g_critical ("tracker_bus_array_sparql_update_blank_async unimplemented");
- // todo
#else /* HAVE_DBUS_FD_PASSING */
g_assert_not_reached ();
@@ -73,7 +204,8 @@ tracker_bus_array_sparql_update_blank (DBusGConnection *connection,
dbus_message_iter_init_append (message, &iter);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &query);
- dbus_connection_send_with_reply (connection, message, &call, -1);
+ dbus_connection_send_with_reply (dbus_g_connection_get_connection (connection),
+ message, &call, -1);
dbus_message_unref (message);
if (!call) {
@@ -137,7 +269,7 @@ tracker_bus_array_sparql_update_blank_finish (GAsyncResult *res,
return NULL;
}
- return g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
+ return g_variant_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
#else /* HAVE_DBUS_FD_PASSING */
g_assert_not_reached ();
return NULL;
diff --git a/src/libtracker-bus/tracker-bus-fd-update.c b/src/libtracker-bus/tracker-bus-fd-update.c
index 12c0185..ab1b772 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.c
+++ b/src/libtracker-bus/tracker-bus-fd-update.c
@@ -401,7 +401,7 @@ tracker_bus_fd_sparql_update_blank_finish (GAsyncResult *res,
return NULL;
}
- return g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
+ return g_variant_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
#else /* HAVE_DBUS_FD_PASSING */
g_assert_not_reached ();
return NULL;
diff --git a/src/libtracker-bus/tracker-bus-shared.c b/src/libtracker-bus/tracker-bus-shared.c
index 7fedce2..938f671 100644
--- a/src/libtracker-bus/tracker-bus-shared.c
+++ b/src/libtracker-bus/tracker-bus-shared.c
@@ -39,6 +39,8 @@ tracker_bus_message_to_variant (DBusMessage *message)
GVariantBuilder builder;
DBusMessageIter iter, subiter, subsubiter;
+ /* TODO: This is probably wrong, especially the hashtable part */
+
/*aaa{ss}*/
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); /* a */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]