From: Mika Laitio Date: Thu, 6 Jan 2011 10:35:07 +0000 (+0200) Subject: W1Store --> Store... X-Git-Url: http://pilppa.org/gitweb/?p=lib1wire.git;a=commitdiff_plain;h=56242039f27dc5d36117b8d513731c7a9009d4b1 W1Store --> Store... Prepare non-w1 functionality be separated from the w1 specific one. Signed-off-by: Mika Laitio --- diff --git a/src/Data.hh b/src/Data.hh index 90b0e47..11c168d 100644 --- a/src/Data.hh +++ b/src/Data.hh @@ -14,7 +14,7 @@ #include "Date.hh" -namespace w1 { +namespace plp { class Data { public: Data(int size); diff --git a/src/DeviceData.cc b/src/DeviceData.cc index 6b75301..d066bbd 100644 --- a/src/DeviceData.cc +++ b/src/DeviceData.cc @@ -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 year_vector) { vector mon_vcr; vector 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 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 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 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 *DeviceData::get_hourly_summary(Date *date, int calc_type) { vector *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: diff --git a/src/DeviceData.hh b/src/DeviceData.hh index e3b3727..eb64b06 100644 --- a/src/DeviceData.hh +++ b/src/DeviceData.hh @@ -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 *get_hourly_summary(plp::Date *date, int calc_type); - std::vector *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 *get_hourly_summary(plp::Date *date, int calc_type); + std::vector *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 year_vector); - Data *find_newest_data(std::vector year_vector); + plp::Data *find_oldest_data(std::vector year_vector); + plp::Data *find_newest_data(std::vector year_vector); }; } diff --git a/src/Makefile.am b/src/Makefile.am index ec3ec8f..9a18e11 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/W1Store.cc b/src/Store.cc similarity index 94% rename from src/W1Store.cc rename to src/Store.cc index fddf015..125a906 100644 --- a/src/W1Store.cc +++ b/src/Store.cc @@ -1,5 +1,5 @@ /* - * W1Store.cc + * Store.cc * * Created on: Oct 31, 2010 * Author: lamikr @@ -20,14 +20,14 @@ #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_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 *W1Store::get_sum(int freq_sec) { +vector *Store::get_sum(int freq_sec) { int row_count; int col_count; int jj; @@ -434,7 +434,7 @@ vector *W1Store::get_sum(int freq_sec) { return ret_val; } -vector *W1Store::get_mean(int freq_sec) { +vector *Store::get_mean(int freq_sec) { int row_count; int col_count; int d_count; @@ -509,7 +509,7 @@ vector *W1Store::get_mean(int freq_sec) { return ret_val; } -vector *W1Store::get_delta(int freq_sec) { +vector *Store::get_delta(int freq_sec) { int row_count; int col_count; int jj; @@ -595,7 +595,7 @@ vector *W1Store::get_delta(int freq_sec) { return ret_val; } -vector *W1Store::get_max_or_min(int freq_sec, bool max) { +vector *Store::get_max_or_min(int freq_sec, bool max) { int row_count; int col_count; int jj; @@ -673,21 +673,21 @@ vector *W1Store::get_max_or_min(int freq_sec, bool max) { return ret_val; } -vector *W1Store::get_max(int freq_sec) { +vector *Store::get_max(int freq_sec) { vector *ret_val; ret_val = get_max_or_min(freq_sec, true); return ret_val; } -vector *W1Store::get_min(int freq_sec) { +vector *Store::get_min(int freq_sec) { vector *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 index 0000000..11218f2 --- /dev/null +++ b/src/Store.hh @@ -0,0 +1,52 @@ +/* + * Store.hh + * + * Created on: Oct 31, 2010 + * Author: lamikr + */ + +#ifndef W1STORE_HH_ +#define W1STORE_HH_ + +#include +#include +#include + +#include + +#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 *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 *get_sum(int freq_sec); + std::vector *get_mean(int freq_sec); + std::vector *get_delta(int freq_sec); + std::vector *get_max(int freq_sec); + std::vector *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 *get_max_or_min(int freq_sec, bool max); + }; +} + +#endif /* W1STORE_HH_ */ diff --git a/src/W1Device.cc b/src/W1Device.cc index c9c2e7e..429a5e8 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -14,11 +14,12 @@ #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); diff --git a/src/W1Device.hh b/src/W1Device.hh index 90b5532..e5de6d9 100644 --- a/src/W1Device.hh +++ b/src/W1Device.hh @@ -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 *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 memory_cache; + std::list memory_cache; }; } diff --git a/src/W1Store.hh b/src/W1Store.hh deleted file mode 100644 index b4a6b1a..0000000 --- a/src/W1Store.hh +++ /dev/null @@ -1,52 +0,0 @@ -/* - * W1Store.hh - * - * Created on: Oct 31, 2010 - * Author: lamikr - */ - -#ifndef W1STORE_HH_ -#define W1STORE_HH_ - -#include -#include -#include - -#include - -#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_list, int dec_precision); - bool load(); - Data *get_sum(); - Data *get_delta(); - Data *get_mean(); - Data *get_max(); - Data *get_min(); - std::vector *get_sum(int freq_sec); - std::vector *get_mean(int freq_sec); - std::vector *get_delta(int freq_sec); - std::vector *get_max(int freq_sec); - std::vector *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 *get_max_or_min(int freq_sec, bool max); - }; -} - -#endif /* W1STORE_HH_ */ diff --git a/src_test/test_w1_datalog_read.cc b/src_test/test_w1_datalog_read.cc index d135c03..1ba7005 100644 --- a/src_test/test_w1_datalog_read.cc +++ b/src_test/test_w1_datalog_read.cc @@ -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;