Skip to content
Permalink
Browse files
[config] Clean-up and add function to check for value changes
Add a function to check if a new value is changed or not.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed May 27, 2015
1 parent de9faa9 commit 7033527f6e48195ed5c9ad73f57f57b9b2cf20f7
Showing with 30 additions and 17 deletions.
  1. +27 −16 src/usb_moded-config.c
  2. +2 −0 src/usb_moded-config.h
  3. +1 −1 src/usb_moded-dbus.h
@@ -330,6 +330,29 @@ char * get_mode_setting(void)

return(get_conf_string(MODE_SETTING_ENTRY, MODE_SETTING_KEY));
}
/*
* @param settingsfile: already opened settingsfile we want to read an entry from
* @param entry: entry we want to read
* @param key: key value of the entry we want to read
* @new_value: potentially new value we want to compare against
*
* @return: 1 when the old value is the same as the new one, 0 otherwise
*/
int config_value_changed(GKeyFile *settingsfile, const char *entry, const char *key, const char *new_value)
{
char *old = g_key_file_get_string(settingsfile, entry, key, NULL);
if (old)
{
gboolean unchanged = (g_strcmp0(old, entry) == 0);
g_free(old);
if (unchanged)
{
return 1;
}
}

return 0;
}

set_config_result_t set_config_setting(const char *entry, const char *key, const char *value)
{
@@ -342,16 +365,10 @@ set_config_result_t set_config_setting(const char *entry, const char *key, const
test = g_key_file_load_from_file(settingsfile, FS_MOUNT_CONFIG_FILE, G_KEY_FILE_NONE, NULL);
if(test)
{
char *old = g_key_file_get_string(settingsfile, entry, key, NULL);
if (old)
if(config_value_changed(settingsfile, entry, key, value))
{
gboolean unchanged = (g_strcmp0(old, value) == 0);
g_free(old);
if (unchanged)
{
g_key_file_free(settingsfile);
return SET_CONFIG_UNCHANGED;
}
}
}
else
@@ -400,16 +417,10 @@ set_config_result_t set_network_setting(const char *config, const char *setting)
set_config_result_t ret = SET_CONFIG_ERROR;
if (test)
{
char *old = g_key_file_get_string(settingsfile, NETWORK_ENTRY, config, NULL);
if (old)
if(config_value_changed(settingsfile, NETWORK_ENTRY, config, setting))
{
gboolean unchanged = (g_strcmp0(old, setting) == 0);
g_free(old);
if (unchanged)
{
g_key_file_free(settingsfile);
return SET_CONFIG_UNCHANGED;
}
g_key_file_free(settingsfile);
return SET_CONFIG_UNCHANGED;
}
}
else
@@ -91,6 +91,8 @@ typedef enum set_config_result_t {
} set_config_result_t;

int conf_file_merge(void);

int config_value_changed(GKeyFile *settingsfile, const char *entry, const char *key, const char *new_value);
set_config_result_t set_config_setting(const char *entry, const char *key, const char *value);

#define SET_CONFIG_OK(ret) ((ret) >= SET_CONFIG_UPDATED)
@@ -2,7 +2,7 @@
Copyright (C) 2010 Nokia Corporation. All rights reserved.
Copyright (C) 2012-2015 Jolla. All rights reserved.
Author: Philippe De Swert <philippe.de-swert@meego.com>
Author: Philippe De Swert <philippedeswert@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License

0 comments on commit 7033527

Please sign in to comment.