core/connections: pick base setting from settings the connection actually has

We will need multiple base settings for Bluetooth NAP servers: bluetooth and
bridge. We want to identify the device as "bluetooth" to the user, but leave
the Bridge factory handle it.

The "connection.type" is somewhat redundant -- let's keep it for what the user
sees. And identify the actual base setting to pick the right factory by the
actually present setting.
This commit is contained in:
Lubomir Rintel
2017-05-22 20:11:40 +02:00
parent 15daf29220
commit 02e527f644
2 changed files with 17 additions and 22 deletions

View File

@@ -592,10 +592,12 @@ _nm_connection_find_base_type_setting (NMConnection *connection)
continue;
if (setting) {
/* FIXME: currently, if there is more than one matching base type,
* we cannot detect the base setting.
* See: https://bugzilla.gnome.org/show_bug.cgi?id=696936#c8 */
return NULL;
NMSettingConnection *s_con = nm_connection_get_setting_connection (connection);
if (!s_con)
return NULL;
return nm_connection_get_setting_by_name (connection,
nm_setting_connection_get_connection_type (s_con));
}
setting = s_iter;
}
@@ -1609,19 +1611,16 @@ nm_connection_to_dbus (NMConnection *connection,
gboolean
nm_connection_is_type (NMConnection *connection, const char *type)
{
NMSettingConnection *s_con;
const char *type2;
NMSetting *setting;
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (type != NULL, FALSE);
s_con = nm_connection_get_setting_connection (connection);
if (!s_con)
setting = nm_connection_get_setting_by_name (connection, type);
if (!setting)
return FALSE;
type2 = nm_setting_connection_get_connection_type (s_con);
return (g_strcmp0 (type2, type) == 0);
return _nm_setting_is_base_type (setting);
}
static int
@@ -1850,22 +1849,19 @@ nm_connection_get_id (NMConnection *connection)
* nm_connection_get_connection_type:
* @connection: the #NMConnection
*
* A shortcut to return the type from the connection's #NMSettingConnection.
*
* Returns: the type from the connection's 'connection' setting
* Returns: the connection's base type.
**/
const char *
nm_connection_get_connection_type (NMConnection *connection)
{
NMSettingConnection *s_con;
NMSetting *setting;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
s_con = nm_connection_get_setting_connection (connection);
if (!s_con)
setting = _nm_connection_find_base_type_setting (connection);
if (!setting)
return NULL;
return nm_setting_connection_get_connection_type (s_con);
return nm_setting_get_name (setting);
}
/**
@@ -1880,9 +1876,8 @@ nm_connection_get_connection_type (NMConnection *connection)
gboolean
nm_connection_is_virtual (NMConnection *connection)
{
const char *type;
const char *type = nm_connection_get_connection_type (connection);
type = nm_connection_get_connection_type (connection);
g_return_val_if_fail (type != NULL, FALSE);
if ( !strcmp (type, NM_SETTING_BOND_SETTING_NAME)

View File

@@ -3558,7 +3558,7 @@ _test_connection_normalize_type_normalizable_type (const char *type,
nm_connection_add_setting (con, s_base);
}
g_assert (!nm_connection_get_connection_type (con));
g_assert (!nm_setting_connection_get_connection_type (s_con));
g_assert (nm_connection_get_setting_by_name (con, type) == s_base);
nmtst_assert_connection_verifies_after_normalization (con, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY);