[tracker/dbus-fd-experiment-gio: 25/41] Add example for async steroids query
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/dbus-fd-experiment-gio: 25/41] Add example for async steroids query
- Date: Thu, 10 Jun 2010 22:54:19 +0000 (UTC)
commit 0d6c3356248b20d1332f8a71edca752ce508a807
Author: Adrien Bustany <abustany gnome org>
Date: Thu Jun 3 20:31:59 2010 -0400
Add example for async steroids query
examples/steroids/Makefile.am | 8 +++-
examples/steroids/steroids-sparql-async.c | 62 +++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletions(-)
---
diff --git a/examples/steroids/Makefile.am b/examples/steroids/Makefile.am
index 09dda67..7824e77 100644
--- a/examples/steroids/Makefile.am
+++ b/examples/steroids/Makefile.am
@@ -13,7 +13,11 @@ INCLUDES = \
$(GIO_CFLAGS) \
$(DBUS_CFLAGS)
-noinst_PROGRAMS = steroids-sparql benchmark benchmark-update
+noinst_PROGRAMS = \
+ steroids-sparql \
+ steroids-sparql-async \
+ benchmark \
+ benchmark-update
steroids_sparql_SOURCES = \
steroids-sparql.c
@@ -34,6 +38,8 @@ steroids_sparql_LDADD = \
-lz \
-lm
+steroids_sparql_async_LDADD= $(steroids_sparql_LDADD)
+
benchmark_LDADD= $(steroids_sparql_LDADD)
benchmark_update_LDADD= $(steroids_sparql_LDADD)
diff --git a/examples/steroids/steroids-sparql-async.c b/examples/steroids/steroids-sparql-async.c
new file mode 100644
index 0000000..7802f94
--- /dev/null
+++ b/examples/steroids/steroids-sparql-async.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libtracker-client/tracker.h>
+
+static TrackerClient *client;
+static GMainLoop *main_loop;
+
+static void
+query_cb (TrackerResultIterator *iterator,
+ GError *error,
+ gpointer user_data)
+{
+ if (!iterator) {
+ fprintf (stderr, "Query preparation failed, %s\n", error->message);
+ g_error_free (error);
+ exit (1);
+ }
+
+ while (tracker_result_iterator_has_next (iterator)) {
+ int i;
+
+ tracker_result_iterator_next (iterator);
+
+ for (i = 0; i < tracker_result_iterator_n_columns (iterator); i++) {
+ printf ("%s", tracker_result_iterator_value (iterator, i));
+
+ if (i != tracker_result_iterator_n_columns (iterator) - 1) {
+ printf (", ");
+ }
+ }
+
+ printf ("\n");
+ }
+
+ tracker_result_iterator_free (iterator);
+ g_object_unref (client);
+
+ g_main_loop_quit (main_loop);
+}
+
+int
+main (int argc, char **argv) {
+ const char *query;
+
+ if (argc != 2) {
+ fprintf (stderr, "Usage: %s query\n", argv[0]);
+ exit (1);
+ }
+
+ query = argv[1];
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+
+ client = tracker_client_new (0, 0);
+
+ tracker_resources_sparql_query_iterate_async (client, query, query_cb, NULL);
+
+ g_main_loop_run (main_loop);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]