[tracker/libtracker-miner] Removed tracker-dbus from libtracker-miner



commit 67e64ad5301750bdc8a6cf2af478d6db914b2d39
Author: Martyn Russell <martyn imendio com>
Date:   Tue Aug 18 13:57:20 2009 +0100

    Removed tracker-dbus from libtracker-miner
    
    The code has been added internally to tracker-miner.c

 data/dbus/tracker-miner.xml                  |   17 ++
 src/libtracker-miner/Makefile.am             |    2 -
 src/libtracker-miner/tracker-dbus.c          |  205 ------------------------
 src/libtracker-miner/tracker-dbus.h          |   37 -----
 src/libtracker-miner/tracker-miner-dbus.h    |    1 -
 src/libtracker-miner/tracker-miner-process.c |    2 +-
 src/libtracker-miner/tracker-miner.c         |  216 ++++++++++++++++++++++++--
 src/libtracker-miner/tracker-miner.h         |    3 +
 8 files changed, 226 insertions(+), 257 deletions(-)
---
diff --git a/data/dbus/tracker-miner.xml b/data/dbus/tracker-miner.xml
index 7d6f64a..82e05e4 100644
--- a/data/dbus/tracker-miner.xml
+++ b/data/dbus/tracker-miner.xml
@@ -2,11 +2,28 @@
 
 <node name="/">
   <interface name="org.freedesktop.Tracker.Miner">
+<!--
+    <method name="GetName">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="s" name="name" direction="out" />
+    </method>
+    <method name="GetStatus">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="s" name="status" direction="out" />
+    </method>
+    <method name="GetProgress">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="d" name="progress" direction="out" />
+    </method>
+-->
     <method name="Pause">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
     </method>
     <method name="Resume">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
     </method>
+    <signal name="Error">
+      <arg type="s" name="reason"/>
+    </signal>
   </interface>
 </node>
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 58f27a5..daa4396 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -26,8 +26,6 @@ libtracker_miner_LTLIBRARIES = libtracker-miner.la
 libtracker_miner_la_SOURCES = 				\
 	tracker-crawler.c				\
 	tracker-crawler.h				\
-	tracker-dbus.c					\
-	tracker-dbus.h					\
 	tracker-marshal.c				\
 	tracker-marshal.h				\
 	tracker-miner-dbus.h				\
diff --git a/src/libtracker-miner/tracker-miner-dbus.h b/src/libtracker-miner/tracker-miner-dbus.h
index 9088d86..927e338 100644
--- a/src/libtracker-miner/tracker-miner-dbus.h
+++ b/src/libtracker-miner/tracker-miner-dbus.h
@@ -23,7 +23,6 @@
 
 #include <glib-object.h>
 
-#include "tracker-dbus.h"
 #include "tracker-miner.h"
 
 G_BEGIN_DECLS
diff --git a/src/libtracker-miner/tracker-miner-process.c b/src/libtracker-miner/tracker-miner-process.c
index 8e57075..a629dd5 100644
--- a/src/libtracker-miner/tracker-miner-process.c
+++ b/src/libtracker-miner/tracker-miner-process.c
@@ -338,7 +338,7 @@ process_finalize (GObject *object)
 
 static gboolean 
 process_defaults (TrackerMinerProcess *process,
-		  GFile            *file)
+		  GFile               *file)
 {
 	return TRUE;
 }
diff --git a/src/libtracker-miner/tracker-miner.c b/src/libtracker-miner/tracker-miner.c
index 251f654..afee9e8 100644
--- a/src/libtracker-miner/tracker-miner.c
+++ b/src/libtracker-miner/tracker-miner.c
@@ -25,6 +25,7 @@
 #include "tracker-marshal.h"
 #include "tracker-miner.h"
 #include "tracker-miner-dbus.h"
+#include "tracker-miner-glue.h"
 
 #define TRACKER_MINER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER, TrackerMinerPrivate))
 
@@ -36,6 +37,12 @@ struct TrackerMinerPrivate {
 	gdouble progress;
 };
 
+typedef struct {
+	DBusGConnection *connection;
+	DBusGProxy      *gproxy;
+	GHashTable      *name_monitors;
+} DBusData;
+
 enum {
 	PROP_0,
 	PROP_NAME,
@@ -50,9 +57,12 @@ enum {
 	RESUMED,
 	TERMINATED,
 	PROGRESS,
+	ERROR,
 	LAST_SIGNAL
 };
 
+static GQuark dbus_data = 0;
+
 static guint signals[LAST_SIGNAL] = { 0 };
 
 
@@ -66,6 +76,9 @@ static void miner_get_property (GObject      *object,
 				GParamSpec   *pspec);
 static void miner_finalize     (GObject      *object);
 static void miner_constructed  (GObject      *object);
+static gboolean terminate_miner_cb (TrackerMiner *miner);
+static gboolean dbus_init (TrackerMiner *miner);
+static void dbus_shutdown (TrackerMiner *miner);
 
 G_DEFINE_ABSTRACT_TYPE (TrackerMiner, tracker_miner, G_TYPE_OBJECT)
 
@@ -123,12 +136,21 @@ tracker_miner_class_init (TrackerMinerClass *klass)
 		g_signal_new ("progress",
 			      G_OBJECT_CLASS_TYPE (object_class),
 			      G_SIGNAL_RUN_LAST,
-			      G_STRUCT_OFFSET (TrackerMinerClass, terminated),
+			      G_STRUCT_OFFSET (TrackerMinerClass, progress),
 			      NULL, NULL,
 			      tracker_marshal_VOID__STRING_DOUBLE,
 			      G_TYPE_NONE, 2,
 			      G_TYPE_STRING,
 			      G_TYPE_DOUBLE);
+	signals[ERROR] =
+		g_signal_new ("error",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (TrackerMinerClass, error),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__POINTER,
+			      G_TYPE_NONE, 1,
+			      G_TYPE_POINTER);
 
 	g_object_class_install_property (object_class,
 					 PROP_NAME,
@@ -227,9 +249,27 @@ miner_finalize (GObject *object)
 		tracker_disconnect (miner->private->client);
 	}
 
+	dbus_shutdown (miner);
+
 	G_OBJECT_CLASS (tracker_miner_parent_class)->finalize (object);
 }
 
+static void
+miner_constructed (GObject *object)
+{
+	TrackerMiner *miner = TRACKER_MINER (object);
+
+	if (!miner->private->name) {
+		g_critical ("Miner should have been given a name, bailing out");
+		g_assert_not_reached ();
+	}
+
+	if (!dbus_init (miner)) {
+		g_critical ("Could not register object to DBus");
+		g_idle_add ((GSourceFunc) terminate_miner_cb, miner);
+	}
+}
+
 static gboolean
 terminate_miner_cb (TrackerMiner *miner)
 {
@@ -238,20 +278,174 @@ terminate_miner_cb (TrackerMiner *miner)
 	return TRUE;
 }
 
+static gboolean
+dbus_register_service (DBusGProxy  *proxy,
+		       const gchar *name)
+{
+	GError *error = NULL;
+	guint	result;
+
+	g_message ("Registering DBus service...\n"
+		   "  Name:'%s'",
+		   name);
+
+	if (!org_freedesktop_DBus_request_name (proxy,
+						name,
+						DBUS_NAME_FLAG_DO_NOT_QUEUE,
+						&result, &error)) {
+		g_critical ("Could not acquire name:'%s', %s",
+			    name,
+			    error ? error->message : "no error given");
+		g_error_free (error);
+
+		return FALSE;
+	}
+
+	if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+		g_critical ("DBus service name:'%s' is already taken, "
+			    "perhaps the application is already running?",
+			    name);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static gboolean
+dbus_register_object (GObject		    *object,
+		      DBusGConnection	    *connection,
+		      DBusGProxy	    *proxy,
+		      const DBusGObjectInfo *info,
+		      const gchar	    *path)
+{
+	g_message ("Registering DBus object...");
+	g_message ("  Path:'%s'", path);
+	g_message ("  Object Type:'%s'", G_OBJECT_TYPE_NAME (object));
+
+	dbus_g_object_type_install_info (G_OBJECT_TYPE (object), info);
+	dbus_g_connection_register_g_object (connection, path, object);
+
+	return TRUE;
+}
+
 static void
-miner_constructed (GObject *object)
+dbus_data_destroy (gpointer data)
 {
-	TrackerMiner *miner = TRACKER_MINER (object);
+	DBusData *dd;
 
-	if (!miner->private->name) {
-		g_critical ("Miner should have been given a name, bailing out");
-		g_assert_not_reached ();
+	dd = data;
+
+	if (dd->gproxy) {
+		g_object_unref (dd->gproxy);
 	}
 
-	if (!tracker_dbus_init (miner)) {
-		g_critical ("Could not register object to DBus");
-		g_idle_add ((GSourceFunc) terminate_miner_cb, miner);
+	if (dd->connection) {
+		dbus_g_connection_unref (dd->connection);
+	}
+
+	if (dd->name_monitors) {
+		g_hash_table_destroy (dd->name_monitors);
+	}
+
+	g_slice_free (DBusData, dd);
+}
+
+static DBusData *
+dbus_data_create (TrackerMiner *miner,
+		  const gchar  *name)
+{
+	DBusData *data;
+	DBusGConnection *connection;
+	DBusGProxy *gproxy;
+	GError *error = NULL;
+	gchar *full_name, *full_path;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+	if (!connection) {
+		g_critical ("Could not connect to the DBus session bus, %s",
+			    error ? error->message : "no error given.");
+		g_error_free (error);
+		return NULL;
+	}
+
+	gproxy = dbus_g_proxy_new_for_name (connection,
+					    DBUS_SERVICE_DBUS,
+					    DBUS_PATH_DBUS,
+					    DBUS_INTERFACE_DBUS);
+
+	/* Register the service name for the miner */
+	full_name = g_strconcat ("org.freedesktop.Tracker.Miner.", name, NULL);
+
+	if (!dbus_register_service (gproxy, full_name)) {
+		g_object_unref (gproxy);
+		g_free (full_name);
+		return NULL;
 	}
+
+	g_free (full_name);
+
+	full_path = g_strconcat ("/org/freedesktop/Tracker/Miner/", name, NULL);
+
+	if (!dbus_register_object (G_OBJECT (miner),
+				   connection, gproxy,
+				   &dbus_glib_tracker_miner_object_info,
+				   full_path)) {
+		g_object_unref (gproxy);
+		g_free (full_path);
+		return NULL;
+	}
+
+	g_free (full_path);
+
+	/* Now we're successfully connected and registered, create the data */
+	data = g_slice_new0 (DBusData);
+	data->connection = dbus_g_connection_ref (connection);
+	data->gproxy = g_object_ref (gproxy);
+
+	return data;
+}
+
+static gboolean
+dbus_init (TrackerMiner *miner)
+{
+	DBusData *data;
+
+	g_return_val_if_fail (TRACKER_IS_MINER (miner), FALSE);
+
+	if (G_UNLIKELY (dbus_data == 0)) {
+		dbus_data = g_quark_from_static_string ("tracker-miner-dbus-data");
+	}
+
+	data = g_object_get_qdata (G_OBJECT (miner), dbus_data);
+
+	if (G_LIKELY (!data)) {
+		const gchar *name;
+
+		name = tracker_miner_get_name (miner);
+		data = dbus_data_create (miner, name);
+	}
+
+	if (G_UNLIKELY (!data)) {
+		return FALSE;
+	}
+
+	g_object_set_qdata_full (G_OBJECT (miner), 
+				 dbus_data, 
+				 data,
+				 dbus_data_destroy);
+
+	return TRUE;
+}
+
+static void
+dbus_shutdown (TrackerMiner *miner)
+{
+	if (dbus_data == 0) {
+		return;
+	}
+
+	g_object_set_qdata (G_OBJECT (miner), dbus_data, NULL);
 }
 
 G_CONST_RETURN gchar *
@@ -275,7 +469,7 @@ tracker_miner_get_status (TrackerMiner *miner)
 {
 	g_return_val_if_fail (TRACKER_IS_MINER (miner), NULL);
 
-	return g_strdup ("Idle");
+	return g_strdup (miner->private->status);
 }
 
 gdouble
@@ -283,7 +477,7 @@ tracker_miner_get_progress (TrackerMiner *miner)
 {
 	g_return_val_if_fail (TRACKER_IS_MINER (miner), 0.0);
 
-	return 0.0;
+	return miner->private->progress;
 }
 
 /* DBus methods */
diff --git a/src/libtracker-miner/tracker-miner.h b/src/libtracker-miner/tracker-miner.h
index e5bd133..999df76 100644
--- a/src/libtracker-miner/tracker-miner.h
+++ b/src/libtracker-miner/tracker-miner.h
@@ -56,6 +56,9 @@ struct TrackerMinerClass {
 	void (* progress)   (TrackerMiner *miner,
 			     const gchar  *status,
 			     gdouble       progress);
+
+	void (* error)      (TrackerMiner *miner,
+			     GError       *error);
 };
 
 



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