[tracker/libtracker-miner] TrackerMinerDiscover: turn into a GObject.



commit 5d5dc0b7d9e5d2e4c0624068df659eb286ee3690
Author: Carlos Garnacho <carlos lanedo com>
Date:   Tue Sep 1 16:58:52 2009 +0200

    TrackerMinerDiscover: turn into a GObject.

 src/libtracker-miner/tracker-miner-discover.c |  132 +++++++++++++++++--------
 src/libtracker-miner/tracker-miner-discover.h |   28 +++++-
 src/tracker-utils/tracker-status.c            |    6 +-
 3 files changed, 121 insertions(+), 45 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-discover.c b/src/libtracker-miner/tracker-miner-discover.c
index 616cfef..72fbaa0 100644
--- a/src/libtracker-miner/tracker-miner-discover.c
+++ b/src/libtracker-miner/tracker-miner-discover.c
@@ -27,52 +27,109 @@
 #include "tracker-miner.h"
 #include "tracker-miner-discover.h"
 
-GSList *
-tracker_miner_discover_get_running (void)
-{
+#define TRACKER_MINER_DISCOVER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_DISCOVER, TrackerMinerDiscoverPrivate))
+
+typedef struct TrackerMinerDiscoverPrivate TrackerMinerDiscoverPrivate;
+
+struct TrackerMinerDiscoverPrivate {
 	DBusGConnection *connection;
-	DBusGProxy *gproxy;
-	GSList *list;
+	DBusGProxy *proxy;
+	TrackerCrawler *crawler;
+};
+
+static void miner_discover_finalize (GObject *object);
+
+
+G_DEFINE_TYPE (TrackerMinerDiscover, tracker_miner_discover, G_TYPE_OBJECT)
+
+static void
+tracker_miner_discover_class_init (TrackerMinerDiscoverClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	object_class->finalize = miner_discover_finalize;
+
+	g_type_class_add_private (object_class, sizeof (TrackerMinerDiscoverPrivate));
+}
+
+static void
+tracker_miner_discover_init (TrackerMinerDiscover *discover)
+{
+	TrackerMinerDiscoverPrivate *priv;
 	GError *error = NULL;
-	gchar **p, **result;
-	
-	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
 
-	if (!connection) {
+	priv = TRACKER_MINER_DISCOVER_GET_PRIVATE (discover);
+
+	priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+	if (!priv->connection) {
 		g_critical ("Could not connect to the DBus session bus, %s",
 			    error ? error->message : "no error given.");
 		g_clear_error (&error);
-		return NULL;
 	}
 
-	/* The definitions below (DBUS_SERVICE_DBUS, etc) are
-	 * predefined for us to just use (dbus_g_proxy_...)
-	 */
-	gproxy = dbus_g_proxy_new_for_name (connection,
-					    DBUS_SERVICE_DBUS,
-					    DBUS_PATH_DBUS,
-					    DBUS_INTERFACE_DBUS);
+	priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
+						 DBUS_SERVICE_DBUS,
+						 DBUS_PATH_DBUS,
+						 DBUS_INTERFACE_DBUS);
 
-	if (!gproxy) {
+	if (!priv->proxy) {
 		g_critical ("Could not get proxy for DBus service");
+	}
+
+	priv->crawler = tracker_crawler_new ();
+}
+
+static void
+miner_discover_finalize (GObject *object)
+{
+	TrackerMinerDiscoverPrivate *priv;
+
+	priv = TRACKER_MINER_DISCOVER_GET_PRIVATE (object);
+
+	if (priv->proxy) {
+		g_object_unref (priv->proxy);
+	}
+
+	if (priv->connection) {
+		dbus_g_connection_unref (priv->connection);
+	}
+
+	G_OBJECT_CLASS (tracker_miner_discover_parent_class)->finalize (object);
+}
+
+TrackerMinerDiscover *
+tracker_miner_discover_new (void)
+{
+	return g_object_new (TRACKER_TYPE_MINER_DISCOVER, NULL);
+}
+
+GSList *
+tracker_miner_discover_get_running (TrackerMinerDiscover *discover)
+{
+	TrackerMinerDiscoverPrivate *priv;
+	GSList *list = NULL;
+	GError *error = NULL;
+	gchar **p, **result;
+
+	g_return_val_if_fail (TRACKER_IS_MINER_DISCOVER (discover), NULL);
+
+	priv = TRACKER_MINER_DISCOVER_GET_PRIVATE (discover);
+
+	if (!priv->connection || !priv->proxy) {
 		return NULL;
 	}
 
-	if (!dbus_g_proxy_call (gproxy, "ListNames", &error, 
-				G_TYPE_INVALID, 
-				G_TYPE_STRV, &result, 
+	if (!dbus_g_proxy_call (priv->proxy, "ListNames", &error,
+				G_TYPE_INVALID,
+				G_TYPE_STRV, &result,
 				G_TYPE_INVALID)) {
 		g_critical ("Could not get a list of names registered on the session bus, %s",
 			    error ? error->message : "no error given");
 		g_clear_error (&error);
-		g_object_unref (gproxy);
 		return NULL;
 	}
 
-	g_object_unref (gproxy);
-
-	list = NULL;
-
 	if (result) {
 		for (p = result; *p; p++) {
 			if (g_str_has_prefix (*p, TRACKER_MINER_DBUS_NAME_PREFIX)) {
@@ -101,7 +158,7 @@ crawler_check_file_cb (TrackerCrawler *crawler,
 		gchar *p;
 
 		p = strstr (basename, ".service");
-		
+
 		if (p) {
 			GSList **list = user_data;
 
@@ -110,9 +167,9 @@ crawler_check_file_cb (TrackerCrawler *crawler,
 		} else {
 			g_free (basename);
 		}
-		
+
 		return TRUE;
-	} 
+	}
 
 	g_free (basename);
 
@@ -123,9 +180,9 @@ static void
 crawler_finished_cb (TrackerCrawler *crawler,
 		     GQueue         *found,
 		     gboolean        was_interrupted,
-		     guint           directories_found, 
-		     guint           directories_ignored, 
-		     guint           files_found, 
+		     guint           directories_found,
+		     guint           directories_ignored,
+		     guint           files_found,
 		     guint           files_ignored,
 		     gpointer        user_data)
 {
@@ -133,7 +190,7 @@ crawler_finished_cb (TrackerCrawler *crawler,
 }
 
 GSList *
-tracker_miner_discover_get_available (void)
+tracker_miner_discover_get_available (TrackerMinerDiscover *discover)
 {
 	GSList *list = NULL;
 	GMainLoop *main_loop;
@@ -141,17 +198,12 @@ tracker_miner_discover_get_available (void)
 	TrackerCrawler *crawler;
 
 	crawler = tracker_crawler_new ();
-	if (!crawler) {
-		g_critical ("Couldn't create TrackerCrawler object");
-		return NULL;
-	}
-
 	main_loop = g_main_loop_new (NULL, FALSE);
 
-	g_signal_connect (crawler, "check-file", 
+	g_signal_connect (crawler, "check-file",
 			  G_CALLBACK (crawler_check_file_cb),
 			  &list);
-	g_signal_connect (crawler, "finished", 
+	g_signal_connect (crawler, "finished",
 			  G_CALLBACK (crawler_finished_cb),
 			  main_loop);
 
diff --git a/src/libtracker-miner/tracker-miner-discover.h b/src/libtracker-miner/tracker-miner-discover.h
index 38c2a56..37cebdb 100644
--- a/src/libtracker-miner/tracker-miner-discover.h
+++ b/src/libtracker-miner/tracker-miner-discover.h
@@ -21,12 +21,34 @@
 #ifndef __LIBTRACKERMINER_DISCOVER_H__
 #define __LIBTRACKERMINER_DISCOVER_H__
 
-#include <glib.h>
+#include <glib-object.h>
 
 G_BEGIN_DECLS
 
-GSList *tracker_miner_discover_get_running   (void);
-GSList *tracker_miner_discover_get_available (void);
+#define TRACKER_TYPE_MINER_DISCOVER         (tracker_miner_discover_get_type())
+#define TRACKER_MINER_DISCOVER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_MINER_DISCOVER, TrackerMinerDiscover))
+#define TRACKER_MINER_DISCOVER_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c),    TRACKER_TYPE_MINER_DISCOVER, TrackerMinerDiscoverClass))
+#define TRACKER_IS_MINER_DISCOVER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_MINER_DISCOVER))
+#define TRACKER_IS_MINER_DISCOVER_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),    TRACKER_TYPE_MINER_DISCOVER))
+#define TRACKER_MINER_DISCOVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),  TRACKER_TYPE_MINER_DISCOVER, TrackerMinerDiscoverClass))
+
+typedef struct TrackerMinerDiscover TrackerMinerDiscover;
+typedef struct TrackerMinerDiscoverClass TrackerMinerDiscoverClass;
+
+struct TrackerMinerDiscover {
+	GObject parent_instance;
+};
+
+struct TrackerMinerDiscoverClass {
+	GObjectClass parent_class;
+};
+
+GType   tracker_miner_discover_get_type (void) G_GNUC_CONST;
+
+TrackerMinerDiscover * tracker_miner_discover_new (void);
+
+GSList *tracker_miner_discover_get_running   (TrackerMinerDiscover *discover);
+GSList *tracker_miner_discover_get_available (TrackerMinerDiscover *discover);
 
 G_END_DECLS
 
diff --git a/src/tracker-utils/tracker-status.c b/src/tracker-utils/tracker-status.c
index 41d14e0..437cfd0 100644
--- a/src/tracker-utils/tracker-status.c
+++ b/src/tracker-utils/tracker-status.c
@@ -403,6 +403,7 @@ miner_get_details (const gchar  *miner,
 gint
 main (gint argc, gchar *argv[])
 {
+	TrackerMinerDiscover *discover;
 	GOptionContext *context;
 	DBusGProxy *proxy;
 	TrackerClient *client;
@@ -475,8 +476,9 @@ main (gint argc, gchar *argv[])
 		return EXIT_SUCCESS;
 	}
 
-	miners_available = tracker_miner_discover_get_available ();
-	miners_running = tracker_miner_discover_get_running ();
+	discover = tracker_miner_discover_new ();
+	miners_available = tracker_miner_discover_get_available (discover);
+	miners_running = tracker_miner_discover_get_running (discover);
 
 	if (list_miners_available) {
 		gchar *str;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]