mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 11:19:16 +02:00
device: add flags to nm_device_is_available()
This commit is contained in:
parent
e96af59444
commit
52dbb2398a
11 changed files with 35 additions and 24 deletions
|
|
@ -930,7 +930,7 @@ bluez_device_removed (NMBluezDevice *bdev, gpointer user_data)
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_available (NMDevice *dev)
|
is_available (NMDevice *dev, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
NMDeviceBt *self = NM_DEVICE_BT (dev);
|
NMDeviceBt *self = NM_DEVICE_BT (dev);
|
||||||
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (self);
|
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (self);
|
||||||
|
|
@ -958,7 +958,7 @@ handle_availability_change (NMDeviceBt *self,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
available = nm_device_is_available (device);
|
available = nm_device_is_available (device, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE);
|
||||||
if (available == old_available)
|
if (available == old_available)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -988,7 +988,7 @@ set_mm_running (NMDeviceBt *self, gboolean running)
|
||||||
_LOGD (LOGD_BT, "ModemManager now %s",
|
_LOGD (LOGD_BT, "ModemManager now %s",
|
||||||
running ? "available" : "unavailable");
|
running ? "available" : "unavailable");
|
||||||
|
|
||||||
old_available = nm_device_is_available (NM_DEVICE (self));
|
old_available = nm_device_is_available (NM_DEVICE (self), NM_DEVICE_CHECK_DEV_AVAILABLE_NONE);
|
||||||
priv->mm_running = running;
|
priv->mm_running = running;
|
||||||
handle_availability_change (self, old_available, NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE);
|
handle_availability_change (self, old_available, NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ get_generic_capabilities (NMDevice *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_available (NMDevice *dev)
|
is_available (NMDevice *dev, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
if (NM_DEVICE_GET_CLASS (dev)->is_up)
|
if (NM_DEVICE_GET_CLASS (dev)->is_up)
|
||||||
return NM_DEVICE_GET_CLASS (dev)->is_up (dev);
|
return NM_DEVICE_GET_CLASS (dev)->is_up (dev);
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ get_generic_capabilities (NMDevice *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_available (NMDevice *dev)
|
is_available (NMDevice *dev, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
if (NM_DEVICE_GET_CLASS (dev)->is_up)
|
if (NM_DEVICE_GET_CLASS (dev)->is_up)
|
||||||
return NM_DEVICE_GET_CLASS (dev)->is_up (dev);
|
return NM_DEVICE_GET_CLASS (dev)->is_up (dev);
|
||||||
|
|
|
||||||
|
|
@ -1734,7 +1734,7 @@ nm_device_removed (NMDevice *self)
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_available (NMDevice *self)
|
is_available (NMDevice *self, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||||
|
|
||||||
|
|
@ -1744,6 +1744,8 @@ is_available (NMDevice *self)
|
||||||
/**
|
/**
|
||||||
* nm_device_is_available:
|
* nm_device_is_available:
|
||||||
* @self: the #NMDevice
|
* @self: the #NMDevice
|
||||||
|
* @flags: additional flags to influence the check. Flags have the
|
||||||
|
* meaning to increase the availability of a device.
|
||||||
*
|
*
|
||||||
* Checks if @self would currently be capable of activating a
|
* Checks if @self would currently be capable of activating a
|
||||||
* connection. In particular, it checks that the device is ready (eg,
|
* connection. In particular, it checks that the device is ready (eg,
|
||||||
|
|
@ -1759,14 +1761,14 @@ is_available (NMDevice *self)
|
||||||
* Returns: %TRUE or %FALSE
|
* Returns: %TRUE or %FALSE
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
nm_device_is_available (NMDevice *self)
|
nm_device_is_available (NMDevice *self, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||||
|
|
||||||
if (priv->firmware_missing)
|
if (priv->firmware_missing)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return NM_DEVICE_GET_CLASS (self)->is_available (self);
|
return NM_DEVICE_GET_CLASS (self)->is_available (self, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
@ -7755,7 +7757,7 @@ _set_state_full (NMDevice *self,
|
||||||
* we can't change states again from the state handler for a variety of
|
* we can't change states again from the state handler for a variety of
|
||||||
* reasons.
|
* reasons.
|
||||||
*/
|
*/
|
||||||
if (nm_device_is_available (self)) {
|
if (nm_device_is_available (self, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE)) {
|
||||||
_LOGD (LOGD_DEVICE, "device is available, will transition to DISCONNECTED");
|
_LOGD (LOGD_DEVICE, "device is available, will transition to DISCONNECTED");
|
||||||
nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_NONE);
|
nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_NONE);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,15 @@ struct _NMDevice {
|
||||||
GObject parent;
|
GObject parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* The flags have an relaxing meaning, that means, specifying more flags, can make
|
||||||
|
* a device appear more available. It can never make a device less available. */
|
||||||
|
typedef enum {
|
||||||
|
NM_DEVICE_CHECK_DEV_AVAILABLE_NONE = 0,
|
||||||
|
|
||||||
|
__NM_DEVICE_CHECK_DEV_AVAILABLE_ALL,
|
||||||
|
NM_DEVICE_CHECK_DEV_AVAILABLE_ALL = (((__NM_DEVICE_CHECK_DEV_AVAILABLE_ALL - 1) << 1) - 1),
|
||||||
|
} NMDeviceCheckDevAvailableFlags;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GObjectClass parent;
|
GObjectClass parent;
|
||||||
|
|
||||||
|
|
@ -130,7 +139,7 @@ typedef struct {
|
||||||
|
|
||||||
guint32 (* get_generic_capabilities) (NMDevice *self);
|
guint32 (* get_generic_capabilities) (NMDevice *self);
|
||||||
|
|
||||||
gboolean (* is_available) (NMDevice *self);
|
gboolean (* is_available) (NMDevice *self, NMDeviceCheckDevAvailableFlags flags);
|
||||||
|
|
||||||
gboolean (* get_enabled) (NMDevice *self);
|
gboolean (* get_enabled) (NMDevice *self);
|
||||||
|
|
||||||
|
|
@ -282,7 +291,7 @@ NMConnection * nm_device_get_connection (NMDevice *dev);
|
||||||
|
|
||||||
void nm_device_removed (NMDevice *dev);
|
void nm_device_removed (NMDevice *dev);
|
||||||
|
|
||||||
gboolean nm_device_is_available (NMDevice *dev);
|
gboolean nm_device_is_available (NMDevice *dev, NMDeviceCheckDevAvailableFlags flags);
|
||||||
gboolean nm_device_has_carrier (NMDevice *dev);
|
gboolean nm_device_has_carrier (NMDevice *dev);
|
||||||
|
|
||||||
NMConnection * nm_device_generate_connection (NMDevice *self, NMDevice *master);
|
NMConnection * nm_device_generate_connection (NMDevice *self, NMDevice *master);
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ get_generic_capabilities (NMDevice *device)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_available (NMDevice *device)
|
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
if (NM_DEVICE_GET_CLASS (device)->is_up)
|
if (NM_DEVICE_GET_CLASS (device)->is_up)
|
||||||
return NM_DEVICE_GET_CLASS (device)->is_up (device);
|
return NM_DEVICE_GET_CLASS (device)->is_up (device);
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_available (NMDevice *device)
|
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (device);
|
NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (device);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1136,7 +1136,7 @@ complete_connection (NMDevice *device,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_available (NMDevice *device)
|
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
|
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
|
||||||
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
||||||
|
|
@ -2162,7 +2162,7 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface,
|
||||||
/* If the interface can now be activated because the supplicant is now
|
/* If the interface can now be activated because the supplicant is now
|
||||||
* available, transition to DISCONNECTED.
|
* available, transition to DISCONNECTED.
|
||||||
*/
|
*/
|
||||||
if ((devstate == NM_DEVICE_STATE_UNAVAILABLE) && nm_device_is_available (device)) {
|
if ((devstate == NM_DEVICE_STATE_UNAVAILABLE) && nm_device_is_available (device, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE)) {
|
||||||
nm_device_state_changed (device,
|
nm_device_state_changed (device,
|
||||||
NM_DEVICE_STATE_DISCONNECTED,
|
NM_DEVICE_STATE_DISCONNECTED,
|
||||||
NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE);
|
NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE);
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ update_availability (NMDeviceWimax *self, gboolean old_available)
|
||||||
NMDeviceState state;
|
NMDeviceState state;
|
||||||
gboolean new_available, changed = FALSE;
|
gboolean new_available, changed = FALSE;
|
||||||
|
|
||||||
new_available = nm_device_is_available (device);
|
new_available = nm_device_is_available (device, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE);
|
||||||
if (new_available == old_available)
|
if (new_available == old_available)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
|
@ -281,7 +281,7 @@ set_enabled (NMDevice *device, gboolean enabled)
|
||||||
if (priv->enabled == enabled)
|
if (priv->enabled == enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
old_available = nm_device_is_available (NM_DEVICE (device));
|
old_available = nm_device_is_available (NM_DEVICE (device), NM_DEVICE_CHECK_DEV_AVAILABLE_NONE);
|
||||||
priv->enabled = enabled;
|
priv->enabled = enabled;
|
||||||
|
|
||||||
nm_log_dbg (LOGD_WIMAX, "(%s): radio now %s",
|
nm_log_dbg (LOGD_WIMAX, "(%s): radio now %s",
|
||||||
|
|
@ -488,7 +488,7 @@ can_auto_connect (NMDevice *device,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_available (NMDevice *device)
|
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device);
|
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device);
|
||||||
const char *iface = nm_device_get_iface (device);
|
const char *iface = nm_device_get_iface (device);
|
||||||
|
|
@ -716,7 +716,7 @@ wmx_state_change_cb (struct wmxsdk *wmxsdk,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
state = nm_device_get_state (NM_DEVICE (self));
|
state = nm_device_get_state (NM_DEVICE (self));
|
||||||
old_available = nm_device_is_available (NM_DEVICE (self));
|
old_available = nm_device_is_available (NM_DEVICE (self), NM_DEVICE_CHECK_DEV_AVAILABLE_NONE);
|
||||||
|
|
||||||
priv->status = new_status;
|
priv->status = new_status;
|
||||||
if (priv->current_nsp)
|
if (priv->current_nsp)
|
||||||
|
|
@ -1157,7 +1157,7 @@ static gboolean
|
||||||
sdk_action_defer_cb (gpointer user_data)
|
sdk_action_defer_cb (gpointer user_data)
|
||||||
{
|
{
|
||||||
NMDeviceWimax *self = NM_DEVICE_WIMAX (user_data);
|
NMDeviceWimax *self = NM_DEVICE_WIMAX (user_data);
|
||||||
gboolean old_available = nm_device_is_available (NM_DEVICE (self));
|
gboolean old_available = nm_device_is_available (NM_DEVICE (self), NM_DEVICE_CHECK_DEV_AVAILABLE_NONE);
|
||||||
|
|
||||||
NM_DEVICE_WIMAX_GET_PRIVATE (self)->sdk_action_defer_id = 0;
|
NM_DEVICE_WIMAX_GET_PRIVATE (self)->sdk_action_defer_id = 0;
|
||||||
update_availability (self, old_available);
|
update_availability (self, old_available);
|
||||||
|
|
|
||||||
|
|
@ -300,14 +300,14 @@ modem_state_cb (NMModem *modem,
|
||||||
nm_device_recheck_available_connections (device);
|
nm_device_recheck_available_connections (device);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dev_state >= NM_DEVICE_STATE_DISCONNECTED) && !nm_device_is_available (device)) {
|
if ((dev_state >= NM_DEVICE_STATE_DISCONNECTED) && !nm_device_is_available (device, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE)) {
|
||||||
nm_device_state_changed (device,
|
nm_device_state_changed (device,
|
||||||
NM_DEVICE_STATE_UNAVAILABLE,
|
NM_DEVICE_STATE_UNAVAILABLE,
|
||||||
NM_DEVICE_STATE_REASON_MODEM_FAILED);
|
NM_DEVICE_STATE_REASON_MODEM_FAILED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dev_state == NM_DEVICE_STATE_UNAVAILABLE) && nm_device_is_available (device)) {
|
if ((dev_state == NM_DEVICE_STATE_UNAVAILABLE) && nm_device_is_available (device, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE)) {
|
||||||
nm_device_state_changed (device,
|
nm_device_state_changed (device,
|
||||||
NM_DEVICE_STATE_DISCONNECTED,
|
NM_DEVICE_STATE_DISCONNECTED,
|
||||||
NM_DEVICE_STATE_REASON_MODEM_AVAILABLE);
|
NM_DEVICE_STATE_REASON_MODEM_AVAILABLE);
|
||||||
|
|
@ -584,7 +584,7 @@ set_enabled (NMDevice *device, gboolean enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_available (NMDevice *device)
|
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
||||||
{
|
{
|
||||||
NMDeviceModem *self = NM_DEVICE_MODEM (device);
|
NMDeviceModem *self = NM_DEVICE_MODEM (device);
|
||||||
NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device);
|
NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device);
|
||||||
|
|
|
||||||
|
|
@ -2696,7 +2696,7 @@ _internal_activate_device (NMManager *self, NMActiveConnection *active, GError *
|
||||||
* in the UNAVAILABLE state here. To ensure it can be activated
|
* in the UNAVAILABLE state here. To ensure it can be activated
|
||||||
* immediately, we transition it to DISCONNECTED.
|
* immediately, we transition it to DISCONNECTED.
|
||||||
*/
|
*/
|
||||||
if ( nm_device_is_available (device)
|
if ( nm_device_is_available (device, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE)
|
||||||
&& (nm_device_get_state (device) == NM_DEVICE_STATE_UNAVAILABLE)) {
|
&& (nm_device_get_state (device) == NM_DEVICE_STATE_UNAVAILABLE)) {
|
||||||
nm_device_state_changed (device,
|
nm_device_state_changed (device,
|
||||||
NM_DEVICE_STATE_DISCONNECTED,
|
NM_DEVICE_STATE_DISCONNECTED,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue