From: Mika Laitio Date: Wed, 15 Aug 2012 09:28:12 +0000 (+0300) Subject: load deviceconfig only once X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=cad6fd5749ae467e006bd3ae62666fe8c92cdf20;p=lib1wire.git load deviceconfig only once Signed-off-by: Mika Laitio --- diff --git a/src/W1Device.cc b/src/W1Device.cc index a15f3d8..4111dd9 100644 --- a/src/W1Device.cc +++ b/src/W1Device.cc @@ -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); } } }