core: allow active connection 'master' to be set after object creation

We want to create the object earlier now, and figuring out the master is
a lot of code that we don't want to run before creating the object.  The
master still must be set before exporting the object over D-Bus though,
as before.
This commit is contained in:
Dan Williams 2013-07-29 16:26:09 -05:00
parent 4b8cd481dc
commit 4237df8c21
5 changed files with 34 additions and 15 deletions

View file

@ -344,9 +344,6 @@ device_state_changed (NMDevice *device, GParamSpec *pspec, NMActRequest *self)
* etc) that will be used to activate @connection and @device
* @subject: the #NMAuthSubject representing the requestor of the activation
* @device: the device/interface to configure according to @connection
* @master: if the activation depends on another device (ie, bond or bridge
* or team master to which this device will be enslaved) pass the #NMDevice
* that this activation request be enslaved to
*
* Begins activation of @device using the given @connection and other details.
*
@ -356,8 +353,7 @@ NMActRequest *
nm_act_request_new (NMConnection *connection,
const char *specific_object,
NMAuthSubject *subject,
NMDevice *device,
NMDevice *master)
NMDevice *device)
{
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
@ -368,7 +364,6 @@ nm_act_request_new (NMConnection *connection,
NM_ACTIVE_CONNECTION_INT_DEVICE, device,
NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, specific_object,
NM_ACTIVE_CONNECTION_INT_SUBJECT, subject,
NM_ACTIVE_CONNECTION_INT_MASTER, master,
NULL);
}

View file

@ -49,8 +49,7 @@ GType nm_act_request_get_type (void);
NMActRequest *nm_act_request_new (NMConnection *connection,
const char *specific_object,
NMAuthSubject *subject,
NMDevice *device,
NMDevice *master);
NMDevice *device);
NMConnection *nm_act_request_get_connection (NMActRequest *req);

View file

@ -265,6 +265,32 @@ nm_active_connection_get_master (NMActiveConnection *self)
return NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->master;
}
/**
* nm_active_connection_set_master:
* @self: the #NMActiveConnection
* @master: if the activation depends on another device (ie, bond or bridge
* master to which this device will be enslaved) pass the #NMDevice that this
* activation request be enslaved to
*
* Sets the master device of the active connection.
*/
void
nm_active_connection_set_master (NMActiveConnection *self, NMDevice *master)
{
NMActiveConnectionPrivate *priv;
g_return_if_fail (NM_IS_ACTIVE_CONNECTION (self));
g_return_if_fail (NM_IS_DEVICE (self));
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
/* Master is write-once, and must be set before exporting the object */
g_return_if_fail (priv->master == NULL);
g_return_if_fail (priv->path == NULL);
g_return_if_fail (master != priv->device);
priv->master = g_object_ref (master);
}
/****************************************************************/
static void
@ -404,10 +430,7 @@ set_property (GObject *object, guint prop_id,
priv->subject = g_value_dup_object (value);
break;
case PROP_INT_MASTER:
g_warn_if_fail (priv->master == NULL);
priv->master = g_value_dup_object (value);
if (priv->master)
g_warn_if_fail (priv->master != priv->device);
nm_active_connection_set_master (NM_ACTIVE_CONNECTION (object), g_value_get_object (value));
break;
case PROP_SPECIFIC_OBJECT:
tmp = g_value_get_boxed (value);
@ -608,7 +631,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
"Internal master device",
"Internal device",
NM_TYPE_DEVICE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
G_PARAM_READWRITE));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (ac_class),

View file

@ -109,4 +109,6 @@ gulong nm_active_connection_get_user_uid (NMActiveConnection *self);
NMDevice * nm_active_connection_get_master (NMActiveConnection *self);
void nm_active_connection_set_master (NMActiveConnection *self, NMDevice *master);
#endif /* NM_ACTIVE_CONNECTION_H */

View file

@ -2559,9 +2559,9 @@ internal_activate_device (NMManager *manager,
req = nm_act_request_new (connection,
specific_object,
subject,
device,
master_device);
device);
g_assert (req);
nm_active_connection_set_master (NM_ACTIVE_CONNECTION (req), master_device);
nm_device_activate (device, req);
return NM_ACTIVE_CONNECTION (req);