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

Committer:
ansond
Date:
Tue Feb 25 18:08:58 2014 +0000
Revision:
14:d4f8ab1e199a
Parent:
10:62107616fc6c
Child:
21:cfdaee0a2b50
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 1:5d332fa199ce 1 /* Copyright C2013 Doug Anson, MIT License
ansond 1:5d332fa199ce 2 *
ansond 1:5d332fa199ce 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 1:5d332fa199ce 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 1:5d332fa199ce 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 1:5d332fa199ce 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 1:5d332fa199ce 7 * furnished to do so, subject to the following conditions:
ansond 1:5d332fa199ce 8 *
ansond 1:5d332fa199ce 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 1:5d332fa199ce 10 * substantial portions of the Software.
ansond 1:5d332fa199ce 11 *
ansond 1:5d332fa199ce 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 1:5d332fa199ce 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 1:5d332fa199ce 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 1:5d332fa199ce 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 1:5d332fa199ce 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 1:5d332fa199ce 17 */
ansond 1:5d332fa199ce 18
ansond 1:5d332fa199ce 19 #include "ResourceFactory.h"
ansond 1:5d332fa199ce 20
ansond 1:5d332fa199ce 21 // default constructor
ansond 1:5d332fa199ce 22 ResourceFactory::ResourceFactory(ErrorHandler *error_handler) {
ansond 1:5d332fa199ce 23 this->m_error_handler = error_handler;
ansond 6:9a4085eeac52 24 this->m_list.clear();
ansond 1:5d332fa199ce 25 }
ansond 1:5d332fa199ce 26
ansond 1:5d332fa199ce 27 // default destructor
ansond 1:5d332fa199ce 28 ResourceFactory::~ResourceFactory() {
ansond 1:5d332fa199ce 29
ansond 1:5d332fa199ce 30 }
ansond 1:5d332fa199ce 31
ansond 1:5d332fa199ce 32 // get the error handler
ansond 2:4d81c828b230 33 ErrorHandler *ResourceFactory::logger() { return this->m_error_handler; }
ansond 1:5d332fa199ce 34
ansond 1:5d332fa199ce 35 // create resources (base class does nothing)
ansond 4:3176f927618d 36 void ResourceFactory::createResources(char *endpoint_name) { ; }
ansond 6:9a4085eeac52 37
ansond 6:9a4085eeac52 38 // create a resource value
ansond 7:36ec6469949e 39 void ResourceFactory::createResource(char *name,char *value) { this->createResource(NULL,name,value,NULL); }
ansond 6:9a4085eeac52 40 void ResourceFactory::createResource(char *endpoint_name,char *name,char *value,void *internals) {
ansond 6:9a4085eeac52 41 Resource resource(this->logger(),endpoint_name,name,value,internals);
ansond 6:9a4085eeac52 42 this->m_list.push_back(resource);
ansond 6:9a4085eeac52 43 }
ansond 6:9a4085eeac52 44
ansond 6:9a4085eeac52 45 // get a resource value (null in base class)
ansond 6:9a4085eeac52 46 char *ResourceFactory::getResourceValue(char *name) {
ansond 6:9a4085eeac52 47 char *value = NULL;
ansond 6:9a4085eeac52 48 bool found = false;
ansond 6:9a4085eeac52 49
ansond 6:9a4085eeac52 50 // loop through the resource list
ansond 6:9a4085eeac52 51 for(int i=0;i<this->m_list.size() && !found;++i) {
ansond 6:9a4085eeac52 52 if (strcmp(this->m_list[i].getName(),name) == 0) {
ansond 6:9a4085eeac52 53 found = true;
ansond 6:9a4085eeac52 54 value = this->m_list[i].getValue();
ansond 14:d4f8ab1e199a 55 this->logger()->log("Getting Resource: %s Value: %s",name,value);
ansond 6:9a4085eeac52 56 }
ansond 6:9a4085eeac52 57 }
ansond 6:9a4085eeac52 58
ansond 6:9a4085eeac52 59 return value;
ansond 10:62107616fc6c 60 }
ansond 10:62107616fc6c 61
ansond 10:62107616fc6c 62 // set a resource value
ansond 10:62107616fc6c 63 void ResourceFactory::setResourceValue(char *name, char *value) {
ansond 10:62107616fc6c 64 bool found = false;
ansond 10:62107616fc6c 65
ansond 10:62107616fc6c 66 // loop through the resource list
ansond 10:62107616fc6c 67 for(int i=0;i<this->m_list.size() && !found;++i) {
ansond 10:62107616fc6c 68 if (strcmp(this->m_list[i].getName(),name) == 0) {
ansond 10:62107616fc6c 69 found = true;
ansond 14:d4f8ab1e199a 70 this->logger()->log("Setting Resource: %s Value: %s",name,value);
ansond 10:62107616fc6c 71 this->m_list[i].setValue(value);
ansond 10:62107616fc6c 72 }
ansond 10:62107616fc6c 73 }
ansond 6:9a4085eeac52 74 }
ansond 10:62107616fc6c 75