core: device disconnection cleanups

Return an error when trying to disconnect an already-disconnected
or deactivated device.
This commit is contained in:
Dan Williams 2009-09-18 09:05:11 -07:00
parent 7239863d8f
commit 99fb844657
4 changed files with 24 additions and 5 deletions

View file

@ -60,7 +60,7 @@
<method name="Disconnect">
<tp:docstring>
Manually disconnect a device
Disconnects a device and prevents the device from automatically activating further connections without user intervention.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_disconnect"/>
</method>

View file

@ -53,6 +53,8 @@ nm_device_interface_error_get_type (void)
ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_CONNECTION_ACTIVATING, "ConnectionActivating"),
/* Connection is invalid for this device. */
ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_CONNECTION_INVALID, "ConnectionInvalid"),
/* Operation could not be performed because the device is not active. */
ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_NOT_ACTIVE, "NotActive"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("NMDeviceInterfaceError", values);
@ -277,12 +279,28 @@ gboolean
nm_device_interface_disconnect (NMDeviceInterface *device,
GError **error)
{
g_return_val_if_fail (device, FALSE);
gboolean success = FALSE;
return NM_DEVICE_INTERFACE_GET_INTERFACE (device)->disconnect (device, error);
g_return_val_if_fail (NM_IS_DEVICE_INTERFACE (device), FALSE);
switch (nm_device_interface_get_state (device)) {
case NM_DEVICE_STATE_UNKNOWN:
case NM_DEVICE_STATE_UNMANAGED:
case NM_DEVICE_STATE_UNAVAILABLE:
case NM_DEVICE_STATE_DISCONNECTED:
g_set_error_literal (error,
NM_DEVICE_INTERFACE_ERROR,
NM_DEVICE_INTERFACE_ERROR_NOT_ACTIVE,
"Cannot disconnect an inactive device.");
break;
default:
success = NM_DEVICE_INTERFACE_GET_INTERFACE (device)->disconnect (device, error);
break;
}
return success;
}
static gboolean
impl_device_disconnect (NMDeviceInterface *device,
GError **error)

View file

@ -36,6 +36,7 @@ typedef enum
{
NM_DEVICE_INTERFACE_ERROR_CONNECTION_ACTIVATING = 0,
NM_DEVICE_INTERFACE_ERROR_CONNECTION_INVALID,
NM_DEVICE_INTERFACE_ERROR_NOT_ACTIVE,
} NMDeviceInterfaceError;
#define NM_DEVICE_INTERFACE_ERROR (nm_device_interface_error_quark ())

View file

@ -2080,8 +2080,8 @@ device_disconnect (NMDeviceInterface *device,
GError **error)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (NM_DEVICE (device));
priv->autoconnect_inhibit = TRUE;
nm_device_deactivate (device, NM_DEVICE_STATE_REASON_USER_REQUESTED);
nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_USER_REQUESTED);
return TRUE;
}