diff options
author | Thomas Haller <thaller@redhat.com> | 2017-02-23 16:45:04 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-02-23 17:00:09 +0100 |
commit | 71a22df337fa36770827f5695966a501963a8cb0 (patch) | |
tree | bf1cac43d45a430547ee64df85373620cd12606a | |
parent | 9a64168c871bdf00e7ff2ff67c6751aabdcc3910 (diff) | |
download | NetworkManager-71a22df337fa36770827f5695966a501963a8cb0.tar.gz |
settings: refactor autoconnect-blocked-reason to use own enum
Don't reuse NMDeviceStateReason for the autoconnect-blocked-reason. There are
only two cases we care: blocked-due-to-no-secrets, blocked-otherwise.
Encode these values in a new enum type.
-rw-r--r-- | src/devices/wwan/nm-device-modem.c | 6 | ||||
-rw-r--r-- | src/nm-policy.c | 14 | ||||
-rw-r--r-- | src/settings/nm-settings-connection.c | 26 | ||||
-rw-r--r-- | src/settings/nm-settings-connection.h | 12 |
4 files changed, 37 insertions, 21 deletions
diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 076eb19dd6..c9a7a2a814 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -390,8 +390,10 @@ device_state_changed (NMDevice *device, /* Block autoconnect of the just-failed connection for situations * where a retry attempt would just fail again. */ - if (connection) - nm_settings_connection_set_autoconnect_blocked_reason (connection, reason); + if (connection) { + nm_settings_connection_set_autoconnect_blocked_reason (connection, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_BLOCKED); + } break; default: break; diff --git a/src/nm-policy.c b/src/nm-policy.c index 7050f93281..9e6f51f652 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1155,7 +1155,7 @@ reset_autoconnect_all (NMPolicy *self, NMDevice *device) if (!device || nm_device_check_connection_compatible (device, NM_CONNECTION (connection))) { nm_settings_connection_reset_autoconnect_retries (connection); - nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_DEVICE_STATE_REASON_NONE); + nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_UNBLOCKED); } } } @@ -1173,9 +1173,9 @@ reset_autoconnect_for_failed_secrets (NMPolicy *self) for (i = 0; connections[i]; i++) { NMSettingsConnection *connection = connections[i]; - if (nm_settings_connection_get_autoconnect_blocked_reason (connection) == NM_DEVICE_STATE_REASON_NO_SECRETS) { + if (nm_settings_connection_get_autoconnect_blocked_reason (connection) == NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS) { nm_settings_connection_reset_autoconnect_retries (connection); - nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_DEVICE_STATE_REASON_NONE); + nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_UNBLOCKED); } } } @@ -1203,7 +1203,7 @@ block_autoconnect_for_device (NMPolicy *self, NMDevice *device) if (nm_device_check_connection_compatible (device, NM_CONNECTION (connection))) { nm_settings_connection_set_autoconnect_blocked_reason (connection, - NM_DEVICE_STATE_REASON_USER_REQUESTED); + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_BLOCKED); } } } @@ -1469,7 +1469,7 @@ device_state_changed (NMDevice *device, _LOGD (LOGD_DEVICE, "connection '%s' now blocked from autoconnect due to no secrets", nm_settings_connection_get_id (connection)); - nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_DEVICE_STATE_REASON_NO_SECRETS); + nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS); } else if (tries != 0) { _LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left", nm_settings_connection_get_id (connection), tries); @@ -1534,7 +1534,7 @@ device_state_changed (NMDevice *device, _LOGD (LOGD_DEVICE, "blocking autoconnect of connection '%s' by user request", nm_settings_connection_get_id (connection)); nm_settings_connection_set_autoconnect_blocked_reason (connection, - NM_DEVICE_STATE_REASON_USER_REQUESTED); + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_BLOCKED); } } } @@ -1562,7 +1562,7 @@ device_state_changed (NMDevice *device, case NM_DEVICE_STATE_IP_CONFIG: /* We must have secrets if we got here. */ if (connection) - nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_DEVICE_STATE_REASON_NONE); + nm_settings_connection_set_autoconnect_blocked_reason (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_UNBLOCKED); break; case NM_DEVICE_STATE_SECONDARIES: if (connection) diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index 43076845a6..e443920efe 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -69,17 +69,24 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; typedef struct _NMSettingsConnectionPrivate { - gboolean removed; NMAgentManager *agent_mgr; NMSessionMonitor *session_monitor; gulong session_changed_id; NMSettingsConnectionFlags flags; - gboolean ready; + + bool removed:1; + bool ready:1; + + /* Is this connection visible by some session? */ + bool visible:1; + + bool timestamp_set:1; + + NMSettingsAutoconnectBlockedReason autoconnect_blocked_reason:3; GSList *pending_auths; /* List of pending authentication requests */ - gboolean visible; /* Is this connection is visible by some session? */ GSList *get_secret_requests; /* in-progress secrets requests */ @@ -99,12 +106,10 @@ typedef struct _NMSettingsConnectionPrivate { NMConnection *agent_secrets; guint64 timestamp; /* Up-to-date timestamp of connection use */ - gboolean timestamp_set; GHashTable *seen_bssids; /* Up-to-date BSSIDs that's been seen for the connection */ int autoconnect_retries; gint32 autoconnect_retry_time; - NMDeviceStateReason autoconnect_blocked_reason; char *filename; } NMSettingsConnectionPrivate; @@ -2604,7 +2609,7 @@ nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *self) return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_retry_time; } -NMDeviceStateReason +NMSettingsAutoconnectBlockedReason nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *self) { return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_blocked_reason; @@ -2612,8 +2617,12 @@ nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *sel void nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection *self, - NMDeviceStateReason reason) + NMSettingsAutoconnectBlockedReason reason) { + g_return_if_fail (NM_IN_SET (reason, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_UNBLOCKED, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_BLOCKED, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS)); NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_blocked_reason = reason; } @@ -2626,7 +2635,7 @@ nm_settings_connection_can_autoconnect (NMSettingsConnection *self) if ( !priv->visible || priv->autoconnect_retries == 0 - || priv->autoconnect_blocked_reason != NM_DEVICE_STATE_REASON_NONE) + || priv->autoconnect_blocked_reason != NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_UNBLOCKED) return FALSE; s_con = nm_connection_get_setting_connection (NM_CONNECTION (self)); @@ -2766,7 +2775,6 @@ nm_settings_connection_init (NMSettingsConnection *self) priv->seen_bssids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); priv->autoconnect_retries = AUTOCONNECT_RETRIES_UNSET; - priv->autoconnect_blocked_reason = NM_DEVICE_STATE_REASON_NONE; g_signal_connect (self, NM_CONNECTION_SECRETS_CLEARED, G_CALLBACK (secrets_cleared_cb), NULL); g_signal_connect (self, NM_CONNECTION_CHANGED, G_CALLBACK (connection_changed_cb), NULL); diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h index a2d6125734..e1ae9ab277 100644 --- a/src/settings/nm-settings-connection.h +++ b/src/settings/nm-settings-connection.h @@ -82,6 +82,12 @@ typedef enum { /*< skip >*/ NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED = (1LL << 1), } NMSettingsConnectionCommitReason; +typedef enum { + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_UNBLOCKED = 0, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_BLOCKED = 1, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS = 2, +} NMSettingsAutoconnectBlockedReason; + struct _NMSettingsConnectionCallId; typedef struct _NMSettingsConnectionCallId *NMSettingsConnectionCallId; @@ -215,9 +221,9 @@ void nm_settings_connection_reset_autoconnect_retries (NMSettingsConnection *sel gint32 nm_settings_connection_get_autoconnect_retry_time (NMSettingsConnection *self); -NMDeviceStateReason nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *self); -void nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection *self, - NMDeviceStateReason reason); +NMSettingsAutoconnectBlockedReason nm_settings_connection_get_autoconnect_blocked_reason (NMSettingsConnection *self); +void nm_settings_connection_set_autoconnect_blocked_reason (NMSettingsConnection *self, + NMSettingsAutoconnectBlockedReason reason); gboolean nm_settings_connection_can_autoconnect (NMSettingsConnection *self); |