]> pilppa.com Git - lib1wire.git/commitdiff
configuration data related changes
authorMika Laitio <lamikr@pilppa.org>
Fri, 3 Aug 2012 15:44:58 +0000 (18:44 +0300)
committerMika Laitio <lamikr@pilppa.org>
Fri, 3 Aug 2012 15:44:58 +0000 (18:44 +0300)
Required due to api changes in libplp.

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
.project
src/Factory.cc
src/W1Device.cc
src/W1TemperatureSensor.cc
src_test/test_w1_datalog_read.cc
src_test/test_w1_datalog_write.cc

index c7ec9299e3868dec9a45f6c384352c3622813117..3b650c9289bca53f76e5fb6ef793d3c3e717b3ba 100644 (file)
--- a/.project
+++ b/.project
@@ -3,6 +3,7 @@
        <name>lib1wire</name>
        <comment></comment>
        <projects>
+               <project>libplp</project>
        </projects>
        <buildSpec>
                <buildCommand>
index bcd43ec09478daf1c9408894d12b2e515b5574f1..76f1a1381ec2e626e1b5a8b4081d3ac03dab2d17 100644 (file)
@@ -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<Device *> 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);
index 0ee589845d75ba9ae0ecdddb142cded40c3beebf..22f555960dad5d9a9e1e7de48fd8f9560fe83b52 100644 (file)
@@ -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);
                }
        }
index 152125a1d34672817f0910e4b59461c307d09dfd..5f954cfaa1403923fd58f639128510a2288ee33b 100644 (file)
@@ -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<double> *W1TemperatureSensor::get_raw_data() {
index f833af5caeda0346ad3600d893f3baee52b28c10..064831b4bc8c71432bd57b1e87294792e73effd3 100644 (file)
@@ -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;
index a0c0cc238ba707cc8400e4784da957130bd47f80..93acbd179c08f2aadd937ef89b8c6a4dd0b04bd2 100644 (file)
@@ -16,6 +16,8 @@
 #include <plp/DeviceConfig.hh>
 #include <plp/Device.hh>
 
+#include <plp/str_util.h>
+
 #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) {