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: ResourceFactory.cpp
- Revision:
- 26:791d22d43cb4
- Parent:
- 25:2a001b4f7024
- Child:
- 40:eae89a487d86
diff -r 2a001b4f7024 -r 791d22d43cb4 ResourceFactory.cpp --- a/ResourceFactory.cpp Thu Feb 27 04:05:31 2014 +0000 +++ b/ResourceFactory.cpp Thu Feb 27 06:04:52 2014 +0000 @@ -21,19 +21,20 @@ // default constructor ResourceFactory::ResourceFactory(ErrorHandler *error_handler) { this->m_error_handler = error_handler; - this->m_list.clear(); + this->m_count = 0; + for(int i=0;i<NUM_RESOURCES;++i) this->m_list[i] = NULL; } // default destructor ResourceFactory::~ResourceFactory() { - + for(int i=0;i<NUM_RESOURCES;++i) if (this->m_list[i] != NULL) delete this->m_list[i]; } // get our number of resources - int ResourceFactory::numResources() { return this->m_list.size(); } + int ResourceFactory::numResources() { return this->m_count; } // get the ith resource - Resource *ResourceFactory::getResource(int index) { return &(this->m_list[index]); }; + Resource *ResourceFactory::getResource(int index) { return this->m_list[index]; }; // get the error handler ErrorHandler *ResourceFactory::logger() { return this->m_error_handler; } @@ -44,8 +45,8 @@ // create a resource value void ResourceFactory::createResource(char *name,char *value) { this->createResource(NULL,name,value,NULL); } void ResourceFactory::createResource(char *endpoint_name,char *name,char *value,void *internals) { - Resource resource(this->logger(),endpoint_name,name,value,internals); - this->m_list.push_back(resource); + this->m_list[this->m_count] = new Resource(this->logger(),endpoint_name,name,value,internals); + ++this->m_count; } // get a resource value (null in base class) @@ -54,10 +55,10 @@ bool found = false; // loop through the resource list - for(int i=0;i<this->m_list.size() && !found;++i) { - if (strcmp(this->m_list[i].getName(),name) == 0) { + for(int i=0;i<this->m_count && !found;++i) { + if (strcmp(this->m_list[i]->getName(),name) == 0) { found = true; - value = this->m_list[i].getValue(); + value = this->m_list[i]->getValue(); this->logger()->log("Getting Resource: %s Value: %s",name,value); } } @@ -71,11 +72,11 @@ bool set = false; // loop through the resource list - for(int i=0;i<this->m_list.size() && !found;++i) { - if (strcmp(this->m_list[i].getName(),name) == 0) { + for(int i=0;i<this->m_count && !found;++i) { + if (strcmp(this->m_list[i]->getName(),name) == 0) { found = true; this->logger()->log("Setting Resource: %s Value: %s",name,value); - this->m_list[i].setValue(value); + this->m_list[i]->setValue(value); set = true; } } @@ -89,10 +90,10 @@ bool found = false; // loop through the resource list - for(int i=0;i<this->m_list.size() && !found;++i) { - if (strcmp(this->m_list[i].getName(),name) == 0) { + for(int i=0;i<this->m_count && !found;++i) { + if (strcmp(this->m_list[i]->getName(),name) == 0) { found = true; - cb = this->m_list[i].getCallbackPointer(); + cb = this->m_list[i]->getCallbackPointer(); } }