X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=src%2FDeviceConfig.cc;h=066a22ca838a359c7698509da5eab8ff8367c29b;hb=d01194ab9275bc97176071089edc2781bb4de51b;hp=f94637cca7ab5b3e716a7d33eebfec2426cbaa0d;hpb=56242039f27dc5d36117b8d513731c7a9009d4b1;p=lib1wire.git diff --git a/src/DeviceConfig.cc b/src/DeviceConfig.cc index f94637c..066a22c 100644 --- a/src/DeviceConfig.cc +++ b/src/DeviceConfig.cc @@ -22,13 +22,13 @@ using namespace w1; string DeviceConfig::store_base_dir = DEFAULT_STORAGE_BASE_DIR; ConfigHandle::ConfigHandle(uci_context *ctx_param, uci_package *pkg_param) { - ctx = ctx_param; - pkg = pkg_param; + _ctx = ctx_param; + _pkg = pkg_param; } ConfigHandle::~ConfigHandle() { - uci_unload(ctx, pkg); - uci_free_context(ctx); + uci_unload(_ctx, _pkg); + uci_free_context(_ctx); } DeviceConfig::DeviceConfig(string device_id_param) { @@ -92,9 +92,9 @@ string DeviceConfig::get_cfg_value(string key) { string ret_val; if (uci_handle != NULL) { - section = uci_lookup_section(uci_handle->ctx, uci_handle->pkg, DEVICE_CONFIG__SECTION_NAME); + section = uci_lookup_section(uci_handle->_ctx, uci_handle->_pkg, DEVICE_CONFIG__SECTION_NAME); if (section != NULL) { - option = uci_lookup_option(uci_handle->ctx, section, key.c_str()); + option = uci_lookup_option(uci_handle->_ctx, section, key.c_str()); switch (option->type) { case UCI_TYPE_STRING: log_info("key: %s option name: %s, value: %s\n", key.c_str(), option->e.name, option->v.string); @@ -110,8 +110,8 @@ string DeviceConfig::get_cfg_value(string key) { } void DeviceConfig::set_cfg_value(string key, string value) { - string cfg_dir; - string cfg_fl; + string cfg_dir; + string cfg_fl; cfg_dir = get_dir_name(device_id); cfg_fl = DEVICE_CONFIG__FILE_NAME; @@ -123,8 +123,8 @@ void DeviceConfig::set_cfg_value(string key, string value) { value.c_str()); } -enum_summary_calculation DeviceConfig::get_summary_calculation_type() { - enum_summary_calculation ret_val; +EnumSummaryCalculationType DeviceConfig::get_summary_calculation_type() { + EnumSummaryCalculationType ret_val; ret_val = MEAN; if (device_type.empty() == false) { @@ -150,27 +150,29 @@ ConfigHandle *DeviceConfig::load_device_config(string device_id_param) { W1Util::mkdirs(cfg_dir.c_str()); } cfg_fl = get_file_name(device_id_param); - ctx = uci_alloc_context(); - if (ctx != NULL) { - log_debug("uci_set_confdir: %s\n", cfg_dir.c_str()); - uci_set_confdir(ctx, cfg_dir.c_str()); - if (access(cfg_fl.c_str(), R_OK) == 0) { + if (access(cfg_fl.c_str(), R_OK) == 0) { + ctx = uci_alloc_context(); + if (ctx != NULL) { + log_debug("uci_set_confdir: %s\n", cfg_dir.c_str()); + uci_set_confdir(ctx, cfg_dir.c_str()); err_flg = uci_load(ctx, cfg_fl.c_str(), &pkg); if (err_flg == UCI_OK) { - log_debug("Loaded device configuration file: %s\n.", cfg_fl.c_str()); + log_debug("Loaded device configuration: %s\n.", cfg_fl.c_str()); ret_val = new ConfigHandle(ctx, pkg); } else { - log_debug("Failed to load file: %s, err code: %d\n.", cfg_fl.c_str(), UCI_OK); + 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, ""); + uci_free_context(ctx); } } else { - log_error("Failed to load device device configuration, file does not exit: %s.\n", cfg_fl.c_str()); + log_error("Failed to load device device configuration, memory allocation error.\n"); + set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, ""); } } else { - log_error("Failed to load device device configuration, invalid device id: %s.\n", cfg_dir.c_str()); + log_error("Failed to load device device configuration, file does not exist: %s.\n", cfg_fl.c_str()); } } return ret_val;