Core Base Classes for the Light Endpoints
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more
Diff: Preferences.cpp
- Revision:
- 116:428281cb5066
- Parent:
- 114:bd38ad417d6a
- Child:
- 117:34f0d83dcabb
--- a/Preferences.cpp Wed Mar 19 03:51:03 2014 +0000 +++ b/Preferences.cpp Wed Mar 19 04:12:53 2014 +0000 @@ -19,10 +19,11 @@ #include "mbed.h" #include "Preferences.h" + LocalFileSystem local("local"); + // default constructor Preferences::Preferences(ErrorHandler *error_handler) { this->m_error_handler = error_handler; - this->m_local_filesystem = new LocalFileSystem("local"); this->m_config_file = new ConfigFile(); this->initialize(); } @@ -30,7 +31,6 @@ // destructor Preferences::~Preferences() { if (this->m_config_file != NULL) delete this->m_config_file; - if (this->m_local_filesystem != NULL) delete this->m_local_filesystem; } // initialize the preferences from the preferences file @@ -65,7 +65,7 @@ char buffer[PREFERENCE_VALUE_LEN+1]; memset(buffer,0,PREFERENCE_VALUE_LEN+1); char *value = this->getPreference(name,buffer,PREFERENCE_VALUE_LEN,NULL); - if (value != NULL) sscanf(buffer,"%d",&int_value); + if (value != NULL && strlen(value) > 0) sscanf(buffer,"%d",&int_value); return int_value; } @@ -84,7 +84,7 @@ char *Preferences::getPreference(char *name,char *buffer,int buffer_length,char *def_value) { if (this->m_config_file != NULL) { memset(buffer,0,buffer_length); - this->m_config_file->getValue(name, &buffer[0], buffer_length); + this->m_config_file->getValue(name,&buffer[0],buffer_length); if (strlen(buffer) == 0 && def_value != NULL) strncpy(buffer,def_value,this->min(buffer_length,strlen(def_value))); } return buffer;