mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-19 12:40:42 +01:00
keep-alive: add nm_keep_alive_disarm() to silence notifications once we disconnect
The NMKeepAlive instance is useful to find out when we should disconnect. The moment when we start disconnecting, we don't care about it anymore. Add a nm_keep_alive_disarm() function to suppress property change events about the alive state, after that point. Emitting further events from that point on is only confusing. Yes, this means, a NMKeepAlive instance shall not be re-used for multiple purposes. Create a separate keep-alive instace for each target that should be guarded. Also, once disarmed, we can release all resources that the NMKeepAlive instance was holding until now.
This commit is contained in:
parent
c668d972ea
commit
15033be1a3
3 changed files with 48 additions and 4 deletions
|
|
@ -264,6 +264,12 @@ nm_active_connection_set_state (NMActiveConnection *self,
|
|||
state_to_string (new_state),
|
||||
state_to_string (priv->state));
|
||||
|
||||
if (new_state > NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
|
||||
/* once we are about to deactivate, we don't need the keep-alive instance
|
||||
* anymore. Freeze/disarm it. */
|
||||
nm_keep_alive_disarm (priv->keep_alive);
|
||||
}
|
||||
|
||||
if ( new_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED
|
||||
&& priv->activation_type == NM_ACTIVATION_TYPE_ASSUME) {
|
||||
/* assuming connections mean to gracefully take over an externally
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ typedef struct {
|
|||
guint subscription_id;
|
||||
|
||||
bool floating:1;
|
||||
bool disarmed:1;
|
||||
|
||||
bool forced:1;
|
||||
bool alive:1;
|
||||
bool dbus_client_confirmed:1;
|
||||
|
|
@ -100,6 +102,11 @@ _notify_alive (NMKeepAlive *self)
|
|||
{
|
||||
NMKeepAlivePrivate *priv = NM_KEEP_ALIVE_GET_PRIVATE (self);
|
||||
|
||||
if (priv->disarmed) {
|
||||
/* once disarmed, the alive state is frozen. */
|
||||
return;
|
||||
}
|
||||
|
||||
if (priv->alive == _is_alive (self))
|
||||
return;
|
||||
priv->alive = !priv->alive;
|
||||
|
|
@ -163,7 +170,8 @@ _set_settings_connection_watch_visible (NMKeepAlive *self,
|
|||
old_connection = g_steal_pointer (&priv->connection);
|
||||
}
|
||||
|
||||
if (connection) {
|
||||
if ( connection
|
||||
&& !priv->disarmed) {
|
||||
priv->connection = g_object_ref (connection);
|
||||
g_signal_connect (priv->connection,
|
||||
NM_SETTINGS_CONNECTION_FLAGS_CHANGED,
|
||||
|
|
@ -300,7 +308,8 @@ nm_keep_alive_set_dbus_client_watch (NMKeepAlive *self,
|
|||
|
||||
cleanup_dbus_watch (self);
|
||||
|
||||
if (client_address) {
|
||||
if ( client_address
|
||||
&& !priv->disarmed) {
|
||||
_LOGD ("Registering dbus client watch for keep alive");
|
||||
|
||||
priv->dbus_client = g_strdup (client_address);
|
||||
|
|
@ -323,6 +332,33 @@ nm_keep_alive_set_dbus_client_watch (NMKeepAlive *self,
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* nm_keep_alive_disarm:
|
||||
* @self: the #NMKeepAlive instance
|
||||
*
|
||||
* Once the instance is disarmed, it will not change its alive state
|
||||
* anymore and will not emit anymore property changed signals about
|
||||
* alive state changed.
|
||||
*
|
||||
* As such, it will also free internal resources (since they no longer
|
||||
* affect the externally visible state).
|
||||
*
|
||||
* Once disarmed, the instance is frozen and cannot change anymore.
|
||||
*/
|
||||
void
|
||||
nm_keep_alive_disarm (NMKeepAlive *self)
|
||||
{
|
||||
NMKeepAlivePrivate *priv = NM_KEEP_ALIVE_GET_PRIVATE (self);
|
||||
|
||||
priv->disarmed = TRUE;
|
||||
|
||||
/* release internal data. */
|
||||
_set_settings_connection_watch_visible (self, NULL, FALSE);
|
||||
cleanup_dbus_watch (self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
get_property (GObject *object,
|
||||
guint prop_id,
|
||||
|
|
@ -366,8 +402,8 @@ dispose (GObject *object)
|
|||
{
|
||||
NMKeepAlive *self = NM_KEEP_ALIVE (object);
|
||||
|
||||
_set_settings_connection_watch_visible (self, NULL, FALSE);
|
||||
cleanup_dbus_watch (self);
|
||||
/* disarm also happens to free all resources. */
|
||||
nm_keep_alive_disarm (self);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ gboolean nm_keep_alive_is_alive (NMKeepAlive *self);
|
|||
|
||||
void nm_keep_alive_sink (NMKeepAlive *self);
|
||||
|
||||
void nm_keep_alive_disarm (NMKeepAlive *self);
|
||||
|
||||
void nm_keep_alive_set_forced (NMKeepAlive *self,
|
||||
gboolean forced);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue