core: device disconnection cleanups
Return an error when trying to disconnect an already-disconnected or deactivated device.
This commit is contained in:
@@ -60,7 +60,7 @@
|
|||||||
|
|
||||||
<method name="Disconnect">
|
<method name="Disconnect">
|
||||||
<tp:docstring>
|
<tp:docstring>
|
||||||
Manually disconnect a device
|
Disconnects a device and prevents the device from automatically activating further connections without user intervention.
|
||||||
</tp:docstring>
|
</tp:docstring>
|
||||||
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_disconnect"/>
|
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_disconnect"/>
|
||||||
</method>
|
</method>
|
||||||
|
@@ -53,6 +53,8 @@ nm_device_interface_error_get_type (void)
|
|||||||
ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_CONNECTION_ACTIVATING, "ConnectionActivating"),
|
ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_CONNECTION_ACTIVATING, "ConnectionActivating"),
|
||||||
/* Connection is invalid for this device. */
|
/* Connection is invalid for this device. */
|
||||||
ENUM_ENTRY (NM_DEVICE_INTERFACE_ERROR_CONNECTION_INVALID, "ConnectionInvalid"),
|
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 }
|
{ 0, 0, 0 }
|
||||||
};
|
};
|
||||||
etype = g_enum_register_static ("NMDeviceInterfaceError", values);
|
etype = g_enum_register_static ("NMDeviceInterfaceError", values);
|
||||||
@@ -277,11 +279,27 @@ gboolean
|
|||||||
nm_device_interface_disconnect (NMDeviceInterface *device,
|
nm_device_interface_disconnect (NMDeviceInterface *device,
|
||||||
GError **error)
|
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
|
static gboolean
|
||||||
impl_device_disconnect (NMDeviceInterface *device,
|
impl_device_disconnect (NMDeviceInterface *device,
|
||||||
|
@@ -36,6 +36,7 @@ typedef enum
|
|||||||
{
|
{
|
||||||
NM_DEVICE_INTERFACE_ERROR_CONNECTION_ACTIVATING = 0,
|
NM_DEVICE_INTERFACE_ERROR_CONNECTION_ACTIVATING = 0,
|
||||||
NM_DEVICE_INTERFACE_ERROR_CONNECTION_INVALID,
|
NM_DEVICE_INTERFACE_ERROR_CONNECTION_INVALID,
|
||||||
|
NM_DEVICE_INTERFACE_ERROR_NOT_ACTIVE,
|
||||||
} NMDeviceInterfaceError;
|
} NMDeviceInterfaceError;
|
||||||
|
|
||||||
#define NM_DEVICE_INTERFACE_ERROR (nm_device_interface_error_quark ())
|
#define NM_DEVICE_INTERFACE_ERROR (nm_device_interface_error_quark ())
|
||||||
|
@@ -2080,8 +2080,8 @@ device_disconnect (NMDeviceInterface *device,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (NM_DEVICE (device));
|
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (NM_DEVICE (device));
|
||||||
|
|
||||||
priv->autoconnect_inhibit = TRUE;
|
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);
|
nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_USER_REQUESTED);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user