config: add new function nm_config_data_diff()

This commit is contained in:
Thomas Haller
2015-01-07 14:30:14 +01:00
parent 56f5fba723
commit 045a576a7a
3 changed files with 34 additions and 20 deletions

View File

@@ -21,6 +21,8 @@
#include "nm-config-data.h"
#include "nm-config.h"
typedef struct {
char *config_main_file;
char *config_description;
@@ -91,6 +93,34 @@ nm_config_data_get_connectivity_response (const NMConfigData *self)
}
/************************************************************************/
GHashTable *
nm_config_data_diff (NMConfigData *old_data, NMConfigData *new_data)
{
GHashTable *changes;
g_return_val_if_fail (NM_IS_CONFIG_DATA (old_data), NULL);
g_return_val_if_fail (NM_IS_CONFIG_DATA (new_data), NULL);
changes = g_hash_table_new (g_str_hash, g_str_equal);
if ( g_strcmp0 (nm_config_data_get_config_main_file (old_data), nm_config_data_get_config_main_file (new_data)) != 0
|| g_strcmp0 (nm_config_data_get_config_description (old_data), nm_config_data_get_config_description (new_data)) != 0)
g_hash_table_insert (changes, NM_CONFIG_CHANGES_CONFIG_FILES, NULL);
if ( nm_config_data_get_connectivity_interval (old_data) != nm_config_data_get_connectivity_interval (new_data)
|| g_strcmp0 (nm_config_data_get_connectivity_uri (old_data), nm_config_data_get_connectivity_uri (new_data))
|| g_strcmp0 (nm_config_data_get_connectivity_response (old_data), nm_config_data_get_connectivity_response (new_data)))
g_hash_table_insert (changes, NM_CONFIG_CHANGES_CONNECTIVITY, NULL);
if (!g_hash_table_size (changes)) {
g_hash_table_destroy (changes);
return NULL;
}
return changes;
}
/************************************************************************/
static void

View File

@@ -56,6 +56,8 @@ NMConfigData *nm_config_data_new (const char *config_main_file,
const char *config_description,
GKeyFile *keyfile);
GHashTable *nm_config_data_diff (NMConfigData *old_data, NMConfigData *new_data);
const char *nm_config_data_get_config_main_file (const NMConfigData *config_data);
const char *nm_config_data_get_config_description (const NMConfigData *config_data);

View File

@@ -721,28 +721,10 @@ nm_config_reload (NMConfig *self)
g_free (config_description);
g_key_file_free (keyfile);
changes = g_hash_table_new (g_str_hash, g_str_equal);
/* reloading configuration means we have to carefully check every single option
* that we want to support and take specific actions. */
old_data = priv->config_data;
if ( nm_config_data_get_connectivity_interval (old_data) != nm_config_data_get_connectivity_interval (new_data)
|| g_strcmp0 (nm_config_data_get_connectivity_uri (old_data), nm_config_data_get_connectivity_uri (new_data))
|| g_strcmp0 (nm_config_data_get_connectivity_response (old_data), nm_config_data_get_connectivity_response (new_data))) {
nm_log_dbg (LOGD_CORE, "config: reload: change '" NM_CONFIG_CHANGES_CONNECTIVITY "'");
g_hash_table_insert (changes, NM_CONFIG_CHANGES_CONNECTIVITY, NULL);
}
changes = nm_config_data_diff (old_data, new_data);
if ( g_strcmp0 (nm_config_data_get_config_main_file (old_data), nm_config_data_get_config_main_file (new_data)) != 0
|| g_strcmp0 (nm_config_data_get_config_description (old_data), nm_config_data_get_config_description (new_data)) != 0) {
nm_log_dbg (LOGD_CORE, "config: reload: change '" NM_CONFIG_CHANGES_CONFIG_FILES "'");
g_hash_table_insert (changes, NM_CONFIG_CHANGES_CONFIG_FILES, NULL);
}
if (!g_hash_table_size (changes)) {
g_hash_table_destroy (changes);
if (!changes) {
g_object_unref (new_data);
return;
}