[tracker/dbus-fd-experiment: 3/13] Add Steroids example client



commit 1074f3edc5bef5aab79bae32f2a39284df7f2d18
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.

 configure.ac                        |    1 +
 examples/Makefile.am                |    3 +-
 examples/steroids/Makefile.am       |   31 +++++++++++++++++++++
 examples/steroids/steroids-sparql.c |   50 +++++++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a5bad87..2505edc 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..19fe433
--- /dev/null
+++ b/examples/steroids/Makefile.am
@@ -0,0 +1,31 @@
+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_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
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]