[tracker/async-init-direct: 2/2] examples: Added an example that uses async connection construction



commit 8f045c327c12849c7dcd51e088faa0dea4de9c38
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Feb 22 12:48:21 2011 +0100

    examples: Added an example that uses async connection construction

 configure.ac                                 |    1 +
 examples/Makefile.am                         |   10 ++--
 examples/async-connection/.gitignore         |    1 +
 examples/async-connection/Makefile.am        |   13 ++++
 examples/async-connection/async-connection.c |   77 ++++++++++++++++++++++++++
 5 files changed, 97 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9f0e402..de53d98 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2112,6 +2112,7 @@ AC_CONFIG_FILES([
 	examples/libtracker-miner/Makefile
 	examples/rss-reader/Makefile
 	examples/class-signal/Makefile
+	examples/async-connection/Makefile
 ])
 
 AC_OUTPUT
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 0098884..21eb629 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 0000000..74a09d9
--- /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 0000000..84a22ea
--- /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 0000000..ea60476
--- /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;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]