]> pilppa.org Git - lib1wire.git/blobdiff - src_test/test_w1_datalog_write.cc
Started adding support for caches when reading data. Cache files for
[lib1wire.git] / src_test / test_w1_datalog_write.cc
index 5b5e6eb8d80d2dbe135a52eadc11e4758a4c29d0..141031b50c35fe58134937c9085a633e77da3eb6 100644 (file)
@@ -13,8 +13,8 @@
 
 #include <plp/log.h>
 
-#include "W1Store.hh"
-#include "W1Scanner.hh"
+#include "DeviceConfig.hh"
+#include "Factory.hh"
 
 using namespace w1;
 using namespace std;
@@ -43,24 +43,24 @@ bool try_parse_long(const char *str, long *result) {
 }
 
 int main(int argc, char** argv) {
-       W1Scanner               *scanner;
-       list<W1Device *>        device_list;
-       int                     round;
-       long                    scan_interval;
-       long                    store_interval;
-       string                  location;
-       bool                    err_flg;
+       list<W1Device *>                device_list;
+       int                             round;
+       long                            scan_interval;
+       long                            store_interval;
+       string                          loc;
+       W1Device                        *device;
+       list<W1Device *>::iterator      iter;
 
        // default values than can be overwritten with parameters
-       location        = "/tmp/";
-       scan_interval   = 600;
-       store_interval  = 6;
+       loc     = "/tmp/w1data";
+       scan_interval   = 600; //600;
+       store_interval  = 2;
        if (argc > 1) {
-               location        = argv[1];
-               log_info("storage location: %s\n", location.c_str());
+               loc     = argv[1];
+               log_info("storage location: %s\n", loc.c_str());
        }
        else {
-               log_warning("No storage location parameter given, using default location: %s\n", location.c_str());
+               log_warning("No storage location parameter given, using default location: %s\n", loc.c_str());
        }
        if (argc > 2) {
                try_parse_long(argv[2], &scan_interval);
@@ -68,31 +68,36 @@ int main(int argc, char** argv) {
        if (argc > 3) {
                try_parse_long(argv[3], &store_interval);
        }
-       log_info("start scanning, data saved to location: %s, scan interval: %d, store interval: %d\n", location.c_str(), scan_interval, store_interval);
-       W1Store::set_location_base_dir(location.c_str());
-       scanner         = new W1Scanner();
-       device_list     = scanner->get_device_list();
+       log_info("scanning 1-wire devices\n");
+       log_info("data save dir: %s, scan interval: %ld, save interval: %ld\n", loc.c_str(), scan_interval, store_interval);
+       DeviceConfig::set_base_dir_name(loc);
+       device_list     = Factory::get_device_list();
        round           = 0;
        if (device_list.size() > 0) {
                while(1) {
                        round++;
-                       for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++) {
-                               W1Device *device = (W1Device *)*list_iter;
-
+                       for(iter = device_list.begin(); iter != device_list.end(); iter++) {
+                               device = (W1Device *)*iter;
                                device->printout();
                                sleep(1);
                                if (round >= store_interval) {
-                                       device->store();
+                                       device->save_data();
                                }
                        }
                        sleep(scan_interval);
                        if (round >= store_interval) {
                                round = 0;
+                               break;
                        }
                }
        }
        else {
                log_debug("could not find 1-wire devices.\n");
        }
+       while (device_list.empty() == false) {
+               device  = device_list.back();
+               device_list.pop_back();
+               delete(device);
+       }
        return 0;
 }