NetworkManager r3506 - in trunk: . libnm-glib



Author: dcbw
Date: Thu Mar 27 14:10:43 2008
New Revision: 3506
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3506&view=rev

Log:
2008-03-27  Dan Williams  <dcbw redhat com>

	* nm-object.c
		- (nm_object_queue_notify): don't notify multiple times for the same
			property

	* nm-object-private.h
		- (handle_ptr_array_return): return NULL if the given array is NULL or
			if it has zero elements

	* nm-ip4-config.c
		- (finalize): use g_ptr_array_foreach() when freeing domains
		- (nm_ip4_config_get_domains): use handle_ptr_array_return()

	* nm-active-connection.c
		- (nm_active_connection_get_devices): use handle_ptr_array_return()

	* nm-device-802-11-wireless.c
	  nm-device-802-11-wireless.h
		- (nm_device_802_11_wireless_get_access_points): return const; use
			handle_ptr_array_return()

	* nm-types.c
		- (nm_object_array_demarshal): always create an array, even of length
			zero, to distinguish between "NM returned no items" and "haven't
			asked NM yet"

	* nm-client.c
		- (dispose): free active connections too
		- (proxy_name_owner_changed): free active connections too when NM goes
			away
		- (nm_client_get_devices): return const; use handle_ptr_array_return()
		- (nm_client_get_active_connections): use handle_ptr_array_return()



Modified:
   trunk/ChangeLog
   trunk/libnm-glib/libnm-glib-test.c
   trunk/libnm-glib/nm-active-connection.c
   trunk/libnm-glib/nm-client.c
   trunk/libnm-glib/nm-client.h
   trunk/libnm-glib/nm-device-802-11-wireless.c
   trunk/libnm-glib/nm-device-802-11-wireless.h
   trunk/libnm-glib/nm-ip4-config.c
   trunk/libnm-glib/nm-object-private.h
   trunk/libnm-glib/nm-object.c
   trunk/libnm-glib/nm-types.c

Modified: trunk/libnm-glib/libnm-glib-test.c
==============================================================================
--- trunk/libnm-glib/libnm-glib-test.c	(original)
+++ trunk/libnm-glib/libnm-glib-test.c	Thu Mar 27 14:10:43 2008
@@ -138,7 +138,7 @@
 dump_wireless (NMDevice80211Wireless *device)
 {
 	const char *str;
-	GPtrArray *aps;
+	const GPtrArray *aps;
 	int i;
 
 	g_print ("Mode: %d\n", nm_device_802_11_wireless_get_mode (device));
@@ -202,7 +202,7 @@
 static gboolean
 test_devices (NMClient *client)
 {
-	GPtrArray *devices;
+	const GPtrArray *devices;
 	int i;
 
 	devices = nm_client_get_devices (client);

Modified: trunk/libnm-glib/nm-active-connection.c
==============================================================================
--- trunk/libnm-glib/nm-active-connection.c	(original)
+++ trunk/libnm-glib/nm-active-connection.c	Thu Mar 27 14:10:43 2008
@@ -179,7 +179,7 @@
 
 	priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
 	if (priv->devices)
-		return priv->devices;
+		return handle_ptr_array_return (priv->devices);
 
 	if (!nm_object_get_property (NM_OBJECT (connection),
 	                             NM_DBUS_INTERFACE,
@@ -191,7 +191,7 @@
 	demarshal_devices (NM_OBJECT (connection), NULL, &value, &priv->devices);
 	g_value_unset (&value);
 
-	return priv->devices;
+	return handle_ptr_array_return (priv->devices);
 }
 
 static void

Modified: trunk/libnm-glib/nm-client.c
==============================================================================
--- trunk/libnm-glib/nm-client.c	(original)
+++ trunk/libnm-glib/nm-client.c	Thu Mar 27 14:10:43 2008
@@ -278,16 +278,15 @@
 }
 
 static void
-free_device_list (NMClient *client)
+free_object_array (GPtrArray **array)
 {
-	NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
-
-	if (!priv->devices)
-		return;
+	g_return_if_fail (array != NULL);
 
-	g_ptr_array_foreach (priv->devices, (GFunc) g_object_unref, NULL);
-	g_ptr_array_free (priv->devices, TRUE);
-	priv->devices = NULL;
+	if (*array) {
+		g_ptr_array_foreach (*array, (GFunc) g_object_unref, NULL);
+		g_ptr_array_free (*array, TRUE);
+		*array = NULL;
+	}
 }
 
 static void
@@ -303,7 +302,8 @@
 	g_object_unref (priv->client_proxy);
 	g_object_unref (priv->bus_proxy);
 
-	free_device_list (NM_CLIENT (object));
+	free_object_array (&priv->devices);
+	free_object_array (&priv->active_connections);
 
 	G_OBJECT_CLASS (nm_client_parent_class)->dispose (object);
 }
@@ -490,7 +490,8 @@
 	if (!priv->manager_running) {
 		priv->state = NM_STATE_UNKNOWN;
 		nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_MANAGER_RUNNING);
-		free_device_list (client);
+		free_object_array (&priv->devices);
+		free_object_array (&priv->active_connections);
 		priv->wireless_enabled = FALSE;
 		priv->wireless_hw_enabled = FALSE;
 		poke_wireless_devices_with_rf_status (client);
@@ -540,7 +541,7 @@
 	}
 }
 
-GPtrArray *
+const GPtrArray *
 nm_client_get_devices (NMClient *client)
 {
 	NMClientPrivate *priv;
@@ -553,7 +554,7 @@
 
 	priv = NM_CLIENT_GET_PRIVATE (client);
 	if (priv->devices)
-		return priv->devices;
+		return handle_ptr_array_return (priv->devices);
 
 	if (!org_freedesktop_NetworkManager_get_devices (priv->client_proxy, &temp, &error)) {
 		g_warning ("%s: error getting devices: %s\n", __func__, error->message);
@@ -567,13 +568,13 @@
 	nm_object_array_demarshal (&value, &priv->devices, connection, nm_device_new);
 	g_value_unset (&value);
 
-	return priv->devices;
+	return handle_ptr_array_return (priv->devices);
 }
 
 NMDevice *
 nm_client_get_device_by_path (NMClient *client, const char *object_path)
 {
-	GPtrArray *devices;
+	const GPtrArray *devices;
 	int i;
 	NMDevice *device = NULL;
 
@@ -683,7 +684,7 @@
 
 	priv = NM_CLIENT_GET_PRIVATE (client);
 	if (priv->active_connections)
-		return priv->active_connections;
+		return handle_ptr_array_return (priv->active_connections);
 
 	if (!nm_object_get_property (NM_OBJECT (client),
 	                             "org.freedesktop.DBus.Properties",
@@ -695,7 +696,7 @@
 	demarshal_active_connections (NM_OBJECT (client), NULL, &value, &priv->active_connections);	
 	g_value_unset (&value);
 
-	return priv->active_connections;
+	return handle_ptr_array_return (priv->active_connections);
 }
 
 gboolean

Modified: trunk/libnm-glib/nm-client.h
==============================================================================
--- trunk/libnm-glib/nm-client.h	(original)
+++ trunk/libnm-glib/nm-client.h	Thu Mar 27 14:10:43 2008
@@ -42,7 +42,7 @@
 
 NMClient *nm_client_new (void);
 
-GPtrArray *nm_client_get_devices          (NMClient *client);
+const GPtrArray *nm_client_get_devices    (NMClient *client);
 NMDevice *nm_client_get_device_by_path    (NMClient *client, const char *object_path);
 
 typedef void (*NMClientActivateDeviceFn) (gpointer user_data, GError *error);

Modified: trunk/libnm-glib/nm-device-802-11-wireless.c
==============================================================================
--- trunk/libnm-glib/nm-device-802-11-wireless.c	(original)
+++ trunk/libnm-glib/nm-device-802-11-wireless.c	Thu Mar 27 14:10:43 2008
@@ -198,7 +198,7 @@
 	return priv->active_ap;
 }
 
-GPtrArray *
+const GPtrArray *
 nm_device_802_11_wireless_get_access_points (NMDevice80211Wireless *self)
 {
 	NMDevice80211WirelessPrivate *priv;
@@ -211,7 +211,7 @@
 
 	priv = NM_DEVICE_802_11_WIRELESS_GET_PRIVATE (self);
 	if (priv->aps)
-		return priv->aps;
+		return handle_ptr_array_return (priv->aps);
 
 	if (!org_freedesktop_NetworkManager_Device_Wireless_get_access_points (priv->proxy, &temp, &error)) {
 		g_warning ("%s: error getting access points: %s", __func__, error->message);
@@ -225,14 +225,14 @@
 	nm_object_array_demarshal (&value, &priv->aps, connection, nm_access_point_new);
 	g_value_unset (&value);
 
-	return priv->aps;
+	return handle_ptr_array_return (priv->aps);
 }
 
 NMAccessPoint *
 nm_device_802_11_wireless_get_access_point_by_path (NMDevice80211Wireless *self,
 											        const char *path)
 {
-	GPtrArray *aps;
+	const GPtrArray *aps;
 	int i;
 	NMAccessPoint *ap = NULL;
 

Modified: trunk/libnm-glib/nm-device-802-11-wireless.h
==============================================================================
--- trunk/libnm-glib/nm-device-802-11-wireless.h	(original)
+++ trunk/libnm-glib/nm-device-802-11-wireless.h	Thu Mar 27 14:10:43 2008
@@ -44,7 +44,7 @@
 NMAccessPoint * nm_device_802_11_wireless_get_access_point_by_path (NMDevice80211Wireless *device,
                                                                     const char *path);
 
-GPtrArray *     nm_device_802_11_wireless_get_access_points        (NMDevice80211Wireless *device);
+const GPtrArray *nm_device_802_11_wireless_get_access_points       (NMDevice80211Wireless *device);
 
 G_END_DECLS
 

Modified: trunk/libnm-glib/nm-ip4-config.c
==============================================================================
--- trunk/libnm-glib/nm-ip4-config.c	(original)
+++ trunk/libnm-glib/nm-ip4-config.c	Thu Mar 27 14:10:43 2008
@@ -120,7 +120,6 @@
 finalize (GObject *object)
 {
 	NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
-	int i;
 
 	g_free (priv->hostname);
 	g_free (priv->nis_domain);
@@ -130,8 +129,7 @@
 		g_array_free (priv->nis_servers, TRUE);
 
 	if (priv->domains) {
-		for (i = 0; i < priv->domains->len; i++)
-			g_free (g_ptr_array_index (priv->domains, i));
+		g_ptr_array_foreach (priv->domains, (GFunc) g_free, NULL);
 		g_ptr_array_free (priv->domains, TRUE);
 	}
 
@@ -396,24 +394,25 @@
 	g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
 
 	priv = NM_IP4_CONFIG_GET_PRIVATE (config);
-	if (!priv->domains) {
-		if (nm_object_get_property (NM_OBJECT (config),
-									NM_DBUS_INTERFACE_IP4_CONFIG,
-									"Domains",
-									&value)) {
-			char **array = NULL, **p;
+	if (priv->domains)
+		return handle_ptr_array_return (priv->domains);
 
-			array = (char **) g_value_get_boxed (&value);
-			if (array && g_strv_length (array)) {
-				priv->domains = g_ptr_array_sized_new (g_strv_length (array));
-				for (p = array; *p; p++)
-					g_ptr_array_add (priv->domains, g_strdup (*p));
-			}
-			g_value_unset (&value);
+	if (nm_object_get_property (NM_OBJECT (config),
+								NM_DBUS_INTERFACE_IP4_CONFIG,
+								"Domains",
+								&value)) {
+		char **array = NULL, **p;
+
+		array = (char **) g_value_get_boxed (&value);
+		if (array && g_strv_length (array)) {
+			priv->domains = g_ptr_array_sized_new (g_strv_length (array));
+			for (p = array; *p; p++)
+				g_ptr_array_add (priv->domains, g_strdup (*p));
 		}
+		g_value_unset (&value);
 	}
 
-	return priv->domains;
+	return handle_ptr_array_return (priv->domains);
 }
 
 const char *

Modified: trunk/libnm-glib/nm-object-private.h
==============================================================================
--- trunk/libnm-glib/nm-object-private.h	(original)
+++ trunk/libnm-glib/nm-object-private.h	Thu Mar 27 14:10:43 2008
@@ -67,4 +67,13 @@
 											   const char *interface,
 											   const char *prop_name);
 
+static inline const GPtrArray *
+handle_ptr_array_return (GPtrArray *array)
+{
+	/* zero-length is special-case; return NULL */
+	if (!array || !array->len)
+		return NULL;
+	return array;
+}
+
 #endif /* NM_OBJECT_PRIVATE_H */

Modified: trunk/libnm-glib/nm-object.c
==============================================================================
--- trunk/libnm-glib/nm-object.c	(original)
+++ trunk/libnm-glib/nm-object.c	Thu Mar 27 14:10:43 2008
@@ -210,6 +210,7 @@
 
 	priv->notify_id = 0;
 
+	priv->notify_props = g_slist_reverse (priv->notify_props);
 	for (iter = priv->notify_props; iter; iter = g_slist_next (iter)) {
 		g_object_notify (G_OBJECT (object), (const char *) iter->data);
 		g_free (iter->data);
@@ -224,6 +225,8 @@
 nm_object_queue_notify (NMObject *object, const char *property)
 {
 	NMObjectPrivate *priv;
+	gboolean found = FALSE;
+	GSList *iter;
 
 	g_return_if_fail (NM_IS_OBJECT (object));
 	g_return_if_fail (property != NULL);
@@ -232,7 +235,15 @@
 	if (!priv->notify_id)
 		priv->notify_id = g_idle_add_full (G_PRIORITY_LOW, deferred_notify_cb, object, NULL);
 
-	priv->notify_props = g_slist_append (priv->notify_props, g_strdup (property));
+	for (iter = priv->notify_props; iter; iter = g_slist_next (iter)) {
+		if (!strcmp ((char *) iter->data, property)) {
+			found = TRUE;
+			break;
+		}
+	}
+
+	if (!found)
+		priv->notify_props = g_slist_prepend (priv->notify_props, g_strdup (property));
 }
 
 /* Stolen from dbus-glib */

Modified: trunk/libnm-glib/nm-types.c
==============================================================================
--- trunk/libnm-glib/nm-types.c	(original)
+++ trunk/libnm-glib/nm-types.c	Thu Mar 27 14:10:43 2008
@@ -241,11 +241,8 @@
 					g_warning ("%s: couldn't create object for %s", __func__, path);
 			}
 		}
-		if (temp->len == 0) {
-			g_ptr_array_free (temp, TRUE);
-			temp = NULL;
-		}
-	}
+	} else
+		temp = g_ptr_array_new ();
 
 	/* Deallocate after to ensure that an object that might already
 	 * be in the array doesn't get destroyed due to refcounting.



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