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) {
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);
}
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;
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) {
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;