From e64bcae092bfa0b9a5dbcb5b839ef1ed10e5c3d8 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 24 Jan 2013 17:47:59 -0600 Subject: [PATCH] core: add IS_MASTER property to NMDevice We can't just check whether there are slaves or not, because the master device may be started before any slaves exist, and the slaves get added later. --- src/nm-device-bond.c | 1 + src/nm-device-bridge.c | 1 + src/nm-device.c | 32 ++++++++++++++++++++++++++++++-- src/nm-device.h | 2 ++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/nm-device-bond.c b/src/nm-device-bond.c index 96074beb4d..c6bd2b386f 100644 --- a/src/nm-device-bond.c +++ b/src/nm-device-bond.c @@ -496,6 +496,7 @@ nm_device_bond_new (const char *udi, const char *iface) NM_DEVICE_DRIVER, "bonding", NM_DEVICE_TYPE_DESC, "Bond", NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND, + NM_DEVICE_IS_MASTER, TRUE, NULL); } diff --git a/src/nm-device-bridge.c b/src/nm-device-bridge.c index 5b1925a6f0..511ca065e4 100644 --- a/src/nm-device-bridge.c +++ b/src/nm-device-bridge.c @@ -560,6 +560,7 @@ nm_device_bridge_new (const char *udi, const char *iface) NM_DEVICE_DRIVER, "bridge", NM_DEVICE_TYPE_DESC, "Bridge", NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BRIDGE, + NM_DEVICE_IS_MASTER, TRUE, NULL); } diff --git a/src/nm-device.c b/src/nm-device.c index fb6883194e..88f5c8c6fd 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -126,6 +126,7 @@ enum { PROP_RFKILL_TYPE, PROP_IFINDEX, PROP_AVAILABLE_CONNECTIONS, + PROP_IS_MASTER, LAST_PROP }; @@ -250,8 +251,9 @@ typedef struct { NMDevice * master; gboolean enslaved; - /* list of SlaveInfo for bond/bridge master */ - GSList * slaves; + /* slave management */ + gboolean is_master; + GSList * slaves; /* list of SlaveInfo */ NMConnectionProvider *con_provider; @@ -1000,6 +1002,18 @@ nm_device_master_get_slaves (NMDevice *dev) return slaves; } +/** + * nm_device_is_master: + * @dev: the device + * + * Returns: whether @dev can enslave other devices (eg, bridge or bond) + */ +gboolean +nm_device_is_master (NMDevice *dev) +{ + return NM_DEVICE_GET_PRIVATE (dev)->is_master; +} + /* release all slaves */ static void nm_device_master_release_slaves (NMDevice *self, gboolean failed) @@ -4292,6 +4306,9 @@ set_property (GObject *object, guint prop_id, case PROP_RFKILL_TYPE: priv->rfkill_type = g_value_get_uint (value); break; + case PROP_IS_MASTER: + priv->is_master = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -4414,6 +4431,9 @@ get_property (GObject *object, guint prop_id, g_ptr_array_add (array, g_strdup (nm_connection_get_path (connection))); g_value_take_boxed (value, array); break; + case PROP_IS_MASTER: + g_value_set_boolean (value, priv->is_master); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -4635,6 +4655,14 @@ nm_device_class_init (NMDeviceClass *klass) DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH, G_PARAM_READABLE)); + g_object_class_install_property + (object_class, PROP_IS_MASTER, + g_param_spec_boolean (NM_DEVICE_IS_MASTER, + "IsMaster", + "IsMaster", + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + /* Signals */ signals[STATE_CHANGED] = g_signal_new ("state-changed", diff --git a/src/nm-device.h b/src/nm-device.h index 9b2a7f54f4..c878745f31 100644 --- a/src/nm-device.h +++ b/src/nm-device.h @@ -60,6 +60,7 @@ #define NM_DEVICE_TYPE_DESC "type-desc" /* Internal only */ #define NM_DEVICE_RFKILL_TYPE "rfkill-type" /* Internal only */ #define NM_DEVICE_IFINDEX "ifindex" /* Internal only */ +#define NM_DEVICE_IS_MASTER "is-master" /* Internal only */ #define NM_DEVICE_AVAILABLE_CONNECTIONS "available-connections" /* Internal signals */ @@ -224,6 +225,7 @@ NMIP6Config * nm_device_get_ip6_config (NMDevice *dev); /* Master */ gboolean nm_device_master_add_slave (NMDevice *dev, NMDevice *slave); GSList * nm_device_master_get_slaves (NMDevice *dev); +gboolean nm_device_is_master (NMDevice *dev); /* Slave */ void nm_device_slave_notify_enslaved (NMDevice *dev,