manager: abstract code from do_sleep_wake() to reuse it

The code that is adding the devices to the sleeping list and taking them
down should be moved to a separated function. This way we can reuse it
and we avoid duplicating code.
This commit is contained in:
Fernando Fernandez Mancera
2024-02-06 01:04:00 +01:00
parent 05ef682bb5
commit c8cf02e6b8

View File

@@ -7215,6 +7215,29 @@ device_sleep_cb(NMDevice *device, GParamSpec *pspec, NMManager *self)
}
}
static void
_handle_device_takedown(NMManager *self, NMDevice *device, gboolean suspending)
{
nm_device_notify_sleeping(device);
if (nm_device_is_activating(device)
|| nm_device_get_state(device) == NM_DEVICE_STATE_ACTIVATED) {
_LOGD(LOGD_SUSPEND,
"sleep: wait disconnection of device %s",
nm_device_get_ip_iface(device));
if (sleep_devices_add(self, device, suspending))
nm_device_queue_state(device,
NM_DEVICE_STATE_DEACTIVATING,
NM_DEVICE_STATE_REASON_SLEEPING);
} else {
nm_device_set_unmanaged_by_flags(device,
NM_UNMANAGED_SLEEPING,
NM_UNMAN_FLAG_OP_SET_UNMANAGED,
NM_DEVICE_STATE_REASON_SLEEPING);
}
}
static void
do_sleep_wake(NMManager *self, gboolean sleeping_changed)
{
@@ -7249,24 +7272,7 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed)
continue;
}
nm_device_notify_sleeping(device);
if (nm_device_is_activating(device)
|| nm_device_get_state(device) == NM_DEVICE_STATE_ACTIVATED) {
_LOGD(LOGD_SUSPEND,
"sleep: wait disconnection of device %s",
nm_device_get_ip_iface(device));
if (sleep_devices_add(self, device, suspending))
nm_device_queue_state(device,
NM_DEVICE_STATE_DEACTIVATING,
NM_DEVICE_STATE_REASON_SLEEPING);
} else {
nm_device_set_unmanaged_by_flags(device,
NM_UNMANAGED_SLEEPING,
NM_UNMAN_FLAG_OP_SET_UNMANAGED,
NM_DEVICE_STATE_REASON_SLEEPING);
}
_handle_device_takedown(self, device, suspending);
}
} else {
_LOGD(LOGD_SUSPEND, "sleep: %s...", waking_from_suspend ? "waking up" : "re-enabling");