]> pilppa.com Git - lib1wire.git/commitdiff
load deviceconfig only once
authorMika Laitio <lamikr@pilppa.org>
Wed, 15 Aug 2012 09:28:12 +0000 (12:28 +0300)
committerMika Laitio <lamikr@pilppa.org>
Wed, 15 Aug 2012 09:28:12 +0000 (12:28 +0300)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/W1Device.cc

index a15f3d8c18a1ec7355fa59553b99c560323aaec0..4111dd9cb8c485e61733c7428e02ca7a6b230ba7 100644 (file)
@@ -45,6 +45,7 @@ W1Device::W1Device(string device_id_param,
        }
        reader  = new DataReader(id);
        name    = "";
+       _cfg    = NULL;
 }
 
 W1Device::~W1Device() {
@@ -57,28 +58,25 @@ W1Device::~W1Device() {
 }
 
 string Device::get_name() {
-       DeviceConfig    *cfg;
-
        if (name.empty() == true) {
-               cfg     = DeviceConfig::get_device_config(id);
-               if (cfg != NULL) {
-                       cfg->get_config_value(DEVICE_CONFIG_VALUE_KEY__NAME, name);
-                       delete(cfg);
+               if (_cfg == NULL) {
+                       _cfg    = DeviceConfig::get_device_config(id);
+               }
+               if (_cfg != NULL) {
+                       _cfg->get_config_value(DEVICE_CONFIG_VALUE_KEY__NAME, name);
                }
        }
        return name;
 }
 
 void Device::set_name(string name_param) {
-       DeviceConfig    *cfg;
-
-       log_debug("set_name started\n");
        if (name.compare(name_param) != 0) {
                name    = name_param;
-               cfg     = DeviceConfig::get_device_config(id);
-               if (cfg != NULL) {
-                       cfg->set_config_value(DEVICE_CONFIG_VALUE_KEY__NAME, name_param, true);
-                       delete(cfg);
+               if (_cfg == NULL) {
+                       _cfg    = DeviceConfig::get_device_config(id);
+               }
+               if (_cfg != NULL) {
+                       _cfg->set_config_value(DEVICE_CONFIG_VALUE_KEY__NAME, name_param, true);
                }
        }
 }