No issues found
1 /*
2 * Copyright (C) 2009, Nokia <ivan.frade@nokia.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include <gio/gio.h>
21
22 #include <libtracker-sparql/tracker-sparql.h>
23
24 static TrackerSparqlConnection *con;
25
26 static void
27 handle_statement (gint subject, gint predicate)
28 {
29 gchar *query, *pred;
30 TrackerSparqlCursor *cursor;
31
32 query = g_strdup_printf ("SELECT tracker:uri (%d) tracker:uri(%d) {}",
33 subject, predicate);
34 cursor = tracker_sparql_connection_query (con, query, NULL, NULL);
35 g_free (query);
36 tracker_sparql_cursor_next (cursor, NULL, NULL);
37 pred = g_strdup (tracker_sparql_cursor_get_string (cursor, 1, NULL));
38 query = g_strdup_printf ("SELECT ?t { <%s> <%s> ?t }",
39 tracker_sparql_cursor_get_string (cursor, 0, NULL),
40 pred);
41 g_object_unref (cursor);
42 cursor = tracker_sparql_connection_query (con, query, NULL, NULL);
43 g_free (query);
44 while (tracker_sparql_cursor_next (cursor, NULL, NULL))
45 g_print ("\t%s = %s\n", pred, tracker_sparql_cursor_get_string (cursor, 0, NULL));
46 g_print ("\n");
47 g_free (pred);
48 g_object_unref (cursor);
49 }
50
51 static void
52 class_signal_cb (GDBusConnection *connection,
53 const gchar *sender_name,
54 const gchar *object_path,
55 const gchar *interface_name,
56 const gchar *signal_name,
57 GVariant *parameters,
58 gpointer user_data)
59
60 {
61 GVariantIter *iter1, *iter2;
62 gchar *class_name;
63 gint graph = 0, subject = 0, predicate = 0, object = 0;
64
65 g_variant_get (parameters, "(&sa(iiii)a(iiii))", &class_name, &iter1, &iter2);
66 g_print ("%s:\n", class_name);
67
68 while (g_variant_iter_loop (iter1, "(iiii)", &graph, &subject, &predicate, &object)) {
69 handle_statement (subject, predicate);
70 }
71
72 while (g_variant_iter_loop (iter2, "(iiii)", &graph, &subject, &predicate, &object)) {
73 handle_statement (subject, predicate);
74 }
75
76 g_variant_iter_free (iter1);
77 g_variant_iter_free (iter2);
78 }
79
80 gint
81 main (gint argc, gchar *argv[])
82 {
83 GMainLoop *loop;
84 GError *error = NULL;
85 GDBusConnection *connection;
86 guint signal_id;
87
88 loop = g_main_loop_new (NULL, FALSE);
89 con = tracker_sparql_connection_get (NULL, &error);
90 connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
91
92 signal_id = g_dbus_connection_signal_subscribe (connection,
93 TRACKER_DBUS_SERVICE,
94 TRACKER_DBUS_INTERFACE_RESOURCES,
95 "GraphUpdated",
96 TRACKER_DBUS_OBJECT_RESOURCES,
97 NULL, /* Use class-name here */
98 G_DBUS_SIGNAL_FLAGS_NONE,
99 class_signal_cb,
100 NULL,
101 NULL);
102
103 g_main_loop_run (loop);
104 g_dbus_connection_signal_unsubscribe (connection, signal_id);
105 g_main_loop_unref (loop);
106 g_object_unref (con);
107 g_object_unref (connection);
108
109 return 0;
110 }