X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=src_test%2Ftest_w1_datalog_write.cc;h=93acbd179c08f2aadd937ef89b8c6a4dd0b04bd2;hb=9e569babf7e271015fedac3b7153d9035ff17ee0;hp=748b9fe29ea2eb14f4b65e648405dd432a5b16a3;hpb=14ca6b205211e856c924f88dff3abf0584b1e414;p=lib1wire.git diff --git a/src_test/test_w1_datalog_write.cc b/src_test/test_w1_datalog_write.cc index 748b9fe..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,36 +27,13 @@ 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) { - list device_list; int read_count_total; long cnt_max_scans; long read_interval_seconds; string loc; Device *device; + list device_list; list::iterator iter; // default values than can be overwritten with parameters @@ -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) { @@ -101,7 +80,7 @@ int main(int argc, char** argv) { log_info("closing the application, max read count reached. (%ld)\n", cnt_max_scans); break; } - for(iter = device_list.begin(); iter != device_list.end(); iter++) { + for (iter = device_list.begin(); iter != device_list.end(); iter++) { device = (Device *)*iter; if (device->get_lifecycle_state() == LIFECYCLE_STATUS__AVAILABLE) { device->printout(); @@ -115,7 +94,7 @@ int main(int argc, char** argv) { } } else { - log_debug("could not find 1-wire devices.\n"); + log_debug("could not find devices.\n"); } log_debug("trying to start emptying list\n"); while (device_list.empty() == false) {