From f280d6c6383f3642069fac8a490f827195619278 Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Fri, 17 Jun 2011 01:46:09 +0300 Subject: [PATCH] cleanups Signed-off-by: Mika Laitio --- src/Factory.cc | 32 ++++++++++++++++---------------- src/Factory.hh | 12 ++++++------ src/W1Device.cc | 13 +++++-------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/Factory.cc b/src/Factory.cc index 6145a46..9d704b5 100644 --- a/src/Factory.cc +++ b/src/Factory.cc @@ -95,28 +95,28 @@ Device *Factory::create_w1_device(int family_code_param, return ret_val; } -Device *Factory::create_w1_device(int family_code_param, +Device *Factory::create_w1_device(int device_w1_family_code_param, + string device_type_param, string device_id_param, - string type_param, dirent *direntry_param) { Device *ret_val; DeviceConfig *config; ret_val = NULL; - if (type_param.empty() == false) { - switch(family_code_param) { + if (device_type_param.empty() == false) { + switch(device_w1_family_code_param) { case 0x10: case 0x28: - ret_val = new W1TemperatureSensor(device_id_param, type_param, direntry_param); + ret_val = new W1TemperatureSensor(device_id_param, device_type_param, direntry_param); break; case 0x1d: - ret_val = new W1CounterDevice(device_id_param, type_param, direntry_param); + ret_val = new W1CounterDevice(device_id_param, device_type_param, direntry_param); break; case 0x81: // 0x81 is the 1-wire USB dongle... No need to create device for it. break; default: - log_debug("Unsupported 1-wire-family code: %#x, device not created: %s\n", family_code_param, device_id_param.c_str()); + log_debug("Unsupported 1-wire-family code: %#x, device not created: %s\n", device_w1_family_code_param, device_id_param.c_str()); break; } if (ret_val != NULL) { @@ -124,10 +124,10 @@ Device *Factory::create_w1_device(int family_code_param, config = DeviceConfig::get_device_config(device_id_param); if (config != NULL) { // if not, create default device config - type_param = config->get_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE); - if (type_param.empty() == true) { - type_param = ret_val->get_type(); - config->set_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE, type_param); + device_type_param = config->get_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE); + if (device_type_param.empty() == true) { + device_type_param = ret_val->get_type(); + config->set_config_value(DEVICE_CONFIG_VALUE_KEY__TYPE, device_type_param); config->set_config_value(DEVICE_CONFIG_VALUE_KEY__ID, ret_val->get_id()); } delete(config); @@ -142,11 +142,11 @@ Device *Factory::create_w1_device(string device_type_param, int family_code; Device *ret_val; - ret_val = NULL; + ret_val = NULL; if (device_type_param.empty() == false) { family_code = get_family_code_by_device_type(device_type_param); if (family_code != -1) { - ret_val = create_w1_device(family_code, device_type_param, device_id_param, NULL); + ret_val = create_w1_device(family_code, device_type_param, device_id_param, NULL); } } return ret_val; @@ -156,7 +156,7 @@ Device *Factory::create_w1_device(dirent *direntry_param, int *err_code_param) { string folder_name; string tmp_str; - string device_name; + string device_id; int pos; int family_code; bool suc_flg; @@ -174,9 +174,9 @@ Device *Factory::create_w1_device(dirent *direntry_param, if (family_code != 0x81) { if (suc_flg == true) { log_debug("1-wire device family code: %#x\n", family_code); - device_name = folder_name.substr(pos + 1, folder_name.length() - pos); + device_id = folder_name.substr(pos + 1, folder_name.length() - pos); ret_val = Factory::create_w1_device(family_code, - device_name, + device_id, direntry_param); if ((ret_val == NULL) && (family_code != 0x81)) { diff --git a/src/Factory.hh b/src/Factory.hh index c4adccb..a4c1c1f 100644 --- a/src/Factory.hh +++ b/src/Factory.hh @@ -28,14 +28,14 @@ namespace w1 { virtual ~Factory(); static std::list get_device_list(); private: - //int parse_family_code(std::string folder_name); - static plp::Device *create_w1_device(int family_code_param, string device_id_param, string type_param, dirent *direntry_param); - static plp::Device *create_w1_device(int family_code, std::string device_id, dirent *direntry_param); - static plp::Device *create_w1_device(std::string device_type_param, std::string device_id_param); + //int parse_family_code(string folder_name); + static plp::Device *create_w1_device(int family_code_param, string device_type_param, string device_id_param, dirent *direntry_param); + static plp::Device *create_w1_device(int family_code, string device_id, dirent *direntry_param); + static plp::Device *create_w1_device(string device_type_param, string device_id_param); static plp::Device *create_w1_device(dirent *direntry_param, int *err_code_param); static std::list get_data_reader_list(); - static int get_family_code_by_device_type(std::string device_type_param); - static std::string get_device_type_by_family_code(int family_code_param); + static int get_family_code_by_device_type(string device_type_param); + static string get_device_type_by_family_code(int family_code_param); }; } diff --git a/src/W1Device.cc b/src/W1Device.cc index 84f4fec..eb94b24 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -48,7 +48,7 @@ W1Device::W1Device(string device_id_param, } W1Device::~W1Device() { - log_debug("W1Device destructor\n"); + log_debug("started\n"); save_and_clean_cache(); if (reader != NULL) { delete(reader); @@ -114,21 +114,18 @@ Data *W1Device::get_data() { Data *ret_val; vector *vect; - log_debug("get_data() started\n"); ret_val = NULL; vect = get_raw_data(); if (vect != NULL) { - log_debug("get_data() got raw data\n"); ret_val = new Data(vect, get_unit()); cache(ret_val); delete(vect); - log_debug("get_data() got raw data done\n"); + log_debug("%s returning new data\n", id.c_str()); } else { - log_debug("get_data() try to read old already saved data\n"); - // read old data already saved + // read old already saved data + log_debug("%s returning old saved data\n", id.c_str()); ret_val = reader->get_latest_data(); - log_debug("get_data() try to read old already saved data done\n"); } return ret_val; } @@ -158,7 +155,7 @@ void W1Device::save_and_clean_cache() { dec_precision = get_data_decimal_precision(); pthread_mutex_lock(&plock); - log_debug("save_and_clean_cache(): memory cache size: %d\n", memory_cache.size()); + log_debug("memory cache size: %d\n", memory_cache.size()); StoreDay::save(id, &memory_cache, dec_precision); while(memory_cache.empty() == false) { data = memory_cache.back(); -- 2.41.0