diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index e6b537122a..890f77d1cc 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -80,6 +80,7 @@ typedef struct { char *slave_type; GSList *permissions; /* list of Permission structs */ gboolean autoconnect; + gint autoconnect_priority; guint64 timestamp; gboolean read_only; char *zone; @@ -95,6 +96,7 @@ enum { PROP_TYPE, PROP_PERMISSIONS, PROP_AUTOCONNECT, + PROP_AUTOCONNECT_PRIORITY, PROP_TIMESTAMP, PROP_READ_ONLY, PROP_ZONE, @@ -497,6 +499,23 @@ nm_setting_connection_get_autoconnect (NMSettingConnection *setting) return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->autoconnect; } +/** + * nm_setting_connection_get_autoconnect_priority: + * @setting: the #NMSettingConnection + * + * Returns the #NMSettingConnection:autoconnect-priority property of the connection. + * The higher number, the higher priority. + * + * Returns: the connection's autoconnect priority + **/ +gint +nm_setting_connection_get_autoconnect_priority (NMSettingConnection *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0); + + return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->autoconnect_priority; +} + /** * nm_setting_connection_get_timestamp: * @setting: the #NMSettingConnection @@ -1094,6 +1113,9 @@ set_property (GObject *object, guint prop_id, case PROP_AUTOCONNECT: priv->autoconnect = g_value_get_boolean (value); break; + case PROP_AUTOCONNECT_PRIORITY: + priv->autoconnect_priority = g_value_get_int (value); + break; case PROP_TIMESTAMP: priv->timestamp = g_value_get_uint64 (value); break; @@ -1165,6 +1187,9 @@ get_property (GObject *object, guint prop_id, case PROP_AUTOCONNECT: g_value_set_boolean (value, nm_setting_connection_get_autoconnect (setting)); break; + case PROP_AUTOCONNECT_PRIORITY: + g_value_set_int (value, nm_setting_connection_get_autoconnect_priority (setting)); + break; case PROP_TIMESTAMP: g_value_set_uint64 (value, nm_setting_connection_get_timestamp (setting)); break; @@ -1331,6 +1356,24 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS)); + /** + * NMSettingConnection:autoconnect-priority: + * + * The autoconnect priority. If the connection is set to autoconnect, + * connections with higher priority will be preferred. Defaults to 0. + * The higher number means higher priority. + **/ + g_object_class_install_property + (object_class, PROP_AUTOCONNECT_PRIORITY, + g_param_spec_int (NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY, "", "", + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MIN, + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MAX, + NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); + /** * NMSettingConnection:timestamp: * diff --git a/libnm-core/nm-setting-connection.h b/libnm-core/nm-setting-connection.h index 169e2c18ee..4b40401d32 100644 --- a/libnm-core/nm-setting-connection.h +++ b/libnm-core/nm-setting-connection.h @@ -72,11 +72,16 @@ typedef enum #define NM_SETTING_CONNECTION_ERROR nm_setting_connection_error_quark () GQuark nm_setting_connection_error_quark (void); +#define NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MIN -999 +#define NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_MAX 999 +#define NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY_DEFAULT 0 + #define NM_SETTING_CONNECTION_ID "id" #define NM_SETTING_CONNECTION_UUID "uuid" #define NM_SETTING_CONNECTION_INTERFACE_NAME "interface-name" #define NM_SETTING_CONNECTION_TYPE "type" #define NM_SETTING_CONNECTION_AUTOCONNECT "autoconnect" +#define NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY "autoconnect-priority" #define NM_SETTING_CONNECTION_TIMESTAMP "timestamp" #define NM_SETTING_CONNECTION_READ_ONLY "read-only" #define NM_SETTING_CONNECTION_PERMISSIONS "permissions" @@ -111,6 +116,7 @@ const char *nm_setting_connection_get_uuid (NMSettingConnection *set const char *nm_setting_connection_get_interface_name (NMSettingConnection *setting); const char *nm_setting_connection_get_connection_type (NMSettingConnection *setting); gboolean nm_setting_connection_get_autoconnect (NMSettingConnection *setting); +gint nm_setting_connection_get_autoconnect_priority (NMSettingConnection *setting); guint64 nm_setting_connection_get_timestamp (NMSettingConnection *setting); gboolean nm_setting_connection_get_read_only (NMSettingConnection *setting); diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 2cb6137866..63811102ca 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -1599,6 +1599,7 @@ test_connection_diff_a_only (void) { NM_SETTING_CONNECTION_TYPE, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_TIMESTAMP, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_AUTOCONNECT, NM_SETTING_DIFF_RESULT_IN_A }, + { NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_READ_ONLY, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_PERMISSIONS, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_ZONE, NM_SETTING_DIFF_RESULT_IN_A }, diff --git a/libnm/libnm.ver b/libnm/libnm.ver index bcb3a97381..ca8283abb4 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -530,6 +530,7 @@ global: nm_setting_connection_error_get_type; nm_setting_connection_error_quark; nm_setting_connection_get_autoconnect; + nm_setting_connection_get_autoconnect_priority; nm_setting_connection_get_connection_type; nm_setting_connection_get_gateway_ping_timeout; nm_setting_connection_get_id;