]> pilppa.org Git - lib1wire.git/blobdiff - src/DeviceConfig.cc
Refactoring and fixes.
[lib1wire.git] / src / DeviceConfig.cc
index ee06135a4270cc4594c0a2d6770a5ae18775c87b..f94637cca7ab5b3e716a7d33eebfec2426cbaa0d 100644 (file)
@@ -97,11 +97,11 @@ string DeviceConfig::get_cfg_value(string key) {
                        option  = uci_lookup_option(uci_handle->ctx, section, key.c_str());
                        switch (option->type) {
                                case UCI_TYPE_STRING:
-                                       log_info("config file: key: %s option name: %s, value: %s\n", key.c_str(), option->e.name, option->v.string);
+                                       log_info("key: %s option name: %s, value: %s\n", key.c_str(), option->e.name, option->v.string);
                                        ret_val = option->v.string;
                                        break;
                                default:
-                                       log_error("config file: key: %s can not parse parameter value\n", key.c_str());
+                                       log_error("key: %s Failed to read parameter value\n", key.c_str());
                                        break;
                        }
                }
@@ -115,7 +115,6 @@ void DeviceConfig::set_cfg_value(string key, string value) {
 
        cfg_dir = get_dir_name(device_id);
        cfg_fl  = DEVICE_CONFIG__FILE_NAME;
-
        set_config_value(cfg_dir.c_str(),
                        cfg_fl.c_str(),
                        DEVICE_CONFIG__SECTION_TYPE,
@@ -129,7 +128,7 @@ enum_summary_calculation DeviceConfig::get_summary_calculation_type() {
 
        ret_val = MEAN;
        if (device_type.empty() == false) {
-               if (device_type.compare("counter") == 0) {
+               if (device_type.compare("Counter Device") == 0) {
                        ret_val = DELTA;
                }
        }
@@ -147,26 +146,31 @@ ConfigHandle *DeviceConfig::load_device_config(string device_id_param) {
        ret_val = NULL;
        cfg_dir = get_dir_name(device_id_param);
        if (cfg_dir.empty() == false) {
+               if (access(cfg_dir.c_str(), W_OK) != 0) {
+                       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) {
-                               log_debug("loading file: %s\n", cfg_fl.c_str());
+                       if (access(cfg_fl.c_str(), R_OK) == 0) {
                                err_flg = uci_load(ctx, cfg_fl.c_str(), &pkg);
                                if (err_flg == UCI_OK) {
-                                       log_debug("Loaded device configuration: %s, UCI_OK: %d, err flg: %d\n.", cfg_fl.c_str(), UCI_OK, err_flg);
+                                       log_debug("Loaded device configuration file: %s\n.", cfg_fl.c_str());
                                        ret_val = new ConfigHandle(ctx, pkg);
                                }
                                else {
-                                       log_debug("Failed to load file: %s, UCI_OK: %d, err flg: %d\n.", cfg_fl.c_str(), UCI_OK, err_flg);
-                                       set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, "unknowntype");
+                                       log_debug("Failed to load file: %s, err code: %d\n.", cfg_fl.c_str(), UCI_OK);
+                                       set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, "");
                                }
                        }
+                       else {
+                               log_error("Failed to load device device configuration, file does not exit: %s.\n", cfg_fl.c_str());
+                       }
                }
                else {
-                       log_error("Failed to load device device configurations, invalid device id: %s.\n", cfg_dir.c_str());
+                       log_error("Failed to load device device configuration, invalid device id: %s.\n", cfg_dir.c_str());
                }
        }
        return ret_val;