Core Base Classes for the Light Endpoints

Dependencies:   BufferedSerial

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Revision:
47:fa96ddc36f04
Parent:
43:361a61395588
Child:
48:43fa2a43b114
diff -r 1041f7efee73 -r fa96ddc36f04 Resource.cpp
--- a/Resource.cpp	Sat Mar 01 16:10:08 2014 +0000
+++ b/Resource.cpp	Sat Mar 01 17:01:46 2014 +0000
@@ -25,6 +25,7 @@
      this->m_io = NULL;
      memset(this->m_name,0,RESOURCE_NAME_LEN+1);
      memset(this->m_value,0,RESOURCE_VALUE_LEN+1);
+     memset(this->m_endpoint_name,0,LIGHT_NAME_LEN+1);
      this->setName(name);
      this->setValue(value);
      this->setCallbackPointer(cb);
@@ -40,15 +41,15 @@
  
  // get and set the name of the resource
  char *Resource::getName() { return this->m_name; }
- void Resource::setName(char *name) { strncpy(this->m_name,name,this->min(RESOURCE_NAME_LEN,strlen(name))); }
+ void Resource::setName(char *name) { if (name != NULL) strncpy(this->m_name,name,this->min(RESOURCE_NAME_LEN,strlen(name))); }
  
  // get and set the value of the resource
- char *Resource::getValue() { this->extract(this->getName()); return this->m_value; }
+ char *Resource::getValue() { this->extract(this->getName()); return this->getValuePointer(); }
  char *Resource::getValuePointer() { return this->m_value; }
- void Resource::setValue(char *value) { strncpy(this->m_value,value,this->min(RESOURCE_VALUE_LEN,strlen(value))); }
+ void Resource::setValue(char *value) { if (value != NULL) strncpy(this->m_value,value,this->min(RESOURCE_VALUE_LEN,strlen(value))); }
  
  // plumb the resource (base class does nothing other than save the endpoint_name)
- void Resource::plumb(char *endpoint_name,char *name) { this->m_endpoint_name = endpoint_name; }
+ void Resource::plumb(char *endpoint_name,char *name) { if (endpint_name != NULL) strncpy(this->m_endpoint_name,endpoint_name,this->min(LIGHT_NAME_LEN,strlen(endpoint_name))); }
  
  // extract the resource value 
  void Resource::extract(char *name) {