[tracker/dbus-fd-experiment-squashed: 3/6] Add Steroids example client
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/dbus-fd-experiment-squashed: 3/6] Add Steroids example client
- Date: Fri, 4 Jun 2010 01:19:27 +0000 (UTC)
commit 505976793ddd5b2adc54d215b6de1cc047b73478
Author: Adrien Bustany <abustany gnome org>
Date: Mon May 24 11:54:48 2010 -0400
Add Steroids example client
This commit adds a steroids-sparql program. This program shows how to
use the tracker_resources_sparql_query_iterate function to do a query
and fetch the results. It does exactly the same thing as
tracker-sparql -q. This commit also adds an async version.
configure.ac | 1 +
examples/Makefile.am | 3 +-
examples/steroids/Makefile.am | 35 ++++++++++++++++
examples/steroids/steroids-sparql-async.c | 62 +++++++++++++++++++++++++++++
examples/steroids/steroids-sparql.c | 50 +++++++++++++++++++++++
5 files changed, 150 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0fa13a9..7e3c4b1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1971,6 +1971,7 @@ AC_CONFIG_FILES([
examples/libtracker-extract/Makefile
examples/libtracker-miner/Makefile
examples/rss-reader/Makefile
+ examples/steroids/Makefile
])
AC_OUTPUT
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 41a8a67..2eacd64 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -3,4 +3,5 @@ include $(top_srcdir)/Makefile.decl
SUBDIRS = \
libtracker-extract \
libtracker-miner \
- rss-reader
+ rss-reader \
+ steroids
diff --git a/examples/steroids/Makefile.am b/examples/steroids/Makefile.am
new file mode 100644
index 0000000..55abdbb
--- /dev/null
+++ b/examples/steroids/Makefile.am
@@ -0,0 +1,35 @@
+include $(top_srcdir)/Makefile.decl
+
+INCLUDES = \
+ -DSHAREDIR=\""$(datadir)"\" \
+ -DG_LOG_DOMAIN=\"Tracker\" \
+ -DTRACKER_COMPILATION \
+ -I$(top_srcdir)/src \
+ -I$(top_builddir)/src \
+ -I$(top_builddir)/src/libtracker-client \
+ $(WARN_CFLAGS) \
+ $(GLIB2_CFLAGS) \
+ $(GCOV_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(DBUS_CFLAGS)
+
+noinst_PROGRAMS = \
+ steroids-sparql \
+ steroids-sparql-async
+
+steroids_sparql_SOURCES = \
+ steroids-sparql.c
+
+steroids_sparql_LDADD = \
+ $(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(DBUS_LIBS) \
+ $(GMODULE_LIBS) \
+ $(GTHREAD_LIBS) \
+ $(GIO_LIBS) \
+ $(GCOV_LIBS) \
+ $(GLIB2_LIBS) \
+ -lz \
+ -lm
+
+steroids_sparql_async_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;
+}
diff --git a/examples/steroids/steroids-sparql.c b/examples/steroids/steroids-sparql.c
new file mode 100644
index 0000000..4178150
--- /dev/null
+++ b/examples/steroids/steroids-sparql.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libtracker-client/tracker.h>
+
+int
+main (int argc, char **argv) {
+ const char *query;
+ TrackerClient *client;
+ GError *error = NULL;
+ TrackerResultIterator *iterator;
+
+ if (argc != 2) {
+ fprintf (stderr, "Usage: %s query\n", argv[0]);
+ exit (1);
+ }
+
+ query = argv[1];
+
+ client = tracker_client_new (0, 0);
+
+ iterator = tracker_resources_sparql_query_iterate (client, query, &error);
+
+ 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);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]