mbed Connector Endpoint interface. This interface permits a mbed endpoint to easily setup MDS resources and emit those resources to an MDS server.

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

Committer:
sam_grove
Date:
Tue Jan 27 23:41:34 2015 +0000
Revision:
2:853f9ecc12df
Parent:
0:b438482ebbfc
Child:
46:cc6076ac5026
Use auto-format on code and add markup to render class documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:b438482ebbfc 1 /**
ansond 0:b438482ebbfc 2 * @file Resource.h
ansond 0:b438482ebbfc 3 * @brief mbed CoAP Endpoint Resource base class template
ansond 0:b438482ebbfc 4 * @author Doug Anson/Chris Paola
ansond 0:b438482ebbfc 5 * @version 1.0
sam_grove 2:853f9ecc12df 6 * @see
ansond 0:b438482ebbfc 7 *
ansond 0:b438482ebbfc 8 * Copyright (c) 2014
ansond 0:b438482ebbfc 9 *
ansond 0:b438482ebbfc 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 0:b438482ebbfc 11 * you may not use this file except in compliance with the License.
ansond 0:b438482ebbfc 12 * You may obtain a copy of the License at
ansond 0:b438482ebbfc 13 *
ansond 0:b438482ebbfc 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 0:b438482ebbfc 15 *
ansond 0:b438482ebbfc 16 * Unless required by applicable law or agreed to in writing, software
ansond 0:b438482ebbfc 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 0:b438482ebbfc 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 0:b438482ebbfc 19 * See the License for the specific language governing permissions and
ansond 0:b438482ebbfc 20 * limitations under the License.
ansond 0:b438482ebbfc 21 */
sam_grove 2:853f9ecc12df 22
sam_grove 2:853f9ecc12df 23 #ifndef __RESOURCE_H__
sam_grove 2:853f9ecc12df 24 #define __RESOURCE_H__
sam_grove 2:853f9ecc12df 25
sam_grove 2:853f9ecc12df 26 // logging facility
sam_grove 2:853f9ecc12df 27 #include "Logger.h"
sam_grove 2:853f9ecc12df 28
sam_grove 2:853f9ecc12df 29 // string support
sam_grove 2:853f9ecc12df 30 #include <string>
sam_grove 2:853f9ecc12df 31
sam_grove 2:853f9ecc12df 32 /** Resource class
sam_grove 2:853f9ecc12df 33 */
sam_grove 2:853f9ecc12df 34 template <typename InnerType> class Resource
sam_grove 2:853f9ecc12df 35 {
sam_grove 2:853f9ecc12df 36 public:
sam_grove 2:853f9ecc12df 37 /**
sam_grove 2:853f9ecc12df 38 Default constructor
sam_grove 2:853f9ecc12df 39 @param logger input the Logger instance this Resource is a part of
sam_grove 2:853f9ecc12df 40 @param name input the Resource URI/Name
sam_grove 2:853f9ecc12df 41 @param value input the Resource value
sam_grove 2:853f9ecc12df 42 */
sam_grove 2:853f9ecc12df 43 Resource(const Logger *logger,const string name,InnerType value) {
sam_grove 2:853f9ecc12df 44 this->init(logger);
sam_grove 2:853f9ecc12df 45 this->m_name = name;
sam_grove 2:853f9ecc12df 46 this->m_value = value;
sam_grove 2:853f9ecc12df 47 }
sam_grove 2:853f9ecc12df 48
sam_grove 2:853f9ecc12df 49 /**
sam_grove 2:853f9ecc12df 50 Copy constructor
sam_grove 2:853f9ecc12df 51 @param resource input the Resource that is to be deep copied
sam_grove 2:853f9ecc12df 52 */
sam_grove 2:853f9ecc12df 53 Resource(const Resource<InnerType> &resource) {
sam_grove 2:853f9ecc12df 54 this->init(resource.m_logger);
sam_grove 2:853f9ecc12df 55 this->m_endpoint = resource.m_endpoint;
sam_grove 2:853f9ecc12df 56 this->m_name = resource.m_name;
sam_grove 2:853f9ecc12df 57 this->m_value = resource.m_value;
sam_grove 2:853f9ecc12df 58 }
sam_grove 2:853f9ecc12df 59
sam_grove 2:853f9ecc12df 60 /**
sam_grove 2:853f9ecc12df 61 Destructor
sam_grove 2:853f9ecc12df 62 */
sam_grove 2:853f9ecc12df 63 virtual ~Resource() {
sam_grove 2:853f9ecc12df 64 }
ansond 0:b438482ebbfc 65
sam_grove 2:853f9ecc12df 66 /**
sam_grove 2:853f9ecc12df 67 Get the resource name
sam_grove 2:853f9ecc12df 68 @return the name of the resource
sam_grove 2:853f9ecc12df 69 */
sam_grove 2:853f9ecc12df 70 string getName() {
sam_grove 2:853f9ecc12df 71 return this->m_name;
sam_grove 2:853f9ecc12df 72 }
sam_grove 2:853f9ecc12df 73
sam_grove 2:853f9ecc12df 74 /**
sam_grove 2:853f9ecc12df 75 Get the resource value
sam_grove 2:853f9ecc12df 76 @return the value of the resource
sam_grove 2:853f9ecc12df 77 */
sam_grove 2:853f9ecc12df 78 InnerType getValue() {
sam_grove 2:853f9ecc12df 79 return this->m_value;
sam_grove 2:853f9ecc12df 80 }
sam_grove 2:853f9ecc12df 81
sam_grove 2:853f9ecc12df 82 /**
sam_grove 2:853f9ecc12df 83 Set the resource name
sam_grove 2:853f9ecc12df 84 @param name input the resource name
sam_grove 2:853f9ecc12df 85 */
sam_grove 2:853f9ecc12df 86 void setName(const string name) {
sam_grove 2:853f9ecc12df 87 this->m_name = name;
sam_grove 2:853f9ecc12df 88 }
ansond 0:b438482ebbfc 89
sam_grove 2:853f9ecc12df 90 /**
sam_grove 2:853f9ecc12df 91 Set the resource value
sam_grove 2:853f9ecc12df 92 @param value input the resource value
sam_grove 2:853f9ecc12df 93 */
sam_grove 2:853f9ecc12df 94 void setValue(const InnerType value) {
sam_grove 2:853f9ecc12df 95 this->m_value = value;
sam_grove 2:853f9ecc12df 96 }
sam_grove 2:853f9ecc12df 97
sam_grove 2:853f9ecc12df 98 /**
sam_grove 2:853f9ecc12df 99 Bind resource to endpoint
sam_grove 2:853f9ecc12df 100 */
sam_grove 2:853f9ecc12df 101 virtual void bind(void *p) = 0;
sam_grove 2:853f9ecc12df 102
sam_grove 2:853f9ecc12df 103 // access the logger()
sam_grove 2:853f9ecc12df 104 Logger *logger() {
sam_grove 2:853f9ecc12df 105 return this->m_logger;
sam_grove 2:853f9ecc12df 106 }
sam_grove 2:853f9ecc12df 107
sam_grove 2:853f9ecc12df 108 protected:
sam_grove 2:853f9ecc12df 109 // initialize internals to Resource
sam_grove 2:853f9ecc12df 110 void init(const Logger *logger) {
sam_grove 2:853f9ecc12df 111 this->m_logger = (Logger *)logger;
sam_grove 2:853f9ecc12df 112 this->m_endpoint = NULL;
sam_grove 2:853f9ecc12df 113 this->m_name = "";
sam_grove 2:853f9ecc12df 114 this->m_value = "";
sam_grove 2:853f9ecc12df 115 }
sam_grove 2:853f9ecc12df 116
sam_grove 2:853f9ecc12df 117 Logger *m_logger;
sam_grove 2:853f9ecc12df 118 void *m_endpoint;
sam_grove 2:853f9ecc12df 119 string m_name;
sam_grove 2:853f9ecc12df 120 InnerType m_value;
sam_grove 2:853f9ecc12df 121 };
sam_grove 2:853f9ecc12df 122
sam_grove 2:853f9ecc12df 123 #endif // __RESOURCE_H__