core: make nm_manager_activate_connection() take a Device, not a path

Simpler; everywhere that called it has an NMDevice already anyway.
This commit is contained in:
Dan Williams
2012-09-13 15:57:36 -05:00
parent a878cd8145
commit f94ac164a6
3 changed files with 23 additions and 31 deletions

View File

@@ -195,8 +195,8 @@ struct PendingActivation {
gboolean add_and_activate; gboolean add_and_activate;
NMConnection *connection; NMConnection *connection;
NMDevice *device;
char *specific_object_path; char *specific_object_path;
char *device_path;
}; };
typedef struct { typedef struct {
@@ -849,7 +849,7 @@ nm_manager_get_state (NMManager *manager)
static PendingActivation * static PendingActivation *
pending_activation_new (NMManager *manager, pending_activation_new (NMManager *manager,
DBusGMethodInvocation *context, DBusGMethodInvocation *context,
const char *device_path, NMDevice *device,
NMConnection *connection, NMConnection *connection,
const char *specific_object_path, const char *specific_object_path,
gboolean add_and_activate, gboolean add_and_activate,
@@ -860,26 +860,21 @@ pending_activation_new (NMManager *manager,
g_return_val_if_fail (manager != NULL, NULL); g_return_val_if_fail (manager != NULL, NULL);
g_return_val_if_fail (context != NULL, NULL); g_return_val_if_fail (context != NULL, NULL);
g_return_val_if_fail (device_path != NULL, NULL); g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
/* A object path of "/" means NULL */ /* A object path of "/" means NULL */
if (g_strcmp0 (specific_object_path, "/") == 0) if (g_strcmp0 (specific_object_path, "/") == 0)
specific_object_path = NULL; specific_object_path = NULL;
if (g_strcmp0 (device_path, "/") == 0)
device_path = NULL;
pending = g_slice_new0 (PendingActivation); pending = g_slice_new0 (PendingActivation);
pending->manager = manager; pending->manager = manager;
pending->context = context; pending->context = context;
pending->callback = callback; pending->callback = callback;
pending->add_and_activate = add_and_activate; pending->add_and_activate = add_and_activate;
pending->connection = g_object_ref (connection); pending->connection = g_object_ref (connection);
pending->device = g_object_ref (device);
/* "/" is special-cased to NULL to get through D-Bus */
pending->specific_object_path = g_strdup (specific_object_path); pending->specific_object_path = g_strdup (specific_object_path);
pending->device_path = g_strdup (device_path);
return pending; return pending;
} }
@@ -972,7 +967,7 @@ pending_activation_destroy (PendingActivation *pending,
} }
g_free (pending->specific_object_path); g_free (pending->specific_object_path);
g_free (pending->device_path); g_clear_object (&pending->device);
g_clear_object (&pending->connection); g_clear_object (&pending->connection);
if (pending->chain) if (pending->chain)
@@ -2768,7 +2763,7 @@ ensure_master_active_connection (NMManager *self,
master_ac = nm_manager_activate_connection (self, master_ac = nm_manager_activate_connection (self,
candidate, candidate,
NULL, NULL,
nm_device_get_path (master_device), master_device,
dbus_sender, dbus_sender,
error); error);
if (!master_ac) if (!master_ac)
@@ -2816,7 +2811,7 @@ ensure_master_active_connection (NMManager *self,
master_ac = nm_manager_activate_connection (self, master_ac = nm_manager_activate_connection (self,
master_connection, master_connection,
NULL, NULL,
nm_device_get_path (candidate), candidate,
dbus_sender, dbus_sender,
error); error);
if (!master_ac) if (!master_ac)
@@ -2907,12 +2902,11 @@ NMActiveConnection *
nm_manager_activate_connection (NMManager *manager, nm_manager_activate_connection (NMManager *manager,
NMConnection *connection, NMConnection *connection,
const char *specific_object, const char *specific_object,
const char *device_path, NMDevice *device,
const char *dbus_sender, const char *dbus_sender,
GError **error) GError **error)
{ {
NMManagerPrivate *priv; NMManagerPrivate *priv;
NMDevice *device = NULL;
gulong sender_uid = G_MAXULONG; gulong sender_uid = G_MAXULONG;
char *iface; char *iface;
NMDevice *master_device = NULL; NMDevice *master_device = NULL;
@@ -2947,14 +2941,7 @@ nm_manager_activate_connection (NMManager *manager,
} }
/* Device-based connection */ /* Device-based connection */
if (device_path) { if (device) {
device = nm_manager_get_device_by_path (manager, device_path);
if (!device) {
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
"Device not found");
return NULL;
}
/* If it's a virtual interface make sure the device given by the /* If it's a virtual interface make sure the device given by the
* path matches the connection's interface details. * path matches the connection's interface details.
*/ */
@@ -3154,7 +3141,7 @@ pending_activate (PendingActivation *pending, NMSettingsConnection *new_connecti
ac = nm_manager_activate_connection (pending->manager, ac = nm_manager_activate_connection (pending->manager,
NM_CONNECTION (pending->connection), NM_CONNECTION (pending->connection),
pending->specific_object_path, pending->specific_object_path,
pending->device_path, pending->device,
sender, sender,
&error); &error);
g_free (sender); g_free (sender);
@@ -3189,8 +3176,12 @@ validate_activation_request (NMManager *self,
|| nm_connection_is_type (connection, NM_SETTING_VPN_SETTING_NAME)) || nm_connection_is_type (connection, NM_SETTING_VPN_SETTING_NAME))
vpn = TRUE; vpn = TRUE;
/* Validate the device path, if given; "/" means NULL */ /* Normalize device path */
if (device_path && (g_strcmp0 (device_path, "/") != 0)) if (device_path && g_strcmp0 (device_path, "/") == 0)
device_path = NULL;
/* And validate it */
if (device_path)
device = nm_manager_get_device_by_path (self, device_path); device = nm_manager_get_device_by_path (self, device_path);
/* VPN doesn't require a device, but if one is given validate it. /* VPN doesn't require a device, but if one is given validate it.
@@ -3232,6 +3223,7 @@ impl_manager_activate_connection (NMManager *self,
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
PendingActivation *pending; PendingActivation *pending;
NMConnection *connection; NMConnection *connection;
NMDevice *device = NULL;
GError *error = NULL; GError *error = NULL;
connection = (NMConnection *) nm_settings_get_connection_by_path (priv->settings, connection_path); connection = (NMConnection *) nm_settings_get_connection_by_path (priv->settings, connection_path);
@@ -3242,7 +3234,7 @@ impl_manager_activate_connection (NMManager *self,
goto error; goto error;
} }
if (!validate_activation_request (self, connection, device_path, NULL, NULL, &error)) if (!validate_activation_request (self, connection, device_path, &device, NULL, &error))
goto error; goto error;
/* Need to check the caller's permissions and stuff before we can /* Need to check the caller's permissions and stuff before we can
@@ -3250,7 +3242,7 @@ impl_manager_activate_connection (NMManager *self,
*/ */
pending = pending_activation_new (self, pending = pending_activation_new (self,
context, context,
device_path, device,
connection, connection,
specific_object_path, specific_object_path,
FALSE, FALSE,
@@ -3363,7 +3355,7 @@ impl_manager_add_and_activate_connection (NMManager *self,
*/ */
pending = pending_activation_new (self, pending = pending_activation_new (self,
context, context,
device_path, device,
connection, connection,
specific_object_path, specific_object_path,
TRUE, TRUE,

View File

@@ -116,7 +116,7 @@ NMDevice *nm_manager_get_device_by_ifindex (NMManager *manager,
NMActiveConnection *nm_manager_activate_connection (NMManager *manager, NMActiveConnection *nm_manager_activate_connection (NMManager *manager,
NMConnection *connection, NMConnection *connection,
const char *specific_object, const char *specific_object,
const char *device_path, NMDevice *device,
const char *dbus_sender, /* NULL if automatic */ const char *dbus_sender, /* NULL if automatic */
GError **error); GError **error);

View File

@@ -1040,7 +1040,7 @@ auto_activate_device (gpointer user_data)
if (!nm_manager_activate_connection (priv->manager, if (!nm_manager_activate_connection (priv->manager,
best_connection, best_connection,
specific_object, specific_object,
nm_device_get_path (data->device), data->device,
NULL, NULL,
&error)) { &error)) {
nm_log_info (LOGD_DEVICE, "Connection '%s' auto-activation failed: (%d) %s", nm_log_info (LOGD_DEVICE, "Connection '%s' auto-activation failed: (%d) %s",
@@ -1357,7 +1357,7 @@ activate_secondary_connections (NMPolicy *policy,
ac = nm_manager_activate_connection (priv->manager, ac = nm_manager_activate_connection (priv->manager,
NM_CONNECTION (settings_con), NM_CONNECTION (settings_con),
nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)), nm_active_connection_get_path (NM_ACTIVE_CONNECTION (req)),
nm_device_get_path (device), device,
nm_act_request_get_dbus_sender (req), nm_act_request_get_dbus_sender (req),
&error); &error);
if (ac) { if (ac) {