[gnome-power-manager] trivial: remove egg-dbus-proxy and use the provided functions in GDBus



commit ae6370d06c454ab6f48436536350cf92d37a00d6
Author: Richard Hughes <richard hughsie com>
Date:   Sun Jun 27 14:00:09 2010 +0100

    trivial: remove egg-dbus-proxy and use the provided functions in GDBus

 src/Makefile.am        |    2 -
 src/egg-dbus-monitor.c |  251 ------------------------------------------------
 src/egg-dbus-monitor.h |   65 -------------
 src/gpm-phone.c        |   77 ++++++----------
 4 files changed, 28 insertions(+), 367 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a3cf214..0ff3a00 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -65,8 +65,6 @@ libgpmshared_a_SOURCES =				\
 	egg-array-float.h				\
 	egg-idletime.h					\
 	egg-idletime.c					\
-	egg-dbus-monitor.h				\
-	egg-dbus-monitor.c				\
 	egg-discrete.h					\
 	egg-discrete.c					\
 	egg-string.h					\
diff --git a/src/gpm-phone.c b/src/gpm-phone.c
index 5773f74..22bf232 100644
--- a/src/gpm-phone.c
+++ b/src/gpm-phone.c
@@ -24,14 +24,13 @@
 #include <string.h>
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <gio/gio.h>
 #include <dbus/dbus-glib.h>
 
 #include "gpm-phone.h"
 #include "egg-debug.h"
 #include "gpm-marshal.h"
 
-#include "egg-dbus-monitor.h"
-
 static void     gpm_phone_finalize   (GObject	    *object);
 
 #define GPM_PHONE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_PHONE, GpmPhonePrivate))
@@ -40,7 +39,7 @@ struct GpmPhonePrivate
 {
 	DBusGProxy		*proxy;
 	DBusGConnection		*connection;
-	EggDbusMonitor		*monitor;
+	guint			 watch_id;
 	gboolean		 present;
 	guint			 percentage;
 	gboolean		 onac;	 
@@ -142,7 +141,6 @@ gpm_phone_get_num_batteries (GpmPhone *phone)
 static void
 gpm_phone_battery_state_changed (DBusGProxy *proxy, guint idx, guint percentage, gboolean on_ac, GpmPhone *phone)
 {
-	g_return_if_fail (phone != NULL);
 	g_return_if_fail (GPM_IS_PHONE (phone));
 
 	egg_debug ("got BatteryStateChanged %i = %i (%i)", idx, percentage, on_ac);
@@ -158,7 +156,6 @@ gpm_phone_battery_state_changed (DBusGProxy *proxy, guint idx, guint percentage,
 static void
 gpm_phone_num_batteries_changed (DBusGProxy *proxy, guint number, GpmPhone *phone)
 {
-	g_return_if_fail (phone != NULL);
 	g_return_if_fail (GPM_IS_PHONE (phone));
 
 	egg_debug ("got NumberBatteriesChanged %i", number);
@@ -227,15 +224,16 @@ gpm_phone_class_init (GpmPhoneClass *klass)
 }
 
 /**
- * gpm_phone_dbus_connect:
- **/
-static gboolean
-gpm_phone_dbus_connect (GpmPhone *phone)
+ * gpm_phone_service_appeared_cb:
+ */
+static void
+gpm_phone_service_appeared_cb (GDBusConnection *connection,
+			       const gchar *name, const gchar *name_owner,
+			       GpmPhone *phone)
 {
 	GError *error = NULL;
 
-	g_return_val_if_fail (phone != NULL, FALSE);
-	g_return_val_if_fail (GPM_IS_PHONE (phone), FALSE);
+	g_return_if_fail (GPM_IS_PHONE (phone));
 
 	if (phone->priv->connection == NULL) {
 		egg_debug ("get connection");
@@ -245,7 +243,7 @@ gpm_phone_dbus_connect (GpmPhone *phone)
 			egg_warning ("Could not connect to DBUS daemon: %s", error->message);
 			g_error_free (error);
 			phone->priv->connection = NULL;
-			return FALSE;
+			return;
 		}
 	}
 	if (phone->priv->proxy == NULL) {
@@ -260,7 +258,7 @@ gpm_phone_dbus_connect (GpmPhone *phone)
 			egg_warning ("Cannot connect, maybe the daemon is not running: %s", error->message);
 			g_error_free (error);
 			phone->priv->proxy = NULL;
-			return FALSE;
+			return;
 		}
 
 		/* complicated type. ick */
@@ -283,17 +281,17 @@ gpm_phone_dbus_connect (GpmPhone *phone)
 					     phone, NULL);
 
 	}
-	return TRUE;
 }
 
 /**
- * gpm_phone_dbus_disconnect:
- **/
-static gboolean
-gpm_phone_dbus_disconnect (GpmPhone *phone)
+ * gpm_phone_service_vanished_cb:
+ */
+static void
+gpm_phone_service_vanished_cb (GDBusConnection *connection,
+			        const gchar *name,
+			        GpmPhone *phone)
 {
-	g_return_val_if_fail (phone != NULL, FALSE);
-	g_return_val_if_fail (GPM_IS_PHONE (phone), FALSE);
+	g_return_if_fail (GPM_IS_PHONE (phone));
 
 	if (phone->priv->proxy != NULL) {
 		egg_debug ("removing proxy");
@@ -306,24 +304,7 @@ gpm_phone_dbus_disconnect (GpmPhone *phone)
 			g_signal_emit (phone, signals [DEVICE_REMOVED], 0, 0);
 		}
 	}
-	return TRUE;
-}
-
-/**
- * monitor_connection_cb:
- * @proxy: The dbus raw proxy
- * @status: The status of the service, where TRUE is connected
- * @screensaver: This class instance
- **/
-static void
-monitor_connection_cb (EggDbusMonitor *monitor,
-		     gboolean   status,
-		     GpmPhone  *phone)
-{
-	if (status)
-		gpm_phone_dbus_connect (phone);
-	else
-		gpm_phone_dbus_disconnect (phone);
+	return;
 }
 
 /**
@@ -333,7 +314,6 @@ monitor_connection_cb (EggDbusMonitor *monitor,
 static void
 gpm_phone_init (GpmPhone *phone)
 {
-	DBusGConnection *connection;
 	phone->priv = GPM_PHONE_GET_PRIVATE (phone);
 
 	phone->priv->connection = NULL;
@@ -342,12 +322,12 @@ gpm_phone_init (GpmPhone *phone)
 	phone->priv->percentage = 0;
 	phone->priv->onac = FALSE;
 
-	phone->priv->monitor = egg_dbus_monitor_new ();
-	g_signal_connect (phone->priv->monitor, "connection-changed",
-			  G_CALLBACK (monitor_connection_cb), phone);
-	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
-	egg_dbus_monitor_assign (phone->priv->monitor, connection, GNOME_PHONE_MANAGER_DBUS_SERVICE);
-	gpm_phone_dbus_connect (phone);
+	phone->priv->watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
+						  GNOME_PHONE_MANAGER_DBUS_SERVICE,
+						  G_BUS_NAME_WATCHER_FLAGS_NONE,
+						  (GBusNameAppearedCallback) gpm_phone_service_appeared_cb,
+						  (GBusNameVanishedCallback) gpm_phone_service_vanished_cb,
+						  phone, NULL);
 }
 
 /**
@@ -358,15 +338,14 @@ static void
 gpm_phone_finalize (GObject *object)
 {
 	GpmPhone *phone;
-	g_return_if_fail (object != NULL);
 	g_return_if_fail (GPM_IS_PHONE (object));
 
 	phone = GPM_PHONE (object);
 	phone->priv = GPM_PHONE_GET_PRIVATE (phone);
 
-	gpm_phone_dbus_disconnect (phone);
-	if (phone->priv->monitor != NULL)
-		g_object_unref (phone->priv->monitor);
+	if (phone->priv->proxy != NULL)
+		g_object_unref (phone->priv->proxy);
+	g_bus_unwatch_name (phone->priv->watch_id);
 
 	G_OBJECT_CLASS (gpm_phone_parent_class)->finalize (object);
 }



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