#include "DeviceConfig.hh"
+#include <stdbool.h>
#include <string.h>
#include <malloc.h>
device_id = device_id_param;
uci_handle = load_device_config(device_id_param);
if (uci_handle != NULL) {
- device_type = get_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE);
+ device_type = get_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE);
}
else {
log_error("Could not read device configuration.\n");
return ret_val;
}
-string DeviceConfig::get_cfg_value(string key) {
+string DeviceConfig::get_config_value(string key) {
struct uci_section *section;
struct uci_option *option;
string ret_val;
return ret_val;
}
-void DeviceConfig::set_cfg_value(string key, string value) {
+void DeviceConfig::set_config_value(string key,
+ string value,
+ bool save_immediately) {
string cfg_dir;
string cfg_fl;
cfg_dir = get_dir_name(device_id);
cfg_fl = DEVICE_CONFIG__FILE_NAME;
- set_config_value(cfg_dir.c_str(),
+ set_config_value_to_section(cfg_dir.c_str(),
cfg_fl.c_str(),
DEVICE_CONFIG__SECTION_TYPE,
DEVICE_CONFIG__SECTION_NAME,
key.c_str(),
- value.c_str());
+ value.c_str(),
+ save_immediately);
}
EnumSummaryCalculationType DeviceConfig::get_summary_calculation_type() {
}
else {
log_debug("Failed to load device configuration: %s, err code: %d.\n", cfg_fl.c_str(), UCI_OK);
- set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, "");
+ set_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE, "", true);
uci_free_context(ctx);
}
}
else {
log_error("Failed to load device device configuration, memory allocation error.\n");
- set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, "");
+ set_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE, "", true);
}
}
else {