]> pilppa.com Git - lib1wire.git/commitdiff
W1Store --> Store...
authorMika Laitio <lamikr@pilppa.org>
Thu, 6 Jan 2011 10:35:07 +0000 (12:35 +0200)
committerMika Laitio <lamikr@pilppa.org>
Thu, 6 Jan 2011 10:35:07 +0000 (12:35 +0200)
Prepare non-w1 functionality be separated from the w1 specific one.

Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/Data.hh
src/DeviceData.cc
src/DeviceData.hh
src/Makefile.am
src/Store.cc [moved from src/W1Store.cc with 94% similarity]
src/Store.hh [new file with mode: 0644]
src/W1Device.cc
src/W1Device.hh
src/W1Store.hh [deleted file]
src_test/test_w1_datalog_read.cc

index 90b0e47ad8b046688f0a020577e7de8df5818911..11c168d79440b8db859332a14cecb28753c8b647 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "Date.hh"
 
-namespace w1 {
+namespace plp {
        class Data {
                public:
                        Data(int size);
index 6b75301a4c67b609683ea4cad92bcae75a9d62af..d066bbdc3f96f9f423d0c58935b3709baae9547f 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "W1Util.hh"
 #include "DeviceData.hh"
-#include "W1Store.hh"
+#include "Store.hh"
 #include "DeviceConfig.hh"
 #include "Factory.hh"
 
@@ -44,7 +44,7 @@ Data *DeviceData::find_oldest_data(vector<string> year_vector) {
        vector<string>  mon_vcr;
        vector<string>  dta_vcr;
        string          f_name;
-       W1Store         *store;
+       Store           *store;
        Data            *ret_val;
 
        ret_val = NULL;
@@ -61,7 +61,7 @@ Data *DeviceData::find_oldest_data(vector<string> year_vector) {
                        if (dta_vcr.size() > 0) {
                                f_name  = dta_vcr.at(0);
                                f_name  = W1Util::concat_paths(mon_dr, f_name);
-                               store   = new W1Store(f_name);
+                               store   = new Store(f_name);
                                ret_val = store->get_oldest_data();
                                delete(store);
                                break;
@@ -80,7 +80,7 @@ Data *DeviceData::find_newest_data(vector<string> year_vector) {
        string          f_name;
        Data            *ret_val;
        int             size;
-       W1Store         *store;
+       Store           *store;
 
        ret_val = NULL;
        size    = year_vector.size();
@@ -98,7 +98,7 @@ Data *DeviceData::find_newest_data(vector<string> year_vector) {
                        if (size > 0) {
                                f_name  = d_vcr.at(size - 1);
                                f_name  = W1Util::concat_paths(mon_dr, f_name);
-                               store   = new W1Store(f_name);
+                               store   = new Store(f_name);
                                ret_val = store->get_newest_data();
                                delete(store);
                                break;
@@ -172,11 +172,12 @@ long int get_interval_type(Date *start_date,
 Data *DeviceData::get_daily_summary(Date *date,
                                int calc_type) {
        Data    *ret_val;
-       W1Store *store;
+       Store   *store;
        bool    suc_flg;
+       //Store *cache_store;
 
        ret_val = NULL;
-       store   = new W1Store(device_id, date);
+       store   = new Store(device_id, date);
        if (store != NULL) {
                suc_flg = store->load();
                if (suc_flg == true) {
@@ -251,10 +252,10 @@ DataRange *DeviceData::get_daily_summary(Date *start_date,
 vector<Data *> *DeviceData::get_hourly_summary(Date *date,
                                        int calc_type) {
        vector<Data *>  *ret_val;
-       W1Store         *store;
+       Store           *store;
 
        ret_val = NULL;
-       store   = new W1Store(device_id, date);
+       store   = new Store(device_id, date);
        store->load();
        switch(calc_type) {
                case SUM:
index e3b3727d482e08bd737d195dc91459780476858d..eb64b0662fb2f15a0404acdb2c3c42c39944c7fc 100644 (file)
@@ -22,26 +22,26 @@ namespace w1 {
                public:
                        DeviceData(std::string device_id);
                        virtual ~DeviceData();
-                       DataRange *get_data_range();
-                       Data *get_daily_summary(plp::Date *date, int calc_type);
+                       plp::DataRange *get_data_range();
+                       plp::Data *get_daily_summary(plp::Date *date, int calc_type);
                        /**
                         * Get summary data calculated from the daily data items that is meaning full.
                         * Depending from the device type, it may be daily mean value, daily delta, highest value, etc...
                         */
-                       Data *get_daily_summary(plp::Date *date);
-                       DataRange *get_daily_summary(plp::Date *start_date, plp::Date *end_date);
-                       std::vector<Data *> *get_hourly_summary(plp::Date *date, int calc_type);
-                       std::vector<Data *> *get_hourly_summary(plp::Date *date);
-                       DataRange *get_hourly_summary(plp::Date *start_date, plp::Date *end_date);
-                       DataRange *get_data(plp::Date *start_date, plp::Date *end_date);
+                       plp::Data *get_daily_summary(plp::Date *date);
+                       plp::DataRange *get_daily_summary(plp::Date *start_date, plp::Date *end_date);
+                       std::vector<plp::Data *> *get_hourly_summary(plp::Date *date, int calc_type);
+                       std::vector<plp::Data *> *get_hourly_summary(plp::Date *date);
+                       plp::DataRange *get_hourly_summary(plp::Date *start_date, plp::Date *end_date);
+                       plp::DataRange *get_data(plp::Date *start_date, plp::Date *end_date);
                protected:
                        std::string                     device_id;
                        std::string                     device_dir;
                        std::string                     device_ch_dir;
                        w1::DeviceConfig                *device_config;
                        enum_summary_calculation        summary_calc_type;
-                       Data *find_oldest_data(std::vector<std::string> year_vector);
-                       Data *find_newest_data(std::vector<std::string> year_vector);
+                       plp::Data *find_oldest_data(std::vector<std::string> year_vector);
+                       plp::Data *find_newest_data(std::vector<std::string> year_vector);
        };
 }
 
index ec3ec8f3df385d4c4fb974cc08de8b2fff028302..9a18e11d643364878484cbed3a2c21bbf9f1281d 100644 (file)
@@ -2,7 +2,7 @@ lib_LTLIBRARIES = lib1wire.la
 lib1wire_la_SOURCES = \
        Factory.cc Factory.hh \
        W1Device.cc W1Device.hh \
-       W1Store.cc W1Store.hh \
+       Store.cc Store.hh \
        W1TemperatureSensor.cc W1TemperatureSensor.hh \
        W1CounterDevice.cc W1CounterDevice.hh \
        W1Util.cc W1Util.hh \
@@ -25,6 +25,6 @@ lib1wireinclude_HEADERS = \
        Factory.hh \
        W1CounterDevice.hh \
        W1Device.hh \
-       W1Store.hh \
+       Store.hh \
        W1TemperatureSensor.hh \
        W1Util.hh
\ No newline at end of file
similarity index 94%
rename from src/W1Store.cc
rename to src/Store.cc
index fddf015ea2795dee3c5399b866bc5dcd27b11a3e..125a9063681fc16e24c3c72381cf11e4da30680d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * W1Store.cc
+ * Store.cc
  *
  *  Created on: Oct 31, 2010
  *      Author: lamikr
 
 #include "DeviceConfig.hh"
 #include "W1Configure.hh"
-#include "W1Store.hh"
+#include "Store.hh"
 #include "W1Util.hh"
 
 using namespace std;
 using namespace w1;
 using namespace plp;
 
-W1Store::W1Store(string device_id,
+Store::Store(string device_id,
                Date *date_time) {
        store_data      = NULL;
        range_data      = NULL;
@@ -35,20 +35,20 @@ W1Store::W1Store(string device_id,
        log_debug("data file name: %s\n", store_file_name.c_str());
 }
 
-W1Store::W1Store(string file_name_param) {
+Store::Store(string file_name_param) {
        store_data      = NULL;
        range_data      = NULL;
        store_file_name = file_name_param;
 }
 
-W1Store::~W1Store() {
+Store::~Store() {
        if (store_data != NULL) {
                delete(store_data);
                store_data      = NULL;
        }
 }
 
-string W1Store::get_dir_name(string device_id, Date *date_time) {
+string Store::get_dir_name(string device_id, Date *date_time) {
        string  ret_val;
        char    buffer[30];
        string  d_name;
@@ -60,7 +60,7 @@ string W1Store::get_dir_name(string device_id, Date *date_time) {
        return ret_val;
 }
 
-string W1Store::get_file_name(string device_id, Date *date_time) {
+string Store::get_file_name(string device_id, Date *date_time) {
        string  ret_val;
        string  fname;
        char    buffer[30];
@@ -73,7 +73,7 @@ string W1Store::get_file_name(string device_id, Date *date_time) {
        return ret_val;
 }
 
-void W1Store::save(string device_id,
+void Store::save(string device_id,
                std::list<Data *> *data_list,
                int dec_precision) {
        string                  n_path;
@@ -119,7 +119,7 @@ void W1Store::save(string device_id,
        }
 }
 
-bool W1Store::load() {
+bool Store::load() {
        Data            *data;
        ifstream        in;
        string          data_str;
@@ -156,7 +156,7 @@ bool W1Store::load() {
        return ret_val;
 }
 
-Data *W1Store::get_sum() {
+Data *Store::get_sum() {
        int     row_count;
        int     col_count;
        double  new_val;
@@ -202,7 +202,7 @@ Data *W1Store::get_sum() {
        return ret_val;
 }
 
-Data *W1Store::get_delta() {
+Data *Store::get_delta() {
        int             row_count;
        int             col_count;
        Data            *o_data;
@@ -237,7 +237,7 @@ Data *W1Store::get_delta() {
        return ret_val;
 }
 
-Data *W1Store::get_mean() {
+Data *Store::get_mean() {
        int     row_count;
        int     col_count;
        int     ii;
@@ -263,7 +263,7 @@ Data *W1Store::get_mean() {
        return ret_val;
 }
 
-Data *W1Store::get_max() {
+Data *Store::get_max() {
        int     row_count;
        int     col_count;
        double  new_val;
@@ -315,7 +315,7 @@ Data *W1Store::get_max() {
        return ret_val;
 }
 
-Data *W1Store::get_min() {
+Data *Store::get_min() {
        int     row_count;
        int     col_count;
        double  new_val;
@@ -367,7 +367,7 @@ Data *W1Store::get_min() {
        return ret_val;
 }
 
-vector<Data *> *W1Store::get_sum(int freq_sec) {
+vector<Data *> *Store::get_sum(int freq_sec) {
        int             row_count;
        int             col_count;
        int             jj;
@@ -434,7 +434,7 @@ vector<Data *> *W1Store::get_sum(int freq_sec) {
        return ret_val;
 }
 
-vector<Data *> *W1Store::get_mean(int freq_sec) {
+vector<Data *> *Store::get_mean(int freq_sec) {
        int             row_count;
        int             col_count;
        int             d_count;
@@ -509,7 +509,7 @@ vector<Data *> *W1Store::get_mean(int freq_sec) {
        return ret_val;
 }
 
-vector<Data *> *W1Store::get_delta(int freq_sec) {
+vector<Data *> *Store::get_delta(int freq_sec) {
        int             row_count;
        int             col_count;
        int             jj;
@@ -595,7 +595,7 @@ vector<Data *> *W1Store::get_delta(int freq_sec) {
        return ret_val;
 }
 
-vector<Data *> *W1Store::get_max_or_min(int freq_sec, bool max) {
+vector<Data *> *Store::get_max_or_min(int freq_sec, bool max) {
        int             row_count;
        int             col_count;
        int             jj;
@@ -673,21 +673,21 @@ vector<Data *> *W1Store::get_max_or_min(int freq_sec, bool max) {
        return ret_val;
 }
 
-vector<Data *> *W1Store::get_max(int freq_sec) {
+vector<Data *> *Store::get_max(int freq_sec) {
        vector<Data *>  *ret_val;
 
        ret_val = get_max_or_min(freq_sec, true);
        return ret_val;
 }
 
-vector<Data *> *W1Store::get_min(int freq_sec) {
+vector<Data *> *Store::get_min(int freq_sec) {
        vector<Data *>  *ret_val;
 
        ret_val = get_max_or_min(freq_sec, false);
        return ret_val;
 }
 
-DataRange *W1Store::get_oldest_and_newest_data() {
+DataRange *Store::get_oldest_and_newest_data() {
        DataRange       *ret_val;
        ifstream        in;
        Data            *o_data;
@@ -749,7 +749,7 @@ DataRange *W1Store::get_oldest_and_newest_data() {
        return ret_val;
 }
 
-Data *W1Store::get_oldest_data() {
+Data *Store::get_oldest_data() {
        int             row_count;
        Data            *ret_val;
        DataRange       *dr;
@@ -766,7 +766,7 @@ Data *W1Store::get_oldest_data() {
        return ret_val;
 }
 
-Data *W1Store::get_newest_data() {
+Data *Store::get_newest_data() {
        int             row_count;
        Data            *ret_val;
        DataRange       *dr;
diff --git a/src/Store.hh b/src/Store.hh
new file mode 100644 (file)
index 0000000..11218f2
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Store.hh
+ *
+ *  Created on: Oct 31, 2010
+ *      Author: lamikr
+ */
+
+#ifndef W1STORE_HH_
+#define W1STORE_HH_
+
+#include <string>
+#include <list>
+#include <vector>
+
+#include <stdbool.h>
+
+#include "Data.hh"
+#include "Date.hh"
+
+namespace plp {
+       class Store {
+               public:
+                       Store(std::string device_id,
+                               plp::Date *date_time);
+                       Store(std::string file_name_param);
+                       virtual ~Store();
+                       static std::string get_dir_name(std::string device_id, plp::Date *ltime);
+                       static std::string get_file_name(std::string device_id, plp::Date *ltime);
+                       static void save(std::string device_id, std::list<plp::Data *> *data_list, int dec_precision);
+                       bool load();
+                       plp::Data *get_sum();
+                       plp::Data *get_delta();
+                       plp::Data *get_mean();
+                       plp::Data *get_max();
+                       plp::Data *get_min();
+                       std::vector<plp::Data *> *get_sum(int freq_sec);
+                       std::vector<plp::Data *> *get_mean(int freq_sec);
+                       std::vector<plp::Data *> *get_delta(int freq_sec);
+                       std::vector<plp::Data *> *get_max(int freq_sec);
+                       std::vector<plp::Data *> *get_min(int freq_sec);
+                       plp::Data *get_oldest_data();
+                       plp::Data *get_newest_data();
+                       plp::DataRange *get_oldest_and_newest_data();
+               protected:
+                       std::string     store_file_name;
+                       plp::DataRange  *store_data;
+                       plp::DataRange  *range_data;
+                       std::vector<plp::Data *> *get_max_or_min(int freq_sec, bool max);
+       };
+}
+
+#endif /* W1STORE_HH_ */
index c9c2e7ed225318caa6b40630c6d2075d33796392..429a5e822baacb581aa17bcf9bf5c3b10ee4aee5 100644 (file)
 
 #include "DeviceConfig.hh"
 #include "Factory.hh"
-#include "W1Store.hh"
+#include "Store.hh"
 #include "W1Device.hh"
 
-using namespace w1;
 using namespace std;
+using namespace w1;
+using namespace plp;
 
 W1Device::W1Device(int family_code_param,
                string device_id_param,
@@ -129,7 +130,7 @@ void W1Device::save_data() {
        int                     dec_precision;
 
        dec_precision   = get_data_decimal_precision();
-       W1Store::save(id, &memory_cache, dec_precision);
+       Store::save(id, &memory_cache, dec_precision);
        for(iter = memory_cache.begin(); iter != memory_cache.end(); iter++) {
                data    = (Data *)*iter;
                delete(data);
index 90b5532860790d287f6bdda828fcf379bad998f2..e5de6d971cd0f0b9e233ea883e061fde3a56202f 100644 (file)
@@ -37,13 +37,13 @@ namespace w1 {
                        void set_name(std::string name_param);
                        virtual std::string get_unit() = 0;
                        virtual std::string get_device_type() = 0;
-                       Data *get_and_collect_data();
+                       plp::Data *get_and_collect_data();
                        virtual void save_data();
                        virtual void printout();
                protected:
                        virtual std::vector<double> *get_raw_data() = 0;
                        virtual unsigned int get_data_decimal_precision() = 0;
-                       void collect_data(Data *data);
+                       void collect_data(plp::Data *data);
                        std::string to_string(double val, int digit_count);
                        //Data *get_formatted_data(Data *data);
                        virtual bool is_supported_w1_family_code(int family_code) = 0;
@@ -52,7 +52,7 @@ namespace w1 {
                        std::string name;
                        std::string dir_path;
                        std::string slave_file;
-                       std::list<w1::Data *> memory_cache;
+                       std::list<plp::Data *> memory_cache;
        };
 }
 
diff --git a/src/W1Store.hh b/src/W1Store.hh
deleted file mode 100644 (file)
index b4a6b1a..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * W1Store.hh
- *
- *  Created on: Oct 31, 2010
- *      Author: lamikr
- */
-
-#ifndef W1STORE_HH_
-#define W1STORE_HH_
-
-#include <string>
-#include <list>
-#include <vector>
-
-#include <stdbool.h>
-
-#include "Data.hh"
-#include "Date.hh"
-
-namespace w1 {
-       class W1Store {
-               public:
-                       W1Store(std::string device_id,
-                               plp::Date *date_time);
-                       W1Store(std::string file_name_param);
-                       virtual ~W1Store();
-                       static std::string get_dir_name(std::string device_id, plp::Date *ltime);
-                       static std::string get_file_name(std::string device_id, plp::Date *ltime);
-                       static void save(std::string device_id, std::list<Data *> *data_list, int dec_precision);
-                       bool load();
-                       Data *get_sum();
-                       Data *get_delta();
-                       Data *get_mean();
-                       Data *get_max();
-                       Data *get_min();
-                       std::vector<w1::Data *> *get_sum(int freq_sec);
-                       std::vector<w1::Data *> *get_mean(int freq_sec);
-                       std::vector<w1::Data *> *get_delta(int freq_sec);
-                       std::vector<w1::Data *> *get_max(int freq_sec);
-                       std::vector<w1::Data *> *get_min(int freq_sec);
-                       w1::Data *get_oldest_data();
-                       w1::Data *get_newest_data();
-                       w1::DataRange *get_oldest_and_newest_data();
-               protected:
-                       std::string             store_file_name;
-                       DataRange               *store_data;
-                       DataRange               *range_data;
-                       std::vector<Data *> *get_max_or_min(int freq_sec, bool max);
-       };
-}
-
-#endif /* W1STORE_HH_ */
index d135c03f611b856f9fa26ecbf927a7d414433ceb..1ba7005ab3584c96b81b68c7b533de09954fb71c 100644 (file)
@@ -19,8 +19,9 @@
 #include "Factory.hh"
 #include "W1Util.hh"
 
-using namespace w1;
 using namespace std;
+using namespace plp;
+using namespace w1;
 
 bool try_parse_long(const char *str, long *result) {
        int     new_result;