[tracker/direct-access] libtracker-bus: Added skeleton for update_blank and update_blank_async
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/direct-access] libtracker-bus: Added skeleton for update_blank and update_blank_async
- Date: Thu, 22 Jul 2010 12:39:20 +0000 (UTC)
commit 81ac0a04010027553574d1ccdbea1678384b4c6e
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Jul 22 14:37:15 2010 +0200
libtracker-bus: Added skeleton for update_blank and update_blank_async
src/libtracker-bus/Makefile.am | 10 ++-
src/libtracker-bus/tracker-bus-array-update.c | 108 +++++++++++++++++++++++++
src/libtracker-bus/tracker-bus-array-update.h | 33 ++++++++
src/libtracker-bus/tracker-bus-fd-update.c | 86 +++++++++-----------
src/libtracker-bus/tracker-bus-fd-update.h | 40 +++++-----
src/libtracker-bus/tracker-bus-fd-update.vapi | 7 +-
src/libtracker-bus/tracker-bus.vala | 32 +++++++
src/libtracker-sparql/tracker-connection.vala | 10 +++
8 files changed, 250 insertions(+), 76 deletions(-)
---
diff --git a/src/libtracker-bus/Makefile.am b/src/libtracker-bus/Makefile.am
index ff85c09..1061415 100644
--- a/src/libtracker-bus/Makefile.am
+++ b/src/libtracker-bus/Makefile.am
@@ -33,7 +33,9 @@ libtracker_bus_la_SOURCES = \
tracker-bus-fd-cursor.h \
tracker-bus-fd-cursor.c \
tracker-bus-fd-update.c \
- tracker-bus-fd-update.h
+ tracker-bus-fd-update.h \
+ tracker-bus-array-update.c \
+ tracker-bus-array-update.h
libtracker_bus_la_LDFLAGS = \
-module -avoid-version -no-undefined
@@ -46,10 +48,12 @@ vapi_sources = \
config.vapi \
$(top_srcdir)/src/libtracker-sparql/tracker-sparql-$(TRACKER_API_VERSION).vapi \
$(top_srcdir)/src/libtracker-bus/tracker-bus-fd-cursor.vapi \
- $(top_srcdir)/src/libtracker-common/libtracker-common.vapi
+ $(top_srcdir)/src/libtracker-common/libtracker-common.vapi \
+ tracker-bus-fd-update.vapi \
+ tracker-bus-array-update.vapi
libtracker-bus.vala.stamp: $(libtracker_bus_la_VALASOURCES) $(vapi_sources)
- $(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 -H tracker-bus.h --vapi tracker-bus-$(TRACKER_API_VERSION).vapi tracker-bus-fd-update.vapi $^
+ $(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 -H tracker-bus.h --vapi tracker-bus-$(TRACKER_API_VERSION).vapi $^
$(AM_V_GEN)touch $@
libtracker_bus_la_LIBADD = \
diff --git a/src/libtracker-bus/tracker-bus-array-update.c b/src/libtracker-bus/tracker-bus-array-update.c
new file mode 100644
index 0000000..40121b6
--- /dev/null
+++ b/src/libtracker-bus/tracker-bus-array-update.c
@@ -0,0 +1,108 @@
+/*
+ * 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-array-update.h"
+#include "tracker-bus.h"
+
+void
+tracker_bus_array_sparql_update_blank_async (DBusGConnection *connection,
+ const gchar *query,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+#ifdef HAVE_DBUS_FD_PASSING
+
+ g_critical ("tracker_bus_array_sparql_update_blank_async unimplemented");
+ // todo
+
+#else /* HAVE_DBUS_FD_PASSING */
+ g_assert_not_reached ();
+#endif /* HAVE_DBUS_FD_PASSING */
+}
+
+
+GVariant *
+tracker_bus_array_sparql_update_blank (DBusGConnection *connection,
+ const gchar *query,
+ GError **error)
+{
+#ifdef HAVE_DBUS_FD_PASSING
+ DBusMessage *reply;
+ GVariant *result;
+
+ g_return_val_if_fail (query != NULL, NULL);
+
+ g_critical ("tracker_bus_array_sparql_update_blank unimplemented");
+ // reply = todo
+
+ if (!reply) {
+ return NULL;
+ }
+
+ if (g_strcmp0 (dbus_message_get_signature (reply), "aaa{ss}")) {
+ g_set_error (error,
+ TRACKER_SPARQL_ERROR,
+ TRACKER_SPARQL_ERROR_UNSUPPORTED,
+ "Server returned invalid results");
+ dbus_message_unref (reply);
+ return NULL;
+ }
+
+ //result = message_to_variant (reply);
+ dbus_message_unref (reply);
+
+ return result;
+#else /* HAVE_DBUS_FD_PASSING */
+ g_assert_not_reached ();
+ return NULL;
+#endif /* HAVE_DBUS_FD_PASSING */
+}
+
+GVariant *
+tracker_bus_array_sparql_update_blank_finish (GAsyncResult *res,
+ GError **error)
+{
+#ifdef HAVE_DBUS_FD_PASSING
+ g_return_val_if_fail (res != NULL, NULL);
+
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) {
+ return NULL;
+ }
+
+ return g_object_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;
+#endif /* HAVE_DBUS_FD_PASSING */
+}
diff --git a/src/libtracker-bus/tracker-bus-array-update.h b/src/libtracker-bus/tracker-bus-array-update.h
new file mode 100644
index 0000000..d6d5758
--- /dev/null
+++ b/src/libtracker-bus/tracker-bus-array-update.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2008-2010, Nokia <ivan frade nokia com>
+ *
+ * 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 <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib.h>
+
+void tracker_bus_array_sparql_update_blank_async (DBusGConnection *connection,
+ const gchar *query,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GVariant * tracker_bus_array_sparql_update_blank (DBusGConnection *connection,
+ const gchar *query,
+ GError **error);
+GVariant * tracker_bus_array_sparql_update_blank_finish (GAsyncResult *res,
+ GError **error);
diff --git a/src/libtracker-bus/tracker-bus-fd-update.c b/src/libtracker-bus/tracker-bus-fd-update.c
index 1638686..8440b7e 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.c
+++ b/src/libtracker-bus/tracker-bus-fd-update.c
@@ -111,7 +111,7 @@ fast_async_data_new (DBusConnection *connection,
return data;
}
-
+/*
static GHashTable *
unmarshal_hash_table (DBusMessageIter *iter)
{
@@ -144,6 +144,34 @@ 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
@@ -153,8 +181,7 @@ sparql_update_fast_callback (DBusPendingCall *call,
FastAsyncData *fad = user_data;
DBusMessage *reply;
GError *error = NULL;
- DBusMessageIter iter, subiter, subsubiter;
- GPtrArray *result;
+ GVariant *result;
/* Check for errors */
reply = dbus_pending_call_steal_reply (call);
@@ -186,30 +213,11 @@ sparql_update_fast_callback (DBusPendingCall *call,
g_simple_async_result_complete (fad->res);
break;
case FAST_UPDATE_BLANK:
- result = g_ptr_array_new_with_free_func (free_inner_array);
- 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_with_free_func ((GDestroyNotify) g_hash_table_unref);
- 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);
- }
-
+ result = message_to_variant (reply);
g_simple_async_result_set_op_res_gpointer (fad->res, result, NULL);
-
g_simple_async_result_complete (fad->res);
-
- g_ptr_array_free (result, TRUE);
+ dbus_message_unref (reply);
+ g_variant_unref (result);
break;
default:
@@ -444,7 +452,7 @@ tracker_bus_fd_sparql_update_finish (GAsyncResult *res,
#endif /* HAVE_DBUS_FD_PASSING */
}
-GPtrArray*
+GVariant *
tracker_bus_fd_sparql_update_blank_finish (GAsyncResult *res,
GError **error)
{
@@ -462,15 +470,14 @@ tracker_bus_fd_sparql_update_blank_finish (GAsyncResult *res,
#endif /* HAVE_DBUS_FD_PASSING */
}
-GPtrArray *
+GVariant *
tracker_bus_fd_sparql_update_blank (DBusGConnection *connection,
const gchar *query,
GError **error)
{
#ifdef HAVE_DBUS_FD_PASSING
DBusMessage *reply;
- DBusMessageIter iter, subiter, subsubiter;
- GPtrArray *result;
+ GVariant *result;
g_return_val_if_fail (query != NULL, NULL);
@@ -490,25 +497,7 @@ tracker_bus_fd_sparql_update_blank (DBusGConnection *connection,
return NULL;
}
- result = g_ptr_array_new_with_free_func (free_inner_array);
- 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_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);
- }
-
+ result = message_to_variant (reply);
dbus_message_unref (reply);
return result;
@@ -554,3 +543,4 @@ tracker_bus_fd_sparql_update_blank_async (DBusGConnection *connection,
g_assert_not_reached ();
#endif /* HAVE_DBUS_FD_PASSING */
}
+
diff --git a/src/libtracker-bus/tracker-bus-fd-update.h b/src/libtracker-bus/tracker-bus-fd-update.h
index 21ccc3c..7ea91b8 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.h
+++ b/src/libtracker-bus/tracker-bus-fd-update.h
@@ -23,25 +23,25 @@
G_BEGIN_DECLS
-void tracker_bus_fd_sparql_update (DBusGConnection *connection,
- const char *query,
- GError **error);
-void tracker_bus_fd_sparql_update_async (DBusGConnection *connection,
- const char *query,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-GPtrArray * tracker_bus_fd_sparql_update_blank (DBusGConnection *connection,
- const gchar *query,
- GError **error);
-void tracker_bus_fd_sparql_update_blank_async (DBusGConnection *connection,
- const gchar *query,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-void tracker_bus_fd_sparql_update_finish (GAsyncResult *res,
- GError **error);
-GPtrArray* tracker_bus_fd_sparql_update_blank_finish (GAsyncResult *res,
- GError **error);
+void tracker_bus_fd_sparql_update (DBusGConnection *connection,
+ const char *query,
+ GError **error);
+void tracker_bus_fd_sparql_update_async (DBusGConnection *connection,
+ const char *query,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GVariant * tracker_bus_fd_sparql_update_blank (DBusGConnection *connection,
+ const gchar *query,
+ GError **error);
+void tracker_bus_fd_sparql_update_blank_async (DBusGConnection *connection,
+ const gchar *query,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+void tracker_bus_fd_sparql_update_finish (GAsyncResult *res,
+ GError **error);
+GVariant * tracker_bus_fd_sparql_update_blank_finish (GAsyncResult *res,
+ GError **error);
G_END_DECLS
diff --git a/src/libtracker-bus/tracker-bus-fd-update.vapi b/src/libtracker-bus/tracker-bus-fd-update.vapi
index 2546a56..67c770c 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.vapi
+++ b/src/libtracker-bus/tracker-bus-fd-update.vapi
@@ -17,14 +17,11 @@
* Boston, MA 02110-1301, USA.
*/
-/* This .vapi file is a workaround for bug fixed in this commit for valac:
- * http://git.gnome.org/browse/vala/commit/?id=7757cf9ecf6084413f409ba31c31ed73cacd6ec1*/
-
[CCode (cheader_filename = "tracker-bus-fd-update.h")]
public void tracker_bus_fd_sparql_update (DBus.Connection connection, string query) throws Tracker.Sparql.Error;
[CCode (cheader_filename = "tracker-bus-fd-update.h")]
-public extern GLib.PtrArray tracker_bus_fd_sparql_update_blank (DBus.Connection connection, string query) throws Tracker.Sparql.Error;
+public extern GLib.Variant tracker_bus_fd_sparql_update_blank (DBus.Connection connection, string query) throws Tracker.Sparql.Error;
[CCode (cheader_filename = "tracker-bus-fd-update.h")]
public extern async void tracker_bus_fd_sparql_update_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error;
[CCode (cheader_filename = "tracker-bus-fd-update.h")]
-public extern async uint tracker_bus_fd_sparql_update_blank_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error;
+public extern async GLib.Variant tracker_bus_fd_sparql_update_blank_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error;
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 331c7ab..f686806 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -137,6 +137,38 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
}
}
+ public override GLib.Variant? update_blank (string sparql, Cancellable? cancellable = null) throws Sparql.Error {
+ GLib.Variant res = null;
+
+ try {
+ if (use_steroids) {
+ res = tracker_bus_fd_sparql_update_blank (connection, sparql);
+ } else {
+ res = tracker_bus_array_sparql_update_blank (connection, sparql);
+ }
+ } catch (DBus.Error e) {
+ throw new Sparql.Error.INTERNAL (e.message);
+ }
+
+ return res;
+ }
+
+ public async override GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+ GLib.Variant res = null;
+
+ try {
+ if (use_steroids) {
+ res = yield tracker_bus_fd_sparql_update_blank_async (connection, sparql, cancellable);
+ } else {
+ res = yield tracker_bus_array_sparql_update_blank_async (connection, sparql, cancellable);
+ }
+ } catch (DBus.Error e) {
+ throw new Sparql.Error.INTERNAL (e.message);
+ }
+
+ return res;
+ }
+
public override void import (File file, Cancellable? cancellable = null) throws Sparql.Error {
try {
resources_object.import (file.get_uri ());
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index 5a26314..9dfa02a 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -143,6 +143,16 @@ public abstract class Tracker.Sparql.Connection : Object {
warning ("Interface 'update_async' not implemented");
}
+ // UpdateBlank
+ public virtual GLib.Variant? update_blank (string sparql, Cancellable? cancellable = null) throws Sparql.Error {
+ warning ("Interface 'update_blank' not implemented");
+ return null;
+ }
+ public async virtual GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+ warning ("Interface 'update_blank_async' not implemented");
+ return null;
+ }
+
// Only applies to update_async with the right priority.
// Priority is used to identify batch updates.
public virtual void update_commit (Cancellable? cancellable = null) throws Sparql.Error {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]