[tracker/direct-access: 82/158] libtracker-sparql: Added statistics{_async} virtual methods
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/direct-access: 82/158] libtracker-sparql: Added statistics{_async} virtual methods
- Date: Thu, 5 Aug 2010 16:34:28 +0000 (UTC)
commit 5d0fb366835e3b939403998a2b1ad9b387e543d6
Author: Martyn Russell <martyn lanedo com>
Date: Tue Jul 20 17:06:15 2010 +0100
libtracker-sparql: Added statistics{_async} virtual methods
libtracker-bus: Implement d-bus version of statistics API
tracker-stats: Reworked to use libtracker-sparql
src/libtracker-bus/tracker-bus.vala | 42 ++++++++++----
src/libtracker-sparql/tracker-connection.vala | 13 ++++
src/libtracker-sparql/tracker-plugin-loader.vala | 8 +++
src/tracker-utils/tracker-stats.c | 69 +++++++++++-----------
4 files changed, 87 insertions(+), 45 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 480abed..c6fbde3 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -27,13 +27,20 @@ private interface Tracker.Bus.Resources : GLib.Object {
public abstract async void sparql_update_async (string query) throws DBus.Error;
}
+[DBus (name = "org.freedesktop.Tracker1.Statistics")]
+private interface Tracker.Bus.Statistics : GLib.Object {
+ public abstract string[,] Get () throws DBus.Error;
+ public async abstract string[,] Get_async () throws DBus.Error;
+}
+
// Imported DBus FD API until we have support with Vala
public extern Tracker.Sparql.Cursor tracker_bus_fd_query (DBus.Connection connection, string query) throws GLib.Error;
// Actual class definition
public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
static DBus.Connection connection;
- static Resources resources;
+ static Resources resources_object;
+ static Statistics statistics_object;
static bool initialized;
static bool use_steroids;
@@ -42,14 +49,18 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
initialized = true;
try {
- connection = DBus.Bus.get (DBus.BusType.SESSION);
-
- // FIXME: Test for steroids and resources interfaces?
+ // FIXME: Test for steroids and resources interfaces?
use_steroids = false;
- resources = (Resources) connection.get_object (TRACKER_DBUS_SERVICE,
- TRACKER_DBUS_OBJECT_RESOURCES,
- TRACKER_DBUS_INTERFACE_RESOURCES);
+ connection = DBus.Bus.get (DBus.BusType.SESSION);
+
+ // FIXME: Ideally we would just get these as and when we need them
+ resources_object = (Resources) connection.get_object (TRACKER_DBUS_SERVICE,
+ TRACKER_DBUS_OBJECT_RESOURCES,
+ TRACKER_DBUS_INTERFACE_RESOURCES);
+ statistics_object = (Statistics) connection.get_object (TRACKER_DBUS_SERVICE,
+ TRACKER_DBUS_OBJECT_STATISTICS,
+ TRACKER_DBUS_INTERFACE_STATISTICS);
} catch (DBus.Error e) {
warning ("Could not connect to D-Bus service:'%s': %s", TRACKER_DBUS_INTERFACE_RESOURCES, e.message);
initialized = false;
@@ -71,11 +82,10 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
//
// Really we need #ifdef here, unsupported in vala AFAIK
-
if (use_steroids) {
return tracker_bus_fd_query (connection, sparql);
} else {
- string[,] results = resources.sparql_query (sparql);
+ string[,] results = resources_object.sparql_query (sparql);
return new Tracker.Bus.ArrayCursor ((owned) results, results.length[0], results.length[1]);
}
}
@@ -86,11 +96,21 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
}
public override void update (string sparql, Cancellable? cancellable = null) throws GLib.Error {
- resources.sparql_update (sparql);
+ resources_object.sparql_update (sparql);
}
public async override void update_async (string sparql, int? priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws GLib.Error {
- yield resources.sparql_update_async (sparql);
+ yield resources_object.sparql_update_async (sparql);
+ }
+
+ public override Sparql.Cursor? statistics (Cancellable? cancellable = null) throws GLib.Error {
+ string[,] results = statistics_object.Get ();
+ return new Tracker.Bus.ArrayCursor ((owned) results, results.length[0], results.length[1]);
+ }
+
+ public async override Sparql.Cursor? statistics_async (Cancellable? cancellable = null) throws GLib.Error {
+ string[,] results = yield statistics_object.Get_async ();
+ return new Tracker.Bus.ArrayCursor ((owned) results, results.length[0], results.length[1]);
}
}
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index e7d5ef4..83ba7a6 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -21,6 +21,8 @@
public const string TRACKER_DBUS_SERVICE = "org.freedesktop.Tracker1";
public const string TRACKER_DBUS_INTERFACE_RESOURCES = TRACKER_DBUS_SERVICE + ".Resources";
public const string TRACKER_DBUS_OBJECT_RESOURCES = "/org/freedesktop/Tracker1/Resources";
+public const string TRACKER_DBUS_INTERFACE_STATISTICS = TRACKER_DBUS_SERVICE + ".Statistics";
+public const string TRACKER_DBUS_OBJECT_STATISTICS = "/org/freedesktop/Tracker1/Statistics";
public const string TRACKER_DBUS_INTERFACE_STEROIDS = TRACKER_DBUS_SERVICE + ".Steroids";
public const string TRACKER_DBUS_OBJECT_STEROIDS = "/org/freedesktop/Tracker1/Steroids";
@@ -81,4 +83,15 @@ public abstract class Tracker.Sparql.Connection : Object {
public async virtual void import_async (File file, Cancellable? cancellable = null) throws GLib.Error {
warning ("Interface 'import_async' not implemented");
}
+
+ // Statistics
+ public virtual Cursor? statistics (Cancellable? cancellable = null) throws GLib.Error {
+ warning ("Interface 'statistics' not implemented");
+ return null;
+ }
+
+ public async virtual Cursor? statistics_async (Cancellable? cancellable = null) throws GLib.Error {
+ warning ("Interface 'statistics_async' not implemented");
+ return null;
+ }
}
diff --git a/src/libtracker-sparql/tracker-plugin-loader.vala b/src/libtracker-sparql/tracker-plugin-loader.vala
index c1abaa7..2935ca4 100644
--- a/src/libtracker-sparql/tracker-plugin-loader.vala
+++ b/src/libtracker-sparql/tracker-plugin-loader.vala
@@ -75,6 +75,14 @@ class Tracker.Sparql.PluginLoader : Connection {
yield bus.import_async (file, cancellable);
}
+ public override Cursor? statistics (Cancellable? cancellable = null) throws GLib.Error {
+ return bus.statistics (cancellable);
+ }
+
+ public async override Cursor? statistics_async (Cancellable? cancellable = null) throws GLib.Error {
+ return yield bus.statistics_async (cancellable);
+ }
+
// Plugin loading functions
private bool load_plugins (bool direct_only) throws GLib.Error {
string env_path = Environment.get_variable ("TRACKER_SPARQL_MODULE_PATH");
diff --git a/src/tracker-utils/tracker-stats.c b/src/tracker-utils/tracker-stats.c
index 3b215c1..7b5d9f5 100644
--- a/src/tracker-utils/tracker-stats.c
+++ b/src/tracker-utils/tracker-stats.c
@@ -28,7 +28,7 @@
#include <glib.h>
#include <glib/gi18n.h>
-#include <libtracker-client/tracker-client.h>
+#include <libtracker-sparql/tracker-sparql.h>
#define ABOUT \
"Tracker " PACKAGE_VERSION "\n"
@@ -50,33 +50,13 @@ static GOptionEntry entries[] = {
{ NULL }
};
-static void
-get_meta_table_data (gpointer value)
-{
- gchar **meta;
- gchar **p;
- gint i;
-
- meta = value;
-
- for (p = meta, i = 0; *p; p++, i++) {
- if (i == 0) {
- g_print (" %s", *p);
- } else {
- g_print (" = %s", *p);
- }
- }
-
- g_print ("\n");
-}
-
int
main (int argc, char **argv)
{
- TrackerClient *client;
+ TrackerSparqlConnection *connection;
+ TrackerSparqlCursor *cursor;
GOptionContext *context;
- GPtrArray *array;
- GError *error = NULL;
+ GError *error = NULL;
setlocale (LC_ALL, "");
@@ -99,37 +79,58 @@ main (int argc, char **argv)
g_option_context_free (context);
- client = tracker_client_new (0, G_MAXINT);
+ g_type_init ();
+
+ if (!g_thread_supported ()) {
+ g_thread_init (NULL);
+ }
- if (!client) {
- g_printerr ("%s\n",
- _("Could not establish a D-Bus connection to Tracker"));
+ connection = tracker_sparql_connection_get (&error);
+
+ if (!connection) {
+ g_printerr ("%s: %s\n",
+ _("Could not establish a connection to Tracker"),
+ error ? error->message : _("No error given"));
+ g_clear_error (&error);
return EXIT_FAILURE;
}
- array = tracker_statistics_get (client, &error);
+ cursor = tracker_sparql_connection_statistics (connection, NULL, &error);
if (error) {
g_printerr ("%s, %s\n",
_("Could not get Tracker statistics"),
error->message);
g_error_free (error);
-
return EXIT_FAILURE;
}
- if (!array) {
+ if (!cursor) {
g_print ("%s\n",
_("No statistics available"));
} else {
+ gint count = 0;
+
g_print ("%s\n",
_("Statistics:"));
- g_ptr_array_foreach (array, (GFunc) get_meta_table_data, NULL);
- g_ptr_array_free (array, TRUE);
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+ g_print (" %s = %s\n",
+ tracker_sparql_cursor_get_string (cursor, 0, NULL),
+ tracker_sparql_cursor_get_string (cursor, 1, NULL));
+ count++;
+ }
+
+ if (count == 0) {
+ g_print (" %s\n", _("None"));
+ }
+
+ g_print ("\n");
+
+ g_object_unref (cursor);
}
- g_object_unref (client);
+ g_object_unref (connection);
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]