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
Resource.cpp@26:791d22d43cb4, 2014-02-27 (annotated)
- Committer:
- ansond
- Date:
- Thu Feb 27 06:04:52 2014 +0000
- Revision:
- 26:791d22d43cb4
- Parent:
- 19:0e62467605e9
- Child:
- 40:eae89a487d86
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 6:9a4085eeac52 | 1 | /* Copyright C2013 Doug Anson, MIT License |
ansond | 6:9a4085eeac52 | 2 | * |
ansond | 6:9a4085eeac52 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 6:9a4085eeac52 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 6:9a4085eeac52 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 6:9a4085eeac52 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 6:9a4085eeac52 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 6:9a4085eeac52 | 8 | * |
ansond | 6:9a4085eeac52 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 6:9a4085eeac52 | 10 | * substantial portions of the Software. |
ansond | 6:9a4085eeac52 | 11 | * |
ansond | 6:9a4085eeac52 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 6:9a4085eeac52 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 6:9a4085eeac52 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 6:9a4085eeac52 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 6:9a4085eeac52 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 6:9a4085eeac52 | 17 | */ |
ansond | 6:9a4085eeac52 | 18 | |
ansond | 6:9a4085eeac52 | 19 | #include "Resource.h" |
ansond | 6:9a4085eeac52 | 20 | |
ansond | 6:9a4085eeac52 | 21 | // default constructor |
ansond | 9:90fadae5489a | 22 | Resource::Resource(ErrorHandler *error_handler,char *endpoint_name,char *name,char *value,void *cb) { |
ansond | 6:9a4085eeac52 | 23 | this->m_error_handler = error_handler; |
ansond | 6:9a4085eeac52 | 24 | memset(this->m_name,0,RESOURCE_NAME_LEN+1); |
ansond | 6:9a4085eeac52 | 25 | memset(this->m_value,0,RESOURCE_VALUE_LEN+1); |
ansond | 6:9a4085eeac52 | 26 | this->setName(name); |
ansond | 6:9a4085eeac52 | 27 | this->setValue(value); |
ansond | 9:90fadae5489a | 28 | this->setCallbackPointer(cb); |
ansond | 6:9a4085eeac52 | 29 | this->plumb(endpoint_name,name); |
ansond | 6:9a4085eeac52 | 30 | } |
ansond | 6:9a4085eeac52 | 31 | |
ansond | 6:9a4085eeac52 | 32 | // default destructor |
ansond | 6:9a4085eeac52 | 33 | Resource::~Resource() { |
ansond | 6:9a4085eeac52 | 34 | } |
ansond | 6:9a4085eeac52 | 35 | |
ansond | 6:9a4085eeac52 | 36 | // get the error handler |
ansond | 6:9a4085eeac52 | 37 | ErrorHandler *Resource::logger() { return this->m_error_handler; } |
ansond | 6:9a4085eeac52 | 38 | |
ansond | 6:9a4085eeac52 | 39 | // get and set the name of the resource |
ansond | 6:9a4085eeac52 | 40 | char *Resource::getName() { return this->m_name; } |
ansond | 6:9a4085eeac52 | 41 | void Resource::setName(char *name) { strncpy(this->m_name,name,this->min(RESOURCE_NAME_LEN,strlen(name))); } |
ansond | 6:9a4085eeac52 | 42 | |
ansond | 6:9a4085eeac52 | 43 | // get and set the value of the resource |
ansond | 6:9a4085eeac52 | 44 | char *Resource::getValue() { this->extract(this->getName()); return this->m_value; } |
ansond | 6:9a4085eeac52 | 45 | void Resource::setValue(char *value) { strncpy(this->m_value,value,this->min(RESOURCE_VALUE_LEN,strlen(value))); } |
ansond | 6:9a4085eeac52 | 46 | |
ansond | 6:9a4085eeac52 | 47 | // plumb the resource (base class does nothing other than save the endpoint_name) |
ansond | 6:9a4085eeac52 | 48 | void Resource::plumb(char *endpoint_name,char *name) { this->m_endpoint_name = endpoint_name; } |
ansond | 6:9a4085eeac52 | 49 | |
ansond | 6:9a4085eeac52 | 50 | // extract the resource value (base class does nothing) |
ansond | 6:9a4085eeac52 | 51 | void Resource::extract(char *name) { ; } |
ansond | 6:9a4085eeac52 | 52 | |
ansond | 6:9a4085eeac52 | 53 | // get the endpoint anme |
ansond | 6:9a4085eeac52 | 54 | char *Resource::endpoint() { return this->m_endpoint_name; } |
ansond | 6:9a4085eeac52 | 55 | |
ansond | 6:9a4085eeac52 | 56 | // set the internal resource linkage |
ansond | 9:90fadae5489a | 57 | void Resource::setCallbackPointer(void *cb) { this->m_cb = cb; } |
ansond | 9:90fadae5489a | 58 | void *Resource::getCallbackPointer() { return this->m_cb; } |
ansond | 6:9a4085eeac52 | 59 | |
ansond | 10:62107616fc6c | 60 | // min function |
ansond | 10:62107616fc6c | 61 | int Resource::min(int value1,int value2) { |
ansond | 6:9a4085eeac52 | 62 | if (value1 < value2) return value1; |
ansond | 6:9a4085eeac52 | 63 | return value2; |
ansond | 10:62107616fc6c | 64 | } |
ansond | 6:9a4085eeac52 | 65 |