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:
ansond
Date:
Tue Jan 27 22:23:51 2015 +0000
Revision:
0:b438482ebbfc
Child:
2:853f9ecc12df
initial check in

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
ansond 0:b438482ebbfc 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 */
ansond 0:b438482ebbfc 22
ansond 0:b438482ebbfc 23 #ifndef __RESOURCE_H__
ansond 0:b438482ebbfc 24 #define __RESOURCE_H__
ansond 0:b438482ebbfc 25
ansond 0:b438482ebbfc 26 // logging facility
ansond 0:b438482ebbfc 27 #include "Logger.h"
ansond 0:b438482ebbfc 28
ansond 0:b438482ebbfc 29 // string support
ansond 0:b438482ebbfc 30 #include <string>
ansond 0:b438482ebbfc 31
ansond 0:b438482ebbfc 32 template <typename InnerType> class Resource {
ansond 0:b438482ebbfc 33 public:
ansond 0:b438482ebbfc 34 /**
ansond 0:b438482ebbfc 35 Default constructor
ansond 0:b438482ebbfc 36 @param logger input the Logger instance this Resource is a part of
ansond 0:b438482ebbfc 37 @param name input the Resource URI/Name
ansond 0:b438482ebbfc 38 @param value input the Resource value
ansond 0:b438482ebbfc 39 */
ansond 0:b438482ebbfc 40 Resource(const Logger *logger,const string name,InnerType value) {
ansond 0:b438482ebbfc 41 this->init(logger);
ansond 0:b438482ebbfc 42 this->m_name = name;
ansond 0:b438482ebbfc 43 this->m_value = value;
ansond 0:b438482ebbfc 44 }
ansond 0:b438482ebbfc 45
ansond 0:b438482ebbfc 46 /**
ansond 0:b438482ebbfc 47 Copy constructor
ansond 0:b438482ebbfc 48 @param resource input the Resource that is to be deep copied
ansond 0:b438482ebbfc 49 */
ansond 0:b438482ebbfc 50 Resource(const Resource<InnerType> &resource) {
ansond 0:b438482ebbfc 51 this->init(resource.m_logger);
ansond 0:b438482ebbfc 52 this->m_endpoint = resource.m_endpoint;
ansond 0:b438482ebbfc 53 this->m_name = resource.m_name;
ansond 0:b438482ebbfc 54 this->m_value = resource.m_value;
ansond 0:b438482ebbfc 55 }
ansond 0:b438482ebbfc 56
ansond 0:b438482ebbfc 57 /**
ansond 0:b438482ebbfc 58 Destructor
ansond 0:b438482ebbfc 59 */
ansond 0:b438482ebbfc 60 virtual ~Resource() {
ansond 0:b438482ebbfc 61 }
ansond 0:b438482ebbfc 62
ansond 0:b438482ebbfc 63 /**
ansond 0:b438482ebbfc 64 Get the resource name
ansond 0:b438482ebbfc 65 @return the name of the resource
ansond 0:b438482ebbfc 66 */
ansond 0:b438482ebbfc 67 string getName() { return this->m_name; }
ansond 0:b438482ebbfc 68
ansond 0:b438482ebbfc 69 /**
ansond 0:b438482ebbfc 70 Get the resource value
ansond 0:b438482ebbfc 71 @return the value of the resource
ansond 0:b438482ebbfc 72 */
ansond 0:b438482ebbfc 73 InnerType getValue() { return this->m_value; }
ansond 0:b438482ebbfc 74
ansond 0:b438482ebbfc 75 /**
ansond 0:b438482ebbfc 76 Set the resource name
ansond 0:b438482ebbfc 77 @param name input the resource name
ansond 0:b438482ebbfc 78 */
ansond 0:b438482ebbfc 79 void setName(const string name) { this->m_name = name; }
ansond 0:b438482ebbfc 80
ansond 0:b438482ebbfc 81 /**
ansond 0:b438482ebbfc 82 Set the resource value
ansond 0:b438482ebbfc 83 @param value input the resource value
ansond 0:b438482ebbfc 84 */
ansond 0:b438482ebbfc 85 void setValue(const InnerType value) { this->m_value = value; }
ansond 0:b438482ebbfc 86
ansond 0:b438482ebbfc 87 /**
ansond 0:b438482ebbfc 88 Bind resource to endpoint
ansond 0:b438482ebbfc 89 */
ansond 0:b438482ebbfc 90 virtual void bind(void *p) = 0;
ansond 0:b438482ebbfc 91
ansond 0:b438482ebbfc 92 // access the logger()
ansond 0:b438482ebbfc 93 Logger *logger() { return this->m_logger; }
ansond 0:b438482ebbfc 94
ansond 0:b438482ebbfc 95 protected:
ansond 0:b438482ebbfc 96 // initialize internals to Resource
ansond 0:b438482ebbfc 97 void init(const Logger *logger) {
ansond 0:b438482ebbfc 98 this->m_logger = (Logger *)logger;
ansond 0:b438482ebbfc 99 this->m_endpoint = NULL;
ansond 0:b438482ebbfc 100 this->m_name = "";
ansond 0:b438482ebbfc 101 this->m_value = "";
ansond 0:b438482ebbfc 102 }
ansond 0:b438482ebbfc 103
ansond 0:b438482ebbfc 104 Logger *m_logger;
ansond 0:b438482ebbfc 105 void *m_endpoint;
ansond 0:b438482ebbfc 106 string m_name;
ansond 0:b438482ebbfc 107 InnerType m_value;
ansond 0:b438482ebbfc 108 };
ansond 0:b438482ebbfc 109
ansond 0:b438482ebbfc 110 #endif // __RESOURCE_H__