summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-12-02 10:33:19 +0100
committerThomas Haller <thaller@redhat.com>2015-12-04 12:28:42 +0100
commit115f50760213dadd3a331995c930761b807623d2 (patch)
tree5a6dda4591263cc0d0414e6f2fce966a2578470c
parentfd4ca82d5e58373615eafdb9ba024ba98a50bd52 (diff)
downloadNetworkManager-115f50760213dadd3a331995c930761b807623d2.tar.gz
device: implement slave property in parent device class
Instead of reimplementing the slave property in bond, bridge and team, just add the property to the parent class. It's not that the parent class would be agnostic to the master/slave implementation, all the slaves are known to the every device type implementation. Also, the derived class doesn't know the correct time when to invoke the notify-changed for the slaves property. E.g. it should be only invoked after nm_device_slave_notify_enslave() when other components also consider the slave as enslaved. Later this will be fixed so that the SLAVES property correspond to what other master/slave related properties say.
-rw-r--r--src/devices/nm-device-bond.c53
-rw-r--r--src/devices/nm-device-bond.h2
-rw-r--r--src/devices/nm-device-bridge.c53
-rw-r--r--src/devices/nm-device-bridge.h2
-rw-r--r--src/devices/nm-device.c26
-rw-r--r--src/devices/nm-device.h6
-rw-r--r--src/devices/team/nm-device-team.c53
-rw-r--r--src/devices/team/nm-device-team.h2
8 files changed, 36 insertions, 161 deletions
diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c
index cd1e1053f5..62e9860ee9 100644
--- a/src/devices/nm-device-bond.c
+++ b/src/devices/nm-device-bond.c
@@ -46,13 +46,6 @@ typedef struct {
int dummy;
} NMDeviceBondPrivate;
-enum {
- PROP_0,
- PROP_SLAVES,
-
- LAST_PROP
-};
-
/******************************************************************/
static NMDeviceCapabilities
@@ -415,7 +408,7 @@ enslave_slave (NMDevice *device,
} else
_LOGI (LOGD_BOND, "bond slave %s was enslaved", slave_iface);
- g_object_notify (G_OBJECT (device), NM_DEVICE_BOND_SLAVES);
+ g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
return TRUE;
}
@@ -444,7 +437,7 @@ release_slave (NMDevice *device,
nm_device_get_ip_iface (slave));
}
- g_object_notify (G_OBJECT (device), NM_DEVICE_BOND_SLAVES);
+ g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
if (configure) {
/* Kernel bonding code "closes" the slave when releasing it, (which clears
@@ -489,36 +482,6 @@ nm_device_bond_init (NMDeviceBond * self)
}
static void
-get_property (GObject *object, guint prop_id,
- GValue *value, GParamSpec *pspec)
-{
- GSList *list;
-
- switch (prop_id) {
- break;
- case PROP_SLAVES:
- list = nm_device_master_get_slaves (NM_DEVICE (object));
- nm_utils_g_value_set_object_path_array (value, list, NULL, NULL);
- g_slist_free (list);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-set_property (GObject *object, guint prop_id,
- const GValue *value, GParamSpec *pspec)
-{
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
nm_device_bond_class_init (NMDeviceBondClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -528,10 +491,6 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_BOND_SETTING_NAME, NM_LINK_TYPE_BOND)
- /* virtual methods */
- object_class->get_property = get_property;
- object_class->set_property = set_property;
-
parent_class->get_generic_capabilities = get_generic_capabilities;
parent_class->is_available = is_available;
parent_class->check_connection_compatible = check_connection_compatible;
@@ -547,14 +506,6 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
parent_class->enslave_slave = enslave_slave;
parent_class->release_slave = release_slave;
- /* properties */
- g_object_class_install_property
- (object_class, PROP_SLAVES,
- g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
NMDBUS_TYPE_DEVICE_BOND_SKELETON,
NULL);
diff --git a/src/devices/nm-device-bond.h b/src/devices/nm-device-bond.h
index 8165bb8062..9e86719e3c 100644
--- a/src/devices/nm-device-bond.h
+++ b/src/devices/nm-device-bond.h
@@ -32,8 +32,6 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_BOND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_BOND))
#define NM_DEVICE_BOND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BOND, NMDeviceBondClass))
-#define NM_DEVICE_BOND_SLAVES "slaves"
-
typedef NMDevice NMDeviceBond;
typedef NMDeviceClass NMDeviceBondClass;
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index b8887f444b..4a20f46b4d 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -44,13 +44,6 @@ typedef struct {
int dummy;
} NMDeviceBridgePrivate;
-enum {
- PROP_0,
- PROP_SLAVES,
-
- LAST_PROP
-};
-
/******************************************************************/
static NMDeviceCapabilities
@@ -351,7 +344,7 @@ enslave_slave (NMDevice *device,
nm_device_get_ip_iface (slave));
}
- g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES);
+ g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
return TRUE;
}
@@ -381,7 +374,7 @@ release_slave (NMDevice *device,
nm_device_get_ip_iface (slave));
}
- g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES);
+ g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
}
static gboolean
@@ -437,36 +430,6 @@ nm_device_bridge_init (NMDeviceBridge * self)
}
static void
-get_property (GObject *object, guint prop_id,
- GValue *value, GParamSpec *pspec)
-{
- GSList *list;
-
- switch (prop_id) {
- break;
- case PROP_SLAVES:
- list = nm_device_master_get_slaves (NM_DEVICE (object));
- nm_utils_g_value_set_object_path_array (value, list, NULL, NULL);
- g_slist_free (list);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-set_property (GObject *object, guint prop_id,
- const GValue *value, GParamSpec *pspec)
-{
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -476,10 +439,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_BRIDGE_SETTING_NAME, NM_LINK_TYPE_BRIDGE)
- /* virtual methods */
- object_class->get_property = get_property;
- object_class->set_property = set_property;
-
parent_class->get_generic_capabilities = get_generic_capabilities;
parent_class->is_available = is_available;
parent_class->check_connection_compatible = check_connection_compatible;
@@ -494,14 +453,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
parent_class->enslave_slave = enslave_slave;
parent_class->release_slave = release_slave;
- /* properties */
- g_object_class_install_property
- (object_class, PROP_SLAVES,
- g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
NMDBUS_TYPE_DEVICE_BRIDGE_SKELETON,
NULL);
diff --git a/src/devices/nm-device-bridge.h b/src/devices/nm-device-bridge.h
index 1d0bf7ca0c..4648267525 100644
--- a/src/devices/nm-device-bridge.h
+++ b/src/devices/nm-device-bridge.h
@@ -33,8 +33,6 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_BRIDGE))
#define NM_DEVICE_BRIDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgeClass))
-#define NM_DEVICE_BRIDGE_SLAVES "slaves"
-
typedef NMDevice NMDeviceBridge;
typedef NMDeviceClass NMDeviceBridgeClass;
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index cdbd6a01f5..1bd2364dfb 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -130,6 +130,7 @@ enum {
PROP_METERED,
PROP_LLDP_NEIGHBORS,
PROP_REAL,
+ PROP_SLAVES,
LAST_PROP
};
@@ -2187,7 +2188,7 @@ nm_device_master_add_slave (NMDevice *self, NMDevice *slave, gboolean configure)
*
* Returns: any slaves of which @self is the master. Caller owns returned list.
*/
-GSList *
+static GSList *
nm_device_master_get_slaves (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
@@ -10396,6 +10397,22 @@ get_property (GObject *object, guint prop_id,
case PROP_REAL:
g_value_set_boolean (value, priv->real);
break;
+ case PROP_SLAVES: {
+ GSList *slave_iter;
+ char **slave_list;
+ guint i;
+
+ slave_list = g_new (char *, g_slist_length (priv->slaves) + 1);
+ i = 0;
+ for (slave_iter = priv->slaves; slave_iter; slave_iter = slave_iter->next) {
+ SlaveInfo *info = slave_iter->data;
+
+ slave_list[i++] = g_strdup (nm_exported_object_get_path ((NMExportedObject *) info->slave));
+ }
+ slave_list[i] = NULL;
+ g_value_take_boxed (value, slave_list);
+ break;
+ }
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -10695,6 +10712,13 @@ nm_device_class_init (NMDeviceClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property
+ (object_class, PROP_SLAVES,
+ g_param_spec_boxed (NM_DEVICE_SLAVES, "", "",
+ G_TYPE_STRV,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
/* Signals */
signals[STATE_CHANGED] =
g_signal_new ("state-changed",
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index 98f1e13594..4ffc721d9c 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -61,6 +61,11 @@
#define NM_DEVICE_LLDP_NEIGHBORS "lldp-neighbors"
#define NM_DEVICE_REAL "real"
+/* the "slaves" property is internal in the parent class, but exposed
+ * by the derived classes NMDeviceBond, NMDeviceBridge and NMDeviceTeam.
+ * It is thus important that the property name matches. */
+#define NM_DEVICE_SLAVES "slaves" /* partially internal */
+
#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 */
@@ -387,7 +392,6 @@ void nm_device_replace_vpn6_config (NMDevice *dev,
void nm_device_capture_initial_config (NMDevice *dev);
/* Master */
-GSList * nm_device_master_get_slaves (NMDevice *dev);
gboolean nm_device_is_master (NMDevice *dev);
/* Slave */
diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c
index 70bfc78198..e56a648f8d 100644
--- a/src/devices/team/nm-device-team.c
+++ b/src/devices/team/nm-device-team.c
@@ -54,13 +54,6 @@ typedef struct {
guint teamd_dbus_watch;
} NMDeviceTeamPrivate;
-enum {
- PROP_0,
- PROP_SLAVES,
-
- LAST_PROP
-};
-
static gboolean teamd_start (NMDevice *device, NMSettingTeam *s_team);
/******************************************************************/
@@ -644,7 +637,7 @@ enslave_slave (NMDevice *device,
} else
_LOGI (LOGD_TEAM, "team port %s was enslaved", slave_iface);
- g_object_notify (G_OBJECT (device), NM_DEVICE_TEAM_SLAVES);
+ g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
return TRUE;
}
@@ -669,7 +662,7 @@ release_slave (NMDevice *device,
} else
_LOGI (LOGD_TEAM, "team port %s was released", nm_device_get_ip_iface (slave));
- g_object_notify (G_OBJECT (device), NM_DEVICE_TEAM_SLAVES);
+ g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
if (configure) {
/* Kernel team code "closes" the port when releasing it, (which clears
@@ -746,36 +739,6 @@ constructed (GObject *object)
}
static void
-get_property (GObject *object, guint prop_id,
- GValue *value, GParamSpec *pspec)
-{
- GSList *list;
-
- switch (prop_id) {
- break;
- case PROP_SLAVES:
- list = nm_device_master_get_slaves (NM_DEVICE (object));
- nm_utils_g_value_set_object_path_array (value, list, NULL, NULL);
- g_slist_free (list);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-set_property (GObject *object, guint prop_id,
- const GValue *value, GParamSpec *pspec)
-{
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
dispose (GObject *object)
{
NMDevice *device = NM_DEVICE (object);
@@ -801,10 +764,7 @@ nm_device_team_class_init (NMDeviceTeamClass *klass)
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_TEAM_SETTING_NAME, NM_LINK_TYPE_TEAM)
- /* virtual methods */
object_class->constructed = constructed;
- object_class->get_property = get_property;
- object_class->set_property = set_property;
object_class->dispose = dispose;
parent_class->create_and_realize = create_and_realize;
@@ -822,15 +782,6 @@ nm_device_team_class_init (NMDeviceTeamClass *klass)
parent_class->enslave_slave = enslave_slave;
parent_class->release_slave = release_slave;
- /* properties */
- g_object_class_install_property
- (object_class, PROP_SLAVES,
- g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES, "", "",
- G_TYPE_STRV,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
-
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
NMDBUS_TYPE_DEVICE_TEAM_SKELETON,
NULL);
diff --git a/src/devices/team/nm-device-team.h b/src/devices/team/nm-device-team.h
index 2436705712..0e81afa744 100644
--- a/src/devices/team/nm-device-team.h
+++ b/src/devices/team/nm-device-team.h
@@ -32,8 +32,6 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_TEAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_TEAM))
#define NM_DEVICE_TEAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_TEAM, NMDeviceTeamClass))
-#define NM_DEVICE_TEAM_SLAVES "slaves"
-
typedef NMDevice NMDeviceTeam;
typedef NMDeviceClass NMDeviceTeamClass;