summaryrefslogtreecommitdiff
path: root/libnm-glib
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2008-03-27 14:10:43 +0000
committerDan Williams <dcbw@redhat.com>2008-03-27 14:10:43 +0000
commitc01b4c9e2e41ed36df4d873112f19b631d3dfb2b (patch)
tree39b99a036439d46e0c1da98721f5b1efb2e3ef08 /libnm-glib
parentec89663e7da344f54e11dbd5848c2828fa258b92 (diff)
downloadNetworkManager-c01b4c9e2e41ed36df4d873112f19b631d3dfb2b.tar.gz
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() git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3506 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
Diffstat (limited to 'libnm-glib')
-rw-r--r--libnm-glib/libnm-glib-test.c4
-rw-r--r--libnm-glib/nm-active-connection.c4
-rw-r--r--libnm-glib/nm-client.c33
-rw-r--r--libnm-glib/nm-client.h2
-rw-r--r--libnm-glib/nm-device-802-11-wireless.c8
-rw-r--r--libnm-glib/nm-device-802-11-wireless.h2
-rw-r--r--libnm-glib/nm-ip4-config.c35
-rw-r--r--libnm-glib/nm-object-private.h9
-rw-r--r--libnm-glib/nm-object.c13
-rw-r--r--libnm-glib/nm-types.c7
10 files changed, 67 insertions, 50 deletions
diff --git a/libnm-glib/libnm-glib-test.c b/libnm-glib/libnm-glib-test.c
index 66b26cb9cb..c5247c739c 100644
--- a/libnm-glib/libnm-glib-test.c
+++ b/libnm-glib/libnm-glib-test.c
@@ -138,7 +138,7 @@ static void
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 @@ dump_device (NMDevice *device)
static gboolean
test_devices (NMClient *client)
{
- GPtrArray *devices;
+ const GPtrArray *devices;
int i;
devices = nm_client_get_devices (client);
diff --git a/libnm-glib/nm-active-connection.c b/libnm-glib/nm-active-connection.c
index 8ee8a8e3c0..e8296027e3 100644
--- a/libnm-glib/nm-active-connection.c
+++ b/libnm-glib/nm-active-connection.c
@@ -179,7 +179,7 @@ nm_active_connection_get_devices (NMActiveConnection *connection)
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 @@ nm_active_connection_get_devices (NMActiveConnection *connection)
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
diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c
index 126e658209..61e4604aa7 100644
--- a/libnm-glib/nm-client.c
+++ b/libnm-glib/nm-client.c
@@ -278,16 +278,15 @@ constructor (GType type,
}
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 @@ dispose (GObject *object)
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 @@ proxy_name_owner_changed (DBusGProxy *proxy,
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 @@ client_device_removed_proxy (DBusGProxy *proxy, char *path, gpointer user_data)
}
}
-GPtrArray *
+const GPtrArray *
nm_client_get_devices (NMClient *client)
{
NMClientPrivate *priv;
@@ -553,7 +554,7 @@ nm_client_get_devices (NMClient *client)
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_client_get_devices (NMClient *client)
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 @@ nm_client_get_active_connections (NMClient *client)
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 @@ nm_client_get_active_connections (NMClient *client)
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
diff --git a/libnm-glib/nm-client.h b/libnm-glib/nm-client.h
index df1a44e2af..1a23234347 100644
--- a/libnm-glib/nm-client.h
+++ b/libnm-glib/nm-client.h
@@ -42,7 +42,7 @@ GType nm_client_get_type (void);
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);
diff --git a/libnm-glib/nm-device-802-11-wireless.c b/libnm-glib/nm-device-802-11-wireless.c
index d53d202d30..f1fb94b705 100644
--- a/libnm-glib/nm-device-802-11-wireless.c
+++ b/libnm-glib/nm-device-802-11-wireless.c
@@ -198,7 +198,7 @@ nm_device_802_11_wireless_get_active_access_point (NMDevice80211Wireless *self)
return priv->active_ap;
}
-GPtrArray *
+const GPtrArray *
nm_device_802_11_wireless_get_access_points (NMDevice80211Wireless *self)
{
NMDevice80211WirelessPrivate *priv;
@@ -211,7 +211,7 @@ nm_device_802_11_wireless_get_access_points (NMDevice80211Wireless *self)
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_device_802_11_wireless_get_access_points (NMDevice80211Wireless *self)
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;
diff --git a/libnm-glib/nm-device-802-11-wireless.h b/libnm-glib/nm-device-802-11-wireless.h
index 01363a9c66..9b810f056d 100644
--- a/libnm-glib/nm-device-802-11-wireless.h
+++ b/libnm-glib/nm-device-802-11-wireless.h
@@ -44,7 +44,7 @@ NMAccessPoint * nm_device_802_11_wireless_get_active_access_point (NMDevice8021
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
diff --git a/libnm-glib/nm-ip4-config.c b/libnm-glib/nm-ip4-config.c
index f14e4378ce..51426c8a7a 100644
--- a/libnm-glib/nm-ip4-config.c
+++ b/libnm-glib/nm-ip4-config.c
@@ -120,7 +120,6 @@ static void
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 @@ finalize (GObject *object)
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 @@ nm_ip4_config_get_domains (NMIP4Config *config)
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;
-
- 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 (priv->domains)
+ return handle_ptr_array_return (priv->domains);
+
+ 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 *
diff --git a/libnm-glib/nm-object-private.h b/libnm-glib/nm-object-private.h
index 6d3404f048..5633ab1647 100644
--- a/libnm-glib/nm-object-private.h
+++ b/libnm-glib/nm-object-private.h
@@ -67,4 +67,13 @@ GByteArray *nm_object_get_byte_array_property (NMObject *object,
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 */
diff --git a/libnm-glib/nm-object.c b/libnm-glib/nm-object.c
index ebc7a35739..8639d9e246 100644
--- a/libnm-glib/nm-object.c
+++ b/libnm-glib/nm-object.c
@@ -210,6 +210,7 @@ deferred_notify_cb (gpointer data)
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 @@ void
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 @@ nm_object_queue_notify (NMObject *object, const char *property)
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 */
diff --git a/libnm-glib/nm-types.c b/libnm-glib/nm-types.c
index 4627713537..19512a20b7 100644
--- a/libnm-glib/nm-types.c
+++ b/libnm-glib/nm-types.c
@@ -241,11 +241,8 @@ nm_object_array_demarshal (GValue *value,
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.