]> pilppa.com Git - lib1wire.git/commitdiff
cleanups
authorMika Laitio <lamikr@pilppa.org>
Thu, 16 Jun 2011 22:46:09 +0000 (01:46 +0300)
committerMika Laitio <lamikr@pilppa.org>
Thu, 16 Jun 2011 22:46:09 +0000 (01:46 +0300)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/Factory.cc
src/Factory.hh
src/W1Device.cc

index 6145a469065afe0a7dc37b03dbebd94d0a17ceb6..9d704b59e32b620489bd1174df32458a68e1c375 100644 (file)
@@ -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)) {
index c4adccb2e46c790a437c6ed41cb1f96b40522a78..a4c1c1f4683e10415a711a9e36f0aaeae3dd2088 100644 (file)
@@ -28,14 +28,14 @@ namespace w1 {
                        virtual ~Factory();
                        static std::list<plp::Device *> 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<plp::DataReader *> 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);
        };
 }
 
index 84f4fecb9c78eff856bec0ee160b712f4b2da35a..eb94b24b3039ed611d17f5ba6d2692441b3835bb 100644 (file)
@@ -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<double>  *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();