libnm-util: simplify nm_connection_for_each_setting_value()

And use less memory as a bonus.
This commit is contained in:
Dan Williams 2011-01-31 21:53:16 -06:00
parent ac757766e6
commit c4ada67108
2 changed files with 7 additions and 30 deletions

View file

@ -850,19 +850,6 @@ nm_connection_to_hash (NMConnection *connection, NMSettingHashFlags flags)
return ret;
}
typedef struct ForEachValueInfo {
NMSettingValueIterFn func;
gpointer user_data;
} ForEachValueInfo;
static void
for_each_setting (gpointer key, gpointer value, gpointer user_data)
{
ForEachValueInfo *info = (ForEachValueInfo *) user_data;
nm_setting_enumerate_values (NM_SETTING (value), info->func, info->user_data);
}
/**
* nm_connection_for_each_setting_value:
* @connection: the #NMConnection
@ -877,25 +864,15 @@ nm_connection_for_each_setting_value (NMConnection *connection,
NMSettingValueIterFn func,
gpointer user_data)
{
NMConnectionPrivate *priv;
ForEachValueInfo *info;
GHashTableIter iter;
gpointer value;
g_return_if_fail (NM_IS_CONNECTION (connection));
g_return_if_fail (func != NULL);
priv = NM_CONNECTION_GET_PRIVATE (connection);
info = g_slice_new0 (ForEachValueInfo);
if (!info) {
g_warning ("Not enough memory to enumerate values.");
return;
}
info->func = func;
info->user_data = user_data;
g_hash_table_foreach (priv->settings, for_each_setting, info);
g_slice_free (ForEachValueInfo, info);
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
while (g_hash_table_iter_next (&iter, NULL, &value))
nm_setting_enumerate_values (NM_SETTING (value), func, user_data);
}
static void

View file

@ -127,8 +127,8 @@ void nm_connection_set_path (NMConnection *connection,
const char * nm_connection_get_path (NMConnection *connection);
void nm_connection_for_each_setting_value (NMConnection *connection,
NMSettingValueIterFn func,
gpointer user_data);
NMSettingValueIterFn func,
gpointer user_data);
GHashTable *nm_connection_to_hash (NMConnection *connection,
NMSettingHashFlags flags);