]> pilppa.org Git - lib1wire.git/commitdiff
Support for querying the list devices having data stored.
authorMika Laitio <lamikr@pilppa.org>
Sun, 26 Dec 2010 13:41:23 +0000 (15:41 +0200)
committerMika Laitio <lamikr@pilppa.org>
Sun, 26 Dec 2010 13:41:23 +0000 (15:41 +0200)
Also refactored the code, removed W1Scanner and moved that functionality
to Factory.hh

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
14 files changed:
configure.ac
src/DeviceConfig.cc
src/DeviceData.cc [moved from src/W1DataList.cc with 90% similarity]
src/DeviceData.hh [moved from src/W1DataList.hh with 91% similarity]
src/Factory.cc
src/Factory.hh
src/Makefile.am
src/W1Scanner.cc [deleted file]
src/W1Scanner.hh [deleted file]
src/W1Store.cc
src/W1Util.cc
src/W1Util.hh
src_test/test_w1_datalog_read.cc
src_test/test_w1_datalog_write.cc

index a8fc4c7bdebec27ea49e88c49b6e29fba6be99f0..327399b8933a4039c6555c339c8f190c7d916e84 100644 (file)
@@ -1,4 +1,4 @@
-AC_INIT(src/W1Scanner.cc)
+AC_INIT(src/Data.cc)
 AM_CONFIG_HEADER(config.h)
 AC_CONFIG_MACRO_DIR([m4])
 
index ee06135a4270cc4594c0a2d6770a5ae18775c87b..f9e8f72684747cee8057c848ca8a42b6f3ec7867 100644 (file)
@@ -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,
@@ -147,12 +146,15 @@ 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) {
+                       if (access(cfg_fl.c_str(), R_OK) == 0) {
                                log_debug("loading file: %s\n", cfg_fl.c_str());
                                err_flg = uci_load(ctx, cfg_fl.c_str(), &pkg);
                                if (err_flg == UCI_OK) {
@@ -164,9 +166,12 @@ ConfigHandle *DeviceConfig::load_device_config(string device_id_param) {
                                        set_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE, "unknowntype");
                                }
                        }
+                       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;
similarity index 90%
rename from src/W1DataList.cc
rename to src/DeviceData.cc
index 9f2674f0971b35b328fcb56f74272212fd0427f8..259d821ae38310cebc583baeab048c4e637af82c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * W1DataList.cc
+ * DeviceData.cc
  *
  *  Created on: Nov 7, 2010
  *      Author: lamikr
 #include <string.h>
 
 #include "W1Util.hh"
-#include "W1DataList.hh"
+#include "DeviceData.hh"
 #include "W1Store.hh"
 #include "DeviceConfig.hh"
+#include "Factory.hh"
 
 #include "plp/log.h"
 
@@ -20,10 +21,10 @@ using namespace w1;
 using namespace std;
 using namespace plp;
 
-W1DataList::W1DataList(string device_id_param) {
+DeviceData::DeviceData(string device_id_param) {
        string          base_dir;
 
-       device_config           = new DeviceConfig(device_id_param);
+       device_config           = Factory::get_device_config(device_id_param);
        summary_calc_type       = device_config->get_summary_calculation_type();
        device_id               = device_id_param;
        base_dir                = DeviceConfig::get_base_dir_name();
@@ -32,11 +33,11 @@ W1DataList::W1DataList(string device_id_param) {
        device_ch_dir           = W1Util::concat_paths(device_ch_dir, device_id);
 }
 
-W1DataList::~W1DataList() {
+DeviceData::~DeviceData() {
        delete(device_config);
 }
 
-Data *W1DataList::find_oldest_data(vector<string> year_vector) {
+Data *DeviceData::find_oldest_data(vector<string> year_vector) {
        unsigned int    ii;
        string          year_dir;
        string          month_dir;
@@ -70,7 +71,7 @@ Data *W1DataList::find_oldest_data(vector<string> year_vector) {
        return ret_val;
 }
 
-Data *W1DataList::find_newest_data(vector<string> year_vector) {
+Data *DeviceData::find_newest_data(vector<string> year_vector) {
        int             ii;
        string          year_dir;
        string          month_dir;
@@ -107,7 +108,7 @@ Data *W1DataList::find_newest_data(vector<string> year_vector) {
        return ret_val;
 }
 
-DataRange *W1DataList::get_data_range() {
+DataRange *DeviceData::get_data_range() {
        DataRange       *ret_val;
        vector<string>  year_list;
        Data            *first_data;
@@ -168,7 +169,7 @@ long int get_interval_type(Date *start_date,
        return ret_val;
 }
 
-Data *W1DataList::get_daily_summary(Date *date) {
+Data *DeviceData::get_daily_summary(Date *date) {
        Data    *ret_val;
        W1Store *store;
 
@@ -198,7 +199,7 @@ Data *W1DataList::get_daily_summary(Date *date) {
        return ret_val;
 }
 
-DataRange *W1DataList::get_daily_summary(Date *start_date,
+DataRange *DeviceData::get_daily_summary(Date *start_date,
                                        Date *end_date) {
        DataRange       *ret_val;
        Data            *data;
@@ -221,7 +222,7 @@ DataRange *W1DataList::get_daily_summary(Date *start_date,
        return ret_val;
 }
 
-DataRange *W1DataList::get_data(Date *start_date,
+DataRange *DeviceData::get_data(Date *start_date,
                                Date *end_date) {
        DataRange       *ret_val;
        int             int_type;
similarity index 91%
rename from src/W1DataList.hh
rename to src/DeviceData.hh
index 2d6ceda966dea44528193acff56572a2e9cc9d2c..33629714972c978b5ff3695430bdad3b7eb6bc56 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * W1DataList.hh
+ * DeviceData.hh
  *
  *  Created on: Nov 7, 2010
  *      Author: lamikr
 #include <time.h>
 
 namespace w1 {
-       class W1DataList {
+       class DeviceData {
                public:
-                       W1DataList(std::string device_id);
-                       virtual ~W1DataList();
+                       DeviceData(std::string device_id);
+                       virtual ~DeviceData();
                        DataRange *get_data_range();
                        /**
                         * Get summary data calculated from the daily data items that is meaning full.
index c81dbe198e3a37c4e423da65fa76611b34632fb6..8a09eaa9d0b22bd0f7a4e2fbb6c26505aca058ef 100644 (file)
@@ -5,14 +5,30 @@
  *      Author: lamikr
  */
 
+#include <string>
+#include <sstream>
+#include <iostream>
+
+#include <string.h>
+
 #include <plp/log.h>
 #include "Factory.hh"
 #include "W1TemperatureSensor.hh"
 #include "W1CounterDevice.hh"
+#include "W1Util.hh"
 
 using namespace w1;
 using namespace std;
 
+template <class NumberDataType>
+bool string_to_number(NumberDataType& result,
+                 const std::string& string_param,
+                 std::ios_base& (*format)(std::ios_base&))
+{
+       std::istringstream iss(string_param);
+       return !(iss >> format >> result).fail();
+}
+
 Factory::Factory() {
        // TODO Auto-generated constructor stub
 }
@@ -60,6 +76,101 @@ W1Device *Factory::get_device(int family_code,
        return ret_val;
 }
 
+W1Device *Factory::create_device(dirent *direntry_param) {
+       string          folder_name;
+       string          tmp_str;
+       string          device_name;
+       int             pos;
+       int             family_code;
+       bool            suc_flg;
+       W1Device        *ret_val;
+
+       ret_val         = NULL;
+       folder_name     = direntry_param->d_name;
+       pos             = folder_name.find("-");
+       if (pos > 0) {
+               tmp_str = folder_name.substr(0, pos);
+               // number in string is in hex format, convert to int
+               suc_flg = string_to_number<int>(family_code, tmp_str, hex);
+               if (suc_flg == true) {
+                       log_debug("family_code: %d\n", family_code);
+                       device_name     = folder_name.substr(pos + 1, folder_name.length() - pos);
+                       ret_val         = Factory::get_device(family_code,
+                                                       device_name,
+                                                       direntry_param);
+               }
+       }
+       return ret_val;
+}
+
+list<W1Device *> Factory::get_device_list() {
+       DIR                     *dir;
+       int                     err_flg;
+       struct dirent           *direntry;
+       W1Device                *device;
+       bool                    is_subdir;
+       list<W1Device *>        ret_val;
+
+       printf("get_device_list() started\n");
+       dir     = opendir(W1_SCAN_ROOTDIR);
+       if (dir != NULL) {
+               direntry        = readdir(dir);
+               while(direntry != NULL) {
+                       is_subdir       = W1Util::is_subdirectory(W1_SCAN_ROOTDIR, direntry);
+                       if (is_subdir == true) {
+                               log_info("dir_name: %s\n", direntry->d_name);
+                               device  = create_device(direntry);
+                               if (device != NULL) {
+                                       log_info("device: %d\n", device->get_family_code());
+                                       ret_val.push_back(device);
+                               }
+                               else {
+                                       log_info("unsupported device-directory: %s\n", direntry->d_name);
+                               }
+                       }
+                       direntry        = readdir(dir);
+               }
+               err_flg = closedir(dir);
+               if (err_flg < 0) {
+                       log_error("failed to close 1-wire device directory: %s\n", W1_SCAN_ROOTDIR);
+               }
+       }
+       return ret_val;
+}
+
+list<DeviceData *> Factory::get_device_data_list() {
+       DIR                     *dir;
+       string                  dr_name;
+       int                     err_flg;
+       struct dirent           *direntry;
+       DeviceData              *dev_dta;
+       bool                    is_subdir;
+       list<DeviceData *>      ret_val;
+
+       printf("get_device_list() started\n");
+       dr_name = DeviceConfig::get_base_dir_name();
+       dir     = opendir(dr_name.c_str());
+       if (dir != NULL) {
+               direntry        = readdir(dir);
+               while(direntry != NULL) {
+                       if (strcmp(direntry->d_name, "cache") != 0) {
+                               is_subdir       = W1Util::is_subdirectory(dr_name.c_str(), direntry);
+                               if (is_subdir == true) {
+                                       dev_dta = new DeviceData(direntry->d_name);
+                                       log_info("dir_name: %s\n", direntry->d_name);
+                                       ret_val.push_back(dev_dta);
+                               }
+                       }
+                       direntry        = readdir(dir);
+               }
+               err_flg = closedir(dir);
+               if (err_flg < 0) {
+                       log_error("failed to close 1-wire device data directory: %s\n", dr_name.c_str());
+               }
+       }
+       return ret_val;
+}
+
 DeviceConfig *Factory::get_device_config(string device_id) {
        DeviceConfig    *ret_val;
 
index 595e271e1b9a717e637bff9c6ce611bd2e3c40fc..a5cf254c31f60c4ae958ebc00f584948c7778ad9 100644 (file)
 #include <dirent.h>
 
 #include "DeviceConfig.hh"
+#include "DeviceData.hh"
 #include "W1Device.hh"
 
+#ifndef W1_SCAN_ROOTDIR
+       #define W1_SCAN_ROOTDIR         "/sys/bus/w1/devices"
+#endif
+
 namespace w1 {
        class Factory {
                public:
                        Factory();
                        virtual ~Factory();
                        static W1Device *get_device(int family_code, std::string device_id, dirent *direntry_param);
+                       static std::list<W1Device *> get_device_list();
+                       static std::list<DeviceData *> get_device_data_list();
                        static DeviceConfig *get_device_config(std::string device_id);
+               private:
+                       //int parse_family_code(std::string folder_name);
+                       static W1Device *create_device(dirent *direntry_param);
        };
 }
 
index 67a7a4b5df7eb6c6769785fc5fac7638c85b6a32..ec3ec8f3df385d4c4fb974cc08de8b2fff028302 100644 (file)
@@ -2,12 +2,11 @@ lib_LTLIBRARIES = lib1wire.la
 lib1wire_la_SOURCES = \
        Factory.cc Factory.hh \
        W1Device.cc W1Device.hh \
-       W1Scanner.cc W1Scanner.hh \
        W1Store.cc W1Store.hh \
        W1TemperatureSensor.cc W1TemperatureSensor.hh \
        W1CounterDevice.cc W1CounterDevice.hh \
        W1Util.cc W1Util.hh \
-       W1DataList.cc W1DataList.hh \
+       DeviceData.cc DeviceData.hh \
        DeviceConfig.cc DeviceConfig.hh \
        Data.cc Data.hh \
        Date.cc Date.hh \
@@ -19,9 +18,13 @@ DISTCLEANFILES = Makefile.in
 
 lib1wireincludedir=$(includedir)/w1
 lib1wireinclude_HEADERS = \
+       Data.hh \
+       Date.hh \
+       DeviceConfig.hh \
+       DeviceData.hh \
+       Factory.hh \
+       W1CounterDevice.hh \
        W1Device.hh \
-       W1Scanner.hh \
        W1Store.hh \
        W1TemperatureSensor.hh \
-       Date.hh \
-       W1CounterDevice.hh
\ No newline at end of file
+       W1Util.hh
\ No newline at end of file
diff --git a/src/W1Scanner.cc b/src/W1Scanner.cc
deleted file mode 100644 (file)
index d40108e..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * W1Scanner.cc
- *
- *  Created on: Oct 20, 2010
- *      Author: lamikr
- */
-
-#include <string.h>
-#include <malloc.h>
-
-#include <string>
-#include <sstream>
-#include <iostream>
-
-#include <plp/log.h>
-
-#include "W1Util.hh"
-#include "W1Scanner.hh"
-#include "W1TemperatureSensor.hh"
-#include "W1CounterDevice.hh"
-#include "Factory.hh"
-
-using namespace w1;
-using namespace std;
-
-template <class NumberDataType>
-bool string_to_number(NumberDataType& result,
-                 const std::string& string_param,
-                 std::ios_base& (*format)(std::ios_base&))
-{
-       std::istringstream iss(string_param);
-       return !(iss >> format >> result).fail();
-}
-
-W1Scanner::W1Scanner() {
-       log_debug("W1Scanner created\n");
-}
-
-W1Scanner::~W1Scanner() {
-}
-
-W1Device *W1Scanner::create_device(dirent *direntry_param) {
-       string          folder_name;
-       string          tmp_str;
-       string          device_name;
-       int             pos;
-       int             family_code;
-       bool            suc_flg;
-       W1Device        *ret_val;
-
-       ret_val         = NULL;
-       folder_name     = direntry_param->d_name;
-       pos             = folder_name.find("-");
-       if (pos > 0) {
-               tmp_str = folder_name.substr(0, pos);
-               // number in string is in hex format, convert to int
-               suc_flg = string_to_number<int>(family_code, tmp_str, hex);
-               if (suc_flg == true) {
-                       log_debug("family_code: %d\n", family_code);
-                       device_name     = folder_name.substr(pos + 1, folder_name.length() - pos);
-                       ret_val         = Factory::get_device(family_code,
-                                                       device_name,
-                                                       direntry_param);
-               }
-       }
-       return ret_val;
-}
-
-list<W1Device *> W1Scanner::get_device_list() {
-       DIR                     *dir;
-       int                     err_flg;
-       struct dirent           *direntry;
-       W1Device                *device;
-       list<W1Device *>        ret_val;
-       bool                    is_subdir;
-
-       printf("get_device_list() started\n");
-       dir     = opendir(W1_SCAN_ROOTDIR);
-       if (dir != NULL) {
-               direntry        = readdir(dir);
-               while(direntry != NULL) {
-                       is_subdir       = W1Util::is_subdirectory(W1_SCAN_ROOTDIR, direntry);
-                       if (is_subdir == true) {
-                               log_info("dir_name: %s\n", direntry->d_name);
-                               device  = create_device(direntry);
-                               if (device != NULL) {
-                                       log_info("device: %d\n", device->get_family_code());
-                                       ret_val.push_back(device);
-                               }
-                               else {
-                                       log_info("unsupported device-directory: %s\n", direntry->d_name);
-                               }
-                       }
-                       direntry        = readdir(dir);
-               }
-               err_flg = closedir(dir);
-               if (err_flg < 0) {
-                       log_error("failed to close 1-wire device directory scanned: %s\n", W1_SCAN_ROOTDIR);
-               }
-       }
-       return ret_val;
-}
diff --git a/src/W1Scanner.hh b/src/W1Scanner.hh
deleted file mode 100644 (file)
index 21a7c7b..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * W1Scanner.hh
- *
- *  Created on: Oct 20, 2010
- *      Author: lamikr
- */
-
-#ifndef W1SCANNER_HH_
-#define W1SCANNER_HH_
-
-#include <dirent.h>
-#include <list>
-#include <string>
-
-#include "W1Device.hh"
-
-#ifndef W1_SCAN_ROOTDIR
-       #define W1_SCAN_ROOTDIR         "/sys/bus/w1/devices"
-#endif
-
-namespace w1 {
-       class W1Scanner {
-               public:
-                       W1Scanner();
-                       virtual ~W1Scanner();
-                       std::list<W1Device *> get_device_list();
-               private:
-                       //int parse_family_code(std::string folder_name);
-                       W1Device *create_device(dirent *direntry_param);
-       };
-}
-
-#endif /* W1SCANNER_HH_ */
index fda285e540c0e6b13dcf3ca56f185410af86578d..8debaa1b316f336e33a5265edcbebf5e09fe4ef7 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <plp/log.h>
 
+#include "DeviceConfig.hh"
 #include "W1Configure.hh"
 #include "W1Store.hh"
 #include "W1Util.hh"
index 08dc7e0e90419341c1202cccd245bf556b3f6173..452d7290758e7b1eee203e5d27e39c9a03a548a0 100644 (file)
@@ -63,7 +63,7 @@ char *W1Util::parse_directory_path(const char *file_path) {
        return ret_val;
 }
 
-bool W1Util::mkdirs(char *path) {
+bool W1Util::mkdirs(const char *path) {
        bool    ret_val;
        char    *p;
        int     err_flg;
@@ -71,13 +71,13 @@ bool W1Util::mkdirs(char *path) {
        ret_val = true;
        if (path != NULL) {
                // go through each directory one by and and create if not exist
-               for (p = path; *p; p++) {
+               for (p = (char *)path; *p; p++) {
                    if ((p != path) &&
                        ((*p == '/') ||
                         (*p == '\\'))) {
                                *p = '\0';
-                               // test whether directory exist and is writable
-                               if (access(path, F_OK)) {
+                               // if dir does not exist, create it
+                               if (access(path, F_OK) != 0) {
                                        log_debug("trying to create directory: %s\n", path);
                                        err_flg = mkdir(path, S_IRWXU);
                                        if (err_flg != 0) {
@@ -89,8 +89,8 @@ bool W1Util::mkdirs(char *path) {
                        }
                }
                if (ret_val == true) {
-                       // test also the existense of whole directory
-                       if (access(path, F_OK)) {
+                       // if dir does not exist, create it
+                       if (access(path, F_OK) != 0) {
                                log_debug("trying to create directory: %s\n", path);
                                err_flg = mkdir(path, S_IRWXU);
                                if (err_flg != 0) {
index 161d2f04b10f7578189ccd0ad302d1929c865d0e..cbc74ab26f4ec14254c4142fcacc1c31b0fb62f6 100644 (file)
@@ -18,8 +18,6 @@
 #include <dirent.h>
 #include <stdbool.h>
 
-#include "W1DataList.hh"
-
 namespace w1 {
        class W1Util {
                public:
@@ -33,7 +31,7 @@ namespace w1 {
                        static std::vector<std::string> get_data_files(const std::string& path);
                        static plp::Date parse_date_str(std::string date_str);
                        static char *parse_directory_path(const char *file_path);
-                       static bool mkdirs(char *path);
+                       static bool mkdirs(const char *path);
                        static std::ofstream *open_for_writing(const char *path);
        };
 }
index 0c4a5b9b1859f65b8833dc3c09589d130fc3d4b3..046a47508c98eb52753636223a1498d9935bbb25 100644 (file)
 
 #include <plp/log.h>
 
-#include "W1DataList.hh"
-#include "DeviceConfig.hh"
-#include "W1Scanner.hh"
-
 #include "Date.hh"
+#include "DeviceData.hh"
+#include "DeviceConfig.hh"
+#include "Factory.hh"
 #include "W1Util.hh"
 
 using namespace w1;
@@ -47,16 +46,16 @@ bool try_parse_long(const char *str, long *result) {
 }
 
 int main(int argc, char** argv) {
-       string          loc;
-       Data            *fdata;
-       Data            *ldata;
-       W1DataList      *dlist;
-       DataRange       *dr;
-       DataRange       *dr2;
+       string                  loc;
+       Data                    *fdata;
+       Data                    *ldata;
+       DeviceData              *dta;
+       DataRange               *dr;
+       DataRange               *dr2;
+       list<DeviceData *>      dta_list;
 
        // default values than can be overwritten with parameters
-       //location      = "/tmp/";
-       loc     = "/home/lamikr/own/src/plp/w1data2/";
+       loc     = "/tmp/w1data";
        if (argc > 1) {
                loc     = argv[1];
                log_info("storage location: %s\n", loc.c_str());
@@ -65,32 +64,35 @@ int main(int argc, char** argv) {
                log_warning("No storage location parameter given, using default location: %s\n", loc.c_str());
        }
        DeviceConfig::set_base_dir_name(loc);
-       dlist   = new W1DataList("0008014e9e09");
-       if (dlist != NULL) {
-               dr      = dlist->get_data_range();
-               if (dr != NULL) {
-                       fdata   = dr->get_first_data();
-                       if (fdata != NULL) {
-                               fdata->printout();
-                               ldata   = dr->get_last_data();
-                               if (ldata != NULL) {
-                                       ldata->printout();
-                                       plp::Date d1;
-                                       plp::Date d2;
+       dta_list        = Factory::get_device_data_list();
+       for(list<DeviceData *>::iterator list_iter = dta_list.begin(); list_iter != dta_list.end(); list_iter++) {
+               dta     = (DeviceData *)*list_iter;
+               if (dta != NULL) {
+                       dr      = dta->get_data_range();
+                       if (dr != NULL) {
+                               fdata   = dr->get_first_data();
+                               if (fdata != NULL) {
+                                       fdata->printout();
+                                       ldata   = dr->get_last_data();
+                                       if (ldata != NULL) {
+                                               ldata->printout();
+                                               plp::Date d1;
+                                               plp::Date d2;
 
-                                       d1      = fdata->get_date();
-                                       d2      = ldata->get_date();
-                                       dr2     = dlist->get_data(&d1, &d2);
-                                       delete(ldata);
-                                       if (dr2 != NULL) {
-                                               delete(dr2);
+                                               d1      = fdata->get_date();
+                                               d2      = ldata->get_date();
+                                               dr2     = dta->get_data(&d1, &d2);
+                                               delete(ldata);
+                                               if (dr2 != NULL) {
+                                                       delete(dr2);
+                                               }
                                        }
+                                       delete(fdata);
                                }
-                               delete(fdata);
+                               delete(dr);
                        }
-                       delete(dr);
+                       delete(dta);
                }
-               delete(dlist);
        }
        return 0;
 }
index f5a86d8820c69f41cb13648606c93383bbd8f1b3..d0cd8e9943b1fd62c709c9cde8e5175ba547a288 100644 (file)
@@ -14,7 +14,7 @@
 #include <plp/log.h>
 
 #include "DeviceConfig.hh"
-#include "W1Scanner.hh"
+#include "Factory.hh"
 
 using namespace w1;
 using namespace std;
@@ -43,24 +43,23 @@ 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;
+       string                  loc;
        W1Device                *device;
 
        // default values than can be overwritten with parameters
-       location        = "/tmp/";
-       scan_interval   = 2; //600;
+       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,15 +67,12 @@ 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: %ld, store interval: %ld\n", location.c_str(), scan_interval, store_interval);
-       DeviceConfig::set_base_dir_name(location);
-       scanner         = new W1Scanner();
-       device_list     = scanner->get_device_list();
+       log_info("start scanning, data saved to location: %s, scan interval: %ld, store interval: %ld\n", loc.c_str(), scan_interval, store_interval);
+       DeviceConfig::set_base_dir_name(loc);
+       device_list     = Factory::get_device_list();
        round           = 0;
-       int     t = 0;
        if (device_list.size() > 0) {
-               while(t < 3) {
-                       t++;
+               while(1) {
                        round++;
                        for(list<W1Device *>::iterator list_iter = device_list.begin(); list_iter != device_list.end(); list_iter++) {
                                device = (W1Device *)*list_iter;
@@ -100,6 +96,5 @@ int main(int argc, char** argv) {
                device_list.pop_back();
                delete(device);
        }
-       delete(scanner);
        return 0;
 }