libnm: rework _nm_setting_aggregate() to delegate to setting class
Instead of special-casing the aggregate implementation for NMSettingVpn, delegate to a virtual function. This will also work with other settings, that have properties/secrets that are not GObject based properties.
This commit is contained in:
@@ -101,9 +101,6 @@ gboolean _nm_setting_verify_secret_string (const char *str,
|
|||||||
gboolean _nm_setting_aggregate (NMSetting *setting,
|
gboolean _nm_setting_aggregate (NMSetting *setting,
|
||||||
NMConnectionAggregateType type,
|
NMConnectionAggregateType type,
|
||||||
gpointer arg);
|
gpointer arg);
|
||||||
gboolean _nm_setting_vpn_aggregate (NMSettingVpn *setting,
|
|
||||||
NMConnectionAggregateType type,
|
|
||||||
gpointer arg);
|
|
||||||
|
|
||||||
gboolean _nm_setting_slave_type_is_valid (const char *slave_type, const char **out_port_type);
|
gboolean _nm_setting_slave_type_is_valid (const char *slave_type, const char **out_port_type);
|
||||||
|
|
||||||
|
@@ -449,20 +449,17 @@ nm_setting_vpn_foreach_secret (NMSettingVpn *setting,
|
|||||||
foreach_item_helper (setting, TRUE, func, user_data);
|
foreach_item_helper (setting, TRUE, func, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
static gboolean
|
||||||
_nm_setting_vpn_aggregate (NMSettingVpn *setting,
|
aggregate (NMSetting *setting,
|
||||||
NMConnectionAggregateType type,
|
int type_i,
|
||||||
gpointer arg)
|
gpointer arg)
|
||||||
{
|
{
|
||||||
NMSettingVpnPrivate *priv;
|
NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
|
||||||
|
NMConnectionAggregateType type = type_i;
|
||||||
NMSettingSecretFlags secret_flags;
|
NMSettingSecretFlags secret_flags;
|
||||||
const char *key_name;
|
const char *key_name;
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), FALSE);
|
|
||||||
|
|
||||||
priv = NM_SETTING_VPN_GET_PRIVATE (setting);
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
case NM_CONNECTION_AGGREGATE_ANY_SECRETS:
|
case NM_CONNECTION_AGGREGATE_ANY_SECRETS:
|
||||||
@@ -984,6 +981,7 @@ nm_setting_vpn_class_init (NMSettingVpnClass *klass)
|
|||||||
setting_class->need_secrets = need_secrets;
|
setting_class->need_secrets = need_secrets;
|
||||||
setting_class->compare_property = compare_property;
|
setting_class->compare_property = compare_property;
|
||||||
setting_class->clear_secrets = clear_secrets;
|
setting_class->clear_secrets = clear_secrets;
|
||||||
|
setting_class->aggregate = aggregate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NMSettingVpn:service-type:
|
* NMSettingVpn:service-type:
|
||||||
|
@@ -1812,37 +1812,17 @@ nm_setting_enumerate_values (NMSetting *setting,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static gboolean
|
||||||
* _nm_setting_aggregate:
|
aggregate (NMSetting *setting,
|
||||||
* @setting: the #NMSetting to aggregate.
|
int type_i,
|
||||||
* @type: the #NMConnectionAggregateType aggregate type.
|
|
||||||
* @arg: the in/out arguments for aggregation. They depend on @type.
|
|
||||||
*
|
|
||||||
* This is the implementation detail of _nm_connection_aggregate(). It
|
|
||||||
* makes no sense to call this function directly outside of _nm_connection_aggregate().
|
|
||||||
*
|
|
||||||
* Returns: %TRUE if afterwards the aggregation is complete. That means,
|
|
||||||
* the only caller _nm_connection_aggregate() will not visit other settings
|
|
||||||
* after a setting returns %TRUE (indicating that there is nothing further
|
|
||||||
* to aggregate). Note that is very different from the boolean return
|
|
||||||
* argument of _nm_connection_aggregate(), which serves a different purpose.
|
|
||||||
*/
|
|
||||||
gboolean
|
|
||||||
_nm_setting_aggregate (NMSetting *setting,
|
|
||||||
NMConnectionAggregateType type,
|
|
||||||
gpointer arg)
|
gpointer arg)
|
||||||
{
|
{
|
||||||
|
NMConnectionAggregateType type = type_i;
|
||||||
const NMSettInfoSetting *sett_info;
|
const NMSettInfoSetting *sett_info;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
nm_assert (NM_IN_SET (type, NM_CONNECTION_AGGREGATE_ANY_SECRETS,
|
||||||
g_return_val_if_fail (arg, FALSE);
|
NM_CONNECTION_AGGREGATE_ANY_SYSTEM_SECRET_FLAGS));
|
||||||
g_return_val_if_fail (NM_IN_SET (type, NM_CONNECTION_AGGREGATE_ANY_SECRETS,
|
|
||||||
NM_CONNECTION_AGGREGATE_ANY_SYSTEM_SECRET_FLAGS),
|
|
||||||
FALSE);
|
|
||||||
|
|
||||||
if (NM_IS_SETTING_VPN (setting))
|
|
||||||
return _nm_setting_vpn_aggregate (NM_SETTING_VPN (setting), type, arg);
|
|
||||||
|
|
||||||
sett_info = _nm_setting_class_get_sett_info (NM_SETTING_GET_CLASS (setting));
|
sett_info = _nm_setting_class_get_sett_info (NM_SETTING_GET_CLASS (setting));
|
||||||
for (i = 0; i < sett_info->property_infos_len; i++) {
|
for (i = 0; i < sett_info->property_infos_len; i++) {
|
||||||
@@ -1886,6 +1866,35 @@ _nm_setting_aggregate (NMSetting *setting,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _nm_setting_aggregate:
|
||||||
|
* @setting: the #NMSetting to aggregate.
|
||||||
|
* @type: the #NMConnectionAggregateType aggregate type.
|
||||||
|
* @arg: the in/out arguments for aggregation. They depend on @type.
|
||||||
|
*
|
||||||
|
* This is the implementation detail of _nm_connection_aggregate(). It
|
||||||
|
* makes no sense to call this function directly outside of _nm_connection_aggregate().
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if afterwards the aggregation is complete. That means,
|
||||||
|
* the only caller _nm_connection_aggregate() will not visit other settings
|
||||||
|
* after a setting returns %TRUE (indicating that there is nothing further
|
||||||
|
* to aggregate). Note that is very different from the boolean return
|
||||||
|
* argument of _nm_connection_aggregate(), which serves a different purpose.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
_nm_setting_aggregate (NMSetting *setting,
|
||||||
|
NMConnectionAggregateType type,
|
||||||
|
gpointer arg)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (NM_IS_SETTING (setting), FALSE);
|
||||||
|
g_return_val_if_fail (arg, FALSE);
|
||||||
|
g_return_val_if_fail (NM_IN_SET (type, NM_CONNECTION_AGGREGATE_ANY_SECRETS,
|
||||||
|
NM_CONNECTION_AGGREGATE_ANY_SYSTEM_SECRET_FLAGS),
|
||||||
|
FALSE);
|
||||||
|
|
||||||
|
return NM_SETTING_GET_CLASS (setting)->aggregate (setting, type, arg);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
clear_secrets (const NMSettInfoSetting *sett_info,
|
clear_secrets (const NMSettInfoSetting *sett_info,
|
||||||
guint property_idx,
|
guint property_idx,
|
||||||
@@ -2622,6 +2631,7 @@ nm_setting_class_init (NMSettingClass *setting_class)
|
|||||||
setting_class->clear_secrets = clear_secrets;
|
setting_class->clear_secrets = clear_secrets;
|
||||||
setting_class->duplicate_copy_properties = duplicate_copy_properties;
|
setting_class->duplicate_copy_properties = duplicate_copy_properties;
|
||||||
setting_class->enumerate_values = enumerate_values;
|
setting_class->enumerate_values = enumerate_values;
|
||||||
|
setting_class->aggregate = aggregate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NMSetting:name:
|
* NMSetting:name:
|
||||||
|
@@ -247,11 +247,16 @@ typedef struct {
|
|||||||
NMSettingValueIterFn func,
|
NMSettingValueIterFn func,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
|
/*< private >*/
|
||||||
|
gboolean (*aggregate) (NMSetting *setting,
|
||||||
|
int type_i,
|
||||||
|
gpointer arg);
|
||||||
|
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
const struct _NMMetaSettingInfo *setting_info;
|
const struct _NMMetaSettingInfo *setting_info;
|
||||||
|
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
gpointer padding[4];
|
gpointer padding[3];
|
||||||
} NMSettingClass;
|
} NMSettingClass;
|
||||||
|
|
||||||
GType nm_setting_get_type (void);
|
GType nm_setting_get_type (void);
|
||||||
|
Reference in New Issue
Block a user