DataReader::DataReader(string device_id_param) {
string base_dir;
- device_config = NULL;
- device_id = device_id_param;
- base_dir = DeviceConfig::get_base_dir_name();
- device_dir = FileUtil::concat_paths(base_dir, device_id);
- device_ch_dir = FileUtil::concat_paths(base_dir, "cache");
- device_ch_dir = FileUtil::concat_paths(device_ch_dir, device_id);
+ log_debug("device_id: %s\n", device_id_param.c_str());
+ summary_calc_type = MEAN;
+ device_config = NULL;
+ device_id = device_id_param;
+ base_dir = DeviceConfig::get_base_dir_name();
+ device_dir = FileUtil::concat_paths(base_dir, device_id);
+ device_ch_dir = FileUtil::concat_paths(base_dir, "cache");
+ device_ch_dir = FileUtil::concat_paths(device_ch_dir, device_id);
}
DataReader::~DataReader() {
ret_val = NULL;
y_list = FileUtil::get_subdirectories(device_dir);
- ret_val = find_latest_data(y_list);
+ if (y_list.size() > 0) {
+ ret_val = find_latest_data(y_list);
+ }
return ret_val;
}
* Get Daily summary specified by the calc_type from the latest date.
*/
DataRange *DataReader::get_daily_summary(EnumSummaryCalculationType calc_type_param) {
- Data *data;
- Date date;
+ Data *data;
+ Date date;
+ DataRange *ret_val;
+ ret_val = NULL;
data = get_latest_data();
- date = data->get_date();
- return get_daily_summary(&date, calc_type_param);
+ if (data != NULL) {
+ date = data->get_date();
+ ret_val = get_daily_summary(&date, calc_type_param);
+ }
+ return ret_val;
}
DataRange *DataReader::get_daily_summary(Date *date,
}
/**
- * Read device type from the device specific config file
+ * Read device type from the device specific config file.
+ *
+ * @rerurn string representing device type.
+ * In the case of error, an empty string is returned.
*/
-string DataReader::get_device_type() {
- string ret_val;
+bool DataReader::get_device_type(string& type_param) {
+ bool ret_val;
+ ret_val = false;
if (device_config == NULL) {
device_config = DeviceConfig::get_device_config(device_id);
- ret_val = device_config->get_cfg_value(DEVICE_CONFIG_VALUE_KEY__TYPE);
+ }
+ if (device_config != NULL) {
+ ret_val = device_config->get_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE, type_param);
}
return ret_val;
}