[tracker/direct-access] pushing what I have for Adrien, squash with update-support commits
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/direct-access] pushing what I have for Adrien, squash with update-support commits
- Date: Fri, 23 Jul 2010 11:07:30 +0000 (UTC)
commit 19c627571da2674c944f2252ce8f4447a7af62f7
Author: Philip Van Hoof <philip codeminded be>
Date: Fri Jul 23 13:05:10 2010 +0200
pushing what I have for Adrien, squash with update-support commits
src/libtracker-bus/Makefile.am | 4 +-
src/libtracker-bus/tracker-bus-array-update.c | 45 ++++++++++++-
src/libtracker-bus/tracker-bus-fd-update.c | 68 +------------------
src/libtracker-bus/tracker-bus-shared.c | 88 +++++++++++++++++++++++++
src/libtracker-bus/tracker-bus-shared.h | 26 +++++++
5 files changed, 161 insertions(+), 70 deletions(-)
---
diff --git a/src/libtracker-bus/Makefile.am b/src/libtracker-bus/Makefile.am
index 1061415..0ab110b 100644
--- a/src/libtracker-bus/Makefile.am
+++ b/src/libtracker-bus/Makefile.am
@@ -35,7 +35,9 @@ libtracker_bus_la_SOURCES = \
tracker-bus-fd-update.c \
tracker-bus-fd-update.h \
tracker-bus-array-update.c \
- tracker-bus-array-update.h
+ tracker-bus-array-update.h \
+ tracker-bus-shared.c \
+ tracker-bus-shared.h
libtracker_bus_la_LDFLAGS = \
-module -avoid-version -no-undefined
diff --git a/src/libtracker-bus/tracker-bus-array-update.c b/src/libtracker-bus/tracker-bus-array-update.c
index 40121b6..1bf43d4 100644
--- a/src/libtracker-bus/tracker-bus-array-update.c
+++ b/src/libtracker-bus/tracker-bus-array-update.c
@@ -33,6 +33,7 @@
#include "tracker-bus-array-update.h"
#include "tracker-bus.h"
+#include "tracker-bus-shared.h"
void
tracker_bus_array_sparql_update_blank_async (DBusGConnection *connection,
@@ -58,18 +59,53 @@ tracker_bus_array_sparql_update_blank (DBusGConnection *connection,
GError **error)
{
#ifdef HAVE_DBUS_FD_PASSING
- DBusMessage *reply;
+ DBusMessage *reply, *message;
GVariant *result;
+ DBusMessageIter iter;
+ DBusPendingCall *call;
g_return_val_if_fail (query != NULL, NULL);
- g_critical ("tracker_bus_array_sparql_update_blank unimplemented");
- // reply = todo
+ 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 (connection, message, &call, -1);
+ dbus_message_unref (message);
+
+ if (!call) {
+ g_set_error (error,
+ TRACKER_SPARQL_ERROR,
+ TRACKER_SPARQL_ERROR_UNSUPPORTED,
+ "UpdateBlank Unsupported or connection disconnected");
+ return NULL;
+ }
+
+ dbus_pending_call_block (call);
+
+ reply = dbus_pending_call_steal_reply (call);
if (!reply) {
return NULL;
}
+ 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_pending_call_unref (call);
+ dbus_error_free (&dbus_error);
+
+ return NULL;
+ }
+
+ dbus_pending_call_unref (call);
+
if (g_strcmp0 (dbus_message_get_signature (reply), "aaa{ss}")) {
g_set_error (error,
TRACKER_SPARQL_ERROR,
@@ -79,7 +115,8 @@ tracker_bus_array_sparql_update_blank (DBusGConnection *connection,
return NULL;
}
- //result = message_to_variant (reply);
+ result = tracker_bus_message_to_variant (reply);
+
dbus_message_unref (reply);
return result;
diff --git a/src/libtracker-bus/tracker-bus-fd-update.c b/src/libtracker-bus/tracker-bus-fd-update.c
index 8440b7e..12c0185 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.c
+++ b/src/libtracker-bus/tracker-bus-fd-update.c
@@ -34,6 +34,7 @@
#include "tracker-bus-fd-update.h"
#include "tracker-bus.h"
+#include "tracker-bus-shared.h"
#ifdef HAVE_DBUS_FD_PASSING
@@ -111,69 +112,6 @@ fast_async_data_new (DBusConnection *connection,
return data;
}
-/*
-static GHashTable *
-unmarshal_hash_table (DBusMessageIter *iter)
-{
- GHashTable *result;
- DBusMessageIter subiter, subsubiter;
-
- result = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_free);
-
- 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;
-}
-
-static void
-free_inner_array (gpointer elem)
-{
- g_ptr_array_free (elem, TRUE);
-}*/
-
-static GVariant*
-message_to_variant (DBusMessage *message)
-{
- GVariant *result = NULL;
- DBusMessageIter iter, subiter, subsubiter;
-
-// result = g_ptr_array_new_with_free_func (free_inner_array);
- dbus_message_iter_init (message, &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_with_free_func ((GDestroyNotify) g_hash_table_destroy);
-// 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, unmarshal_hash_table (&subsubiter));
- dbus_message_iter_next (&subsubiter);
- }
-
- dbus_message_iter_next (&subiter);
- }
-
- return result;
-}
-
static void
sparql_update_fast_callback (DBusPendingCall *call,
void *user_data)
@@ -213,7 +151,7 @@ sparql_update_fast_callback (DBusPendingCall *call,
g_simple_async_result_complete (fad->res);
break;
case FAST_UPDATE_BLANK:
- result = message_to_variant (reply);
+ 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);
@@ -497,7 +435,7 @@ tracker_bus_fd_sparql_update_blank (DBusGConnection *connection,
return NULL;
}
- result = message_to_variant (reply);
+ result = tracker_bus_message_to_variant (reply);
dbus_message_unref (reply);
return result;
diff --git a/src/libtracker-bus/tracker-bus-shared.c b/src/libtracker-bus/tracker-bus-shared.c
new file mode 100644
index 0000000..7fedce2
--- /dev/null
+++ b/src/libtracker-bus/tracker-bus-shared.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2006, Jamie McCracken <jamiemcc gnome org>
+ * Copyright (C) 2008-2010, Nokia <ivan frade nokia com>
+ * Copyright (C) 2010, Codeminded BVBA <philip codeminded be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <glib-object.h>
+
+#include <libtracker-common/tracker-common.h>
+#include <libtracker-sparql/tracker-sparql.h>
+
+#include "tracker-bus-shared.h"
+
+GVariant*
+tracker_bus_message_to_variant (DBusMessage *message)
+{
+ GVariantBuilder builder;
+ DBusMessageIter iter, subiter, subsubiter;
+
+ /*aaa{ss}*/
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); /* a */
+
+ dbus_message_iter_init (message, &iter);
+ dbus_message_iter_recurse (&iter, &subiter);
+
+ while (dbus_message_iter_get_arg_type (&subiter) != DBUS_TYPE_INVALID) {
+
+ g_variant_builder_open (&builder, G_VARIANT_TYPE_ARRAY); /* a */
+
+ dbus_message_iter_recurse (&subiter, &subsubiter);
+
+ while (dbus_message_iter_get_arg_type (&subsubiter) != DBUS_TYPE_INVALID) {
+ DBusMessageIter s_subiter, s_subsubiter;
+
+ dbus_message_iter_recurse (&subsubiter, &s_subiter);
+
+ while (dbus_message_iter_get_arg_type (&s_subiter) != DBUS_TYPE_INVALID) {
+ const gchar *key, *value;
+
+ g_variant_builder_open (&builder, G_VARIANT_TYPE_ARRAY); /* a */
+ g_variant_builder_open (&builder, G_VARIANT_TYPE_DICTIONARY); /* {ss} */
+
+ dbus_message_iter_recurse (&s_subiter, &s_subsubiter);
+ dbus_message_iter_get_basic (&s_subsubiter, &key);
+ dbus_message_iter_next (&s_subsubiter);
+ dbus_message_iter_get_basic (&s_subsubiter, &value);
+
+ g_variant_builder_add (&builder, "{ss}", key, value);
+
+ dbus_message_iter_next (&subiter);
+
+ g_variant_builder_close (&builder);
+ g_variant_builder_close (&builder);
+ }
+
+ dbus_message_iter_next (&subsubiter);
+ }
+
+ g_variant_builder_close (&builder);
+
+ dbus_message_iter_next (&subiter);
+ }
+
+ return g_variant_builder_end (&builder);
+}
diff --git a/src/libtracker-bus/tracker-bus-shared.h b/src/libtracker-bus/tracker-bus-shared.h
new file mode 100644
index 0000000..85b2dff
--- /dev/null
+++ b/src/libtracker-bus/tracker-bus-shared.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2006, Jamie McCracken <jamiemcc gnome org>
+ * Copyright (C) 2008-2010, Nokia <ivan frade nokia com>
+ * Copyright (C) 2010, Codeminded BVBA <philip codeminded be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+G_BEGIN_DECLS
+
+GVariant* tracker_bus_message_to_variant (DBusMessage *message);
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]