gnome-bluetooth r430 - trunk/properties



Author: hadess
Date: Tue Mar  3 15:04:19 2009
New Revision: 430
URL: http://svn.gnome.org/viewvc/gnome-bluetooth?rev=430&view=rev

Log:
Clean up

Remove debug, add safe guards around public functions,
fix memleaks.



Modified:
   trunk/properties/killswitch.c

Modified: trunk/properties/killswitch.c
==============================================================================
--- trunk/properties/killswitch.c	(original)
+++ trunk/properties/killswitch.c	Tue Mar  3 15:04:19 2009
@@ -26,10 +26,7 @@
 #include <config.h>
 #endif
 
-#include <glib/gi18n.h>
-
 #include <dbus/dbus-glib-lowlevel.h>
-
 #include <hal/libhal.h>
 
 #include "killswitch.h"
@@ -91,8 +88,6 @@
 	/* Look for the killswitch */
 	for (l = priv->killswitches; l ; l = l->next) {
 		BluetoothIndKillswitch *ind = l->data;
-		g_message ("comparing %p", call);
-		g_message ("with %p", ind->call);
 		if (call != ind->call)
 			continue;
 		ind->killed = (power > 0);
@@ -111,6 +106,8 @@
 	BluetoothKillswitchPrivate *priv = BLUETOOTH_KILLSWITCH_GET_PRIVATE (killswitch);
 	GList *l;
 
+	g_return_if_fail (BLUETOOTH_IS_KILLSWITCH (killswitch));
+
 	for (l = priv->killswitches ; l ; l = l->next) {
 		BluetoothIndKillswitch *ind = l->data;
 		DBusPendingCall *call;
@@ -146,6 +143,7 @@
 	gboolean value;
 	GList *l;
 
+	g_return_if_fail (BLUETOOTH_IS_KILLSWITCH (killswitch));
 	g_return_if_fail (state == KILLSWITCH_STATE_KILLED || state == KILLSWITCH_STATE_NOT_KILLED);
 
 	value = (state == KILLSWITCH_STATE_NOT_KILLED);
@@ -173,7 +171,6 @@
 		}
 
 		ind->call = call;
-		g_message ("set state, call %p", call);
 
 		dbus_pending_call_set_notify(call, setpower_reply, killswitch, NULL);
 
@@ -188,6 +185,8 @@
 	int state = KILLSWITCH_STATE_UNKNOWN;
 	GList *l;
 
+	g_return_val_if_fail (BLUETOOTH_IS_KILLSWITCH (killswitch), KILLSWITCH_STATE_UNKNOWN);
+
 	for (l = priv->killswitches ; l ; l = l->next) {
 		BluetoothIndKillswitch *ind = l->data;
 
@@ -215,6 +214,8 @@
 {
 	BluetoothKillswitchPrivate *priv = BLUETOOTH_KILLSWITCH_GET_PRIVATE (killswitch);
 
+	g_return_val_if_fail (BLUETOOTH_IS_KILLSWITCH (killswitch), FALSE);
+
 	return (priv->killswitches != NULL);
 }
 
@@ -255,8 +256,6 @@
 	ind->call = call;
 	priv->killswitches = g_list_append (priv->killswitches, ind);
 
-	g_message ("add killswitch %p", call);
-
 	dbus_pending_call_set_notify (call, getpower_reply, killswitch, NULL);
 
 	dbus_message_unref (message);
@@ -308,6 +307,12 @@
 }
 
 static void
+free_ind_killswitch (BluetoothIndKillswitch *ind)
+{
+	g_free (ind->udi);
+}
+
+static void
 bluetooth_killswitch_finalize (GObject *object)
 {
 	BluetoothKillswitchPrivate *priv = BLUETOOTH_KILLSWITCH_GET_PRIVATE (object);
@@ -323,8 +328,9 @@
 		priv->connection = NULL;
 	}
 
-	//FIXME
-	//kill everything in killswitches
+	g_list_foreach (priv->killswitches, (GFunc) free_ind_killswitch, NULL);
+	g_list_free (priv->killswitches);
+	priv->killswitches = NULL;
 
 	G_OBJECT_CLASS(bluetooth_killswitch_parent_class)->finalize(object);
 }



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