summary refs log tree commit diff
path: root/libnm-glib/nm-client.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2011-08-23 19:16:47 +0200
committerMichael Biebl <biebl@debian.org>2011-08-23 19:16:47 +0200
commit263bf4c0c89bb88dc995acd9a6a2de9095fbd461 (patch)
tree7224326afe367409e7150e49fad9029f81fe24b8 /libnm-glib/nm-client.c
parentd465e5fac63f36bcf4069e36827f4b62c494556d (diff)
Imported Upstream version 0.9.0 upstream/0.9.0
Diffstat (limited to 'libnm-glib/nm-client.c')
-rw-r--r--libnm-glib/nm-client.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c
index 644af3e4..0769de1a 100644
--- a/libnm-glib/nm-client.c
+++ b/libnm-glib/nm-client.c
@@ -557,6 +557,40 @@ nm_client_get_device_by_path (NMClient *client, const char *object_path)
 	return device;
 }
 
+/**
+ * nm_client_get_device_by_iface:
+ * @client: a #NMClient
+ * @iface: the interface name to search for
+ *
+ * Gets a #NMDevice from a #NMClient.
+ *
+ * Returns: (transfer none): the #NMDevice for the given @iface or %NULL if none is found.
+ **/
+NMDevice *
+nm_client_get_device_by_iface (NMClient *client, const char *iface)
+{
+	const GPtrArray *devices;
+	int i;
+	NMDevice *device = NULL;
+
+	g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
+	g_return_val_if_fail (iface, NULL);
+
+	devices = nm_client_get_devices (client);
+	if (!devices)
+		return NULL;
+
+	for (i = 0; i < devices->len; i++) {
+		NMDevice *candidate = g_ptr_array_index (devices, i);
+		if (!strcmp (nm_device_get_iface (candidate), iface)) {
+			device = candidate;
+			break;
+		}
+	}
+
+	return device;
+}
+
 typedef struct {
 	NMClient *client;
 	NMClientActivateFn act_fn;
@@ -763,7 +797,7 @@ nm_client_add_and_activate_connection (NMClient *client,
 
 	if (partial)
 		hash = nm_connection_to_hash (partial, NM_SETTING_HASH_FLAG_ALL);
-	else
+	if (!hash)
 		hash = g_hash_table_new (g_str_hash, g_str_equal);
 
 	priv = NM_CLIENT_GET_PRIVATE (client);