From: Mika Laitio Date: Fri, 3 Aug 2012 15:44:58 +0000 (+0300) Subject: configuration data related changes X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=9e569babf7e271015fedac3b7153d9035ff17ee0;p=lib1wire.git configuration data related changes Required due to api changes in libplp. Signed-off-by: Mika Laitio --- diff --git a/.project b/.project index c7ec929..3b650c9 100644 --- a/.project +++ b/.project @@ -3,6 +3,7 @@ lib1wire + libplp diff --git a/src/Factory.cc b/src/Factory.cc index bcd43ec..76f1a13 100644 --- a/src/Factory.cc +++ b/src/Factory.cc @@ -101,6 +101,7 @@ Device *Factory::create_device(int device_w1_family_code_param, dirent *direntry_param) { Device *ret_val; DeviceConfig *config; + bool succ; ret_val = NULL; if (device_type_param.empty() == false) { @@ -124,11 +125,11 @@ Device *Factory::create_device(int device_w1_family_code_param, config = DeviceConfig::get_device_config(device_id_param); if (config != NULL) { // if not, create default device config - device_type_param = config->get_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE); - if (device_type_param.empty() == true) { + succ = config->get_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE, device_type_param); + if (succ == false) { device_type_param = ret_val->get_type(); - config->set_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE, device_type_param); - config->set_config_value(DEVICE_CONFIG_VALUE_KEY__ID, ret_val->get_id()); + config->set_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE, device_type_param, false); + config->set_config_value(DEVICE_CONFIG_VALUE_KEY__ID, ret_val->get_id(), true); } delete(config); } @@ -246,8 +247,8 @@ list Factory::get_device_list() { } if (found == false) { // reader device is not in the list of active devices. create and add it to list as in-active one... - type = reader->get_device_type(); - if (type.empty() == false) { + found = reader->get_device_type(type); + if (found == true) { device = create_device(type, id1); if (device != NULL) { ret_val.push_back(device); diff --git a/src/W1Device.cc b/src/W1Device.cc index 0ee5898..22f5559 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -62,7 +62,7 @@ string W1Device::get_name() { if (name.empty() == true) { cfg = DeviceConfig::get_device_config(id); if (cfg != NULL) { - name = cfg->get_config_value(DEVICE_CONFIG_VALUE_KEY__NAME); + cfg->get_config_value(DEVICE_CONFIG_VALUE_KEY__NAME, name); delete(cfg); } } @@ -76,7 +76,7 @@ void W1Device::set_name(string name_param) { name = name_param; cfg = DeviceConfig::get_device_config(id); if (cfg != NULL) { - cfg->set_config_value(DEVICE_CONFIG_VALUE_KEY__NAME, name_param); + cfg->set_config_value(DEVICE_CONFIG_VALUE_KEY__NAME, name_param, true); delete(cfg); } } diff --git a/src/W1TemperatureSensor.cc b/src/W1TemperatureSensor.cc index 152125a..5f954cf 100644 --- a/src/W1TemperatureSensor.cc +++ b/src/W1TemperatureSensor.cc @@ -44,7 +44,7 @@ double convert_w1_temperature_to_celcius(string raw_value, */ } else { - log_error("Failed to convert temperature %s to celsius value", raw_value.c_str()); + log_error("Failed to convert temperature %s to celcius value.", raw_value.c_str()); *err_flg = 1; } return dbl_val; @@ -62,7 +62,7 @@ W1TemperatureSensor::W1TemperatureSensor(string device_id_param, } W1TemperatureSensor::~W1TemperatureSensor() { - log_debug("W1TemperatureSensor destructor\n"); + log_debug("destructor\n"); } vector *W1TemperatureSensor::get_raw_data() { diff --git a/src_test/test_w1_datalog_read.cc b/src_test/test_w1_datalog_read.cc index f833af5..064831b 100644 --- a/src_test/test_w1_datalog_read.cc +++ b/src_test/test_w1_datalog_read.cc @@ -24,29 +24,6 @@ using namespace std; using namespace plp; using namespace w1; -bool try_parse_long(const char *str, long *result) { - int new_result; - char *endptr; - bool ret_val; - - ret_val = false; - errno = 0; - new_result = strtol(str, &endptr, 10); - if (errno != 0) { - log_error("invalid input %s, could not convert to integer.\n", str); - } - else { - if (endptr == str) { - log_error("invalid input %s, could not convert to integer.\n", str); - } - else { - *result = new_result; - ret_val = true; - } - } - return ret_val; -} - int main(int argc, char** argv) { string loc; Data *fdata; diff --git a/src_test/test_w1_datalog_write.cc b/src_test/test_w1_datalog_write.cc index a0c0cc2..93acbd1 100644 --- a/src_test/test_w1_datalog_write.cc +++ b/src_test/test_w1_datalog_write.cc @@ -16,6 +16,8 @@ #include #include +#include + #include "Factory.hh" using namespace w1; @@ -25,29 +27,6 @@ using namespace plp; #define DEFAULT_READ_INTERVAL_SECONDS 600 #define DEFAULT_MAX_READ_COUNT -1 -bool try_parse_long(const char *str, long *result) { - int new_result; - char *endptr; - bool ret_val; - - ret_val = false; - errno = 0; - new_result = strtol(str, &endptr, 10); - if (errno != 0) { - log_error("invalid input %s, could not convert to integer.\n", str); - } - else { - if (endptr == str) { - log_error("invalid input %s, could not convert to integer.\n", str); - } - else { - *result = new_result; - ret_val = true; - } - } - return ret_val; -} - int main(int argc, char** argv) { int read_count_total; long cnt_max_scans; @@ -71,10 +50,10 @@ int main(int argc, char** argv) { log_info("\tmax_read_count == -1: read devices until application is terminated\n\n"); } if (argc > 2) { - try_parse_long(argv[2], &read_interval_seconds); + parse_long(argv[2], &read_interval_seconds); } if (argc > 3) { - try_parse_long(argv[3], &cnt_max_scans); + parse_long(argv[3], &cnt_max_scans); } log_info("searching 1-wire devices\n"); if (read_interval_seconds == DEFAULT_READ_INTERVAL_SECONDS) {