summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPhilip Van Hoof <philip@codeminded.be>2011-02-22 12:48:21 +0100
committerPhilip Van Hoof <philip@codeminded.be>2011-02-22 13:00:50 +0100
commit9a97fceb91e35a2ac4030c665a45f336ef814cbd (patch)
treeee43acda7f7fe7abbbe9410071ca20e8c2a3cc7b /examples
parent74de6439853efdf75b8ac846f55a809807918430 (diff)
downloadtracker-9a97fceb91e35a2ac4030c665a45f336ef814cbd.tar.gz
examples: Added an example that uses async connection construction
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am10
-rw-r--r--examples/async-connection/.gitignore1
-rw-r--r--examples/async-connection/Makefile.am13
-rw-r--r--examples/async-connection/async-connection.c77
4 files changed, 96 insertions, 5 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 0098884cd..21eb6291f 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,7 +1,7 @@
include $(top_srcdir)/Makefile.decl
-SUBDIRS = \
- libtracker-extract \
- libtracker-miner \
- rss-reader \
- class-signal
+SUBDIRS = libtracker-extract \
+ libtracker-miner \
+ rss-reader \
+ class-signal \
+ async-connection
diff --git a/examples/async-connection/.gitignore b/examples/async-connection/.gitignore
new file mode 100644
index 000000000..74a09d9c7
--- /dev/null
+++ b/examples/async-connection/.gitignore
@@ -0,0 +1 @@
+async-connection
diff --git a/examples/async-connection/Makefile.am b/examples/async-connection/Makefile.am
new file mode 100644
index 000000000..84a22ea9e
--- /dev/null
+++ b/examples/async-connection/Makefile.am
@@ -0,0 +1,13 @@
+include $(top_srcdir)/Makefile.decl
+
+noinst_PROGRAMS = async-connection
+
+AM_CPPFLAGS = $(BUILD_CFLAGS) \
+ -I$(top_srcdir)/src \
+ $(LIBTRACKER_SPARQL_CFLAGS)
+
+LDADD = $(top_builddir)/src/libtracker-sparql/libtracker-sparql-$(TRACKER_API_VERSION).la \
+ $(BUILD_LIBS) \
+ $(LIBTRACKER_SPARQL_LIBS)
+
+async_connection_SOURCES = async-connection.c
diff --git a/examples/async-connection/async-connection.c b/examples/async-connection/async-connection.c
new file mode 100644
index 000000000..ea60476ea
--- /dev/null
+++ b/examples/async-connection/async-connection.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2009, Nokia <ivan.frade@nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 <gio/gio.h>
+#include <libtracker-sparql/tracker-sparql.h>
+
+typedef struct {
+ GMainLoop *loop;
+ GTimer *timer;
+} LoopTimer;
+
+static void
+on_connection (GObject *object, GAsyncResult *res, gpointer user_data)
+{
+ LoopTimer *lt = user_data;
+ GError *error = NULL;
+ gdouble ct;
+ TrackerSparqlConnection *con = tracker_sparql_connection_get_finish (res, &error);
+
+ ct = g_timer_elapsed (lt->timer, NULL);
+
+ g_timer_start (lt->timer);
+
+ if (!error) {
+ TrackerSparqlCursor *cursor;
+ cursor = tracker_sparql_connection_query (con, "SELECT ?r { ?r a rdfs:Resource }", NULL, NULL);
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+ g_print ("%s\n", tracker_sparql_cursor_get_string (cursor, 0, NULL));
+ }
+ g_object_unref (cursor);
+ g_object_unref (con);
+ } else {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ }
+
+ g_print ("Async construction took: %.6f\n", ct);
+ g_print ("Query took: %.6f\n", g_timer_elapsed (lt->timer, NULL));
+
+ g_main_loop_quit (lt->loop);
+}
+
+gint
+main (gint argc, gchar *argv[])
+{
+ LoopTimer lt;
+
+ g_type_init ();
+ lt.loop = g_main_loop_new (NULL, FALSE);
+
+ lt.timer = g_timer_new ();
+
+ tracker_sparql_connection_get_async (NULL, on_connection, &lt);
+
+ g_main_loop_run (lt.loop);
+
+ g_timer_destroy (lt.timer);
+ g_main_loop_unref (lt.loop);
+
+ return 0;
+}