mbed Connector Interface simplification API on top of mbed-client

Fork of mbedConnectorInterfaceV3 by Doug Anson

NOTE:

This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!

Committer:
ansond
Date:
Tue Jun 14 04:01:34 2016 +0000
Revision:
27:b8aaf7dc7023
Parent:
18:996d04762f32
Child:
33:1d0b855df5a5
Initial merge and update of device and firmware objects

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:1f1f55e73248 1 /**
ansond 0:1f1f55e73248 2 * @file Resource.h
ansond 0:1f1f55e73248 3 * @brief mbed CoAP Endpoint Resource base class template
ansond 0:1f1f55e73248 4 * @author Doug Anson/Chris Paola
ansond 0:1f1f55e73248 5 * @version 1.0
ansond 0:1f1f55e73248 6 * @see
ansond 0:1f1f55e73248 7 *
ansond 0:1f1f55e73248 8 * Copyright (c) 2014
ansond 0:1f1f55e73248 9 *
ansond 0:1f1f55e73248 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 0:1f1f55e73248 11 * you may not use this file except in compliance with the License.
ansond 0:1f1f55e73248 12 * You may obtain a copy of the License at
ansond 0:1f1f55e73248 13 *
ansond 0:1f1f55e73248 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 0:1f1f55e73248 15 *
ansond 0:1f1f55e73248 16 * Unless required by applicable law or agreed to in writing, software
ansond 0:1f1f55e73248 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 0:1f1f55e73248 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 0:1f1f55e73248 19 * See the License for the specific language governing permissions and
ansond 0:1f1f55e73248 20 * limitations under the License.
ansond 0:1f1f55e73248 21 */
ansond 0:1f1f55e73248 22
ansond 0:1f1f55e73248 23 #ifndef __RESOURCE_H__
ansond 0:1f1f55e73248 24 #define __RESOURCE_H__
ansond 0:1f1f55e73248 25
ansond 0:1f1f55e73248 26 // logging facility
ansond 0:1f1f55e73248 27 #include "mbed-connector-interface/Logger.h"
ansond 0:1f1f55e73248 28
ansond 0:1f1f55e73248 29 // mbed-client support
ansond 0:1f1f55e73248 30 #include "mbed-client/m2minterfacefactory.h"
ansond 0:1f1f55e73248 31 #include "mbed-client/m2mdevice.h"
ansond 0:1f1f55e73248 32 #include "mbed-client/m2minterfaceobserver.h"
ansond 0:1f1f55e73248 33 #include "mbed-client/m2minterface.h"
ansond 0:1f1f55e73248 34 #include "mbed-client/m2mobjectinstance.h"
ansond 0:1f1f55e73248 35 #include "mbed-client/m2mresource.h"
ansond 0:1f1f55e73248 36
ansond 0:1f1f55e73248 37 // string support
ansond 0:1f1f55e73248 38 #include <string>
ansond 0:1f1f55e73248 39
ansond 0:1f1f55e73248 40 /** Resource class
ansond 0:1f1f55e73248 41 */
ansond 0:1f1f55e73248 42 template <typename InnerType> class Resource
ansond 0:1f1f55e73248 43 {
ansond 0:1f1f55e73248 44 public:
ansond 27:b8aaf7dc7023 45 // Available Resource Types
ansond 27:b8aaf7dc7023 46 typedef enum {
ansond 27:b8aaf7dc7023 47 STRING,
ansond 27:b8aaf7dc7023 48 INTEGER,
ansond 27:b8aaf7dc7023 49 FLOAT,
ansond 27:b8aaf7dc7023 50 BOOLEAN,
ansond 27:b8aaf7dc7023 51 OPAQUE,
ansond 27:b8aaf7dc7023 52 TIME,
ansond 27:b8aaf7dc7023 53 OBJLINK
ansond 27:b8aaf7dc7023 54 }ResourceType;
ansond 27:b8aaf7dc7023 55
ansond 0:1f1f55e73248 56 /**
ansond 0:1f1f55e73248 57 Default constructor
ansond 0:1f1f55e73248 58 @param logger input the Logger instance this Resource is a part of
ansond 0:1f1f55e73248 59 @param obj_name input the Object Name
ansond 0:1f1f55e73248 60 @param res_name input the Resource URI/Name
ansond 0:1f1f55e73248 61 @param value input the Resource value
ansond 0:1f1f55e73248 62 */
ansond 0:1f1f55e73248 63 Resource(const Logger *logger,const string obj_name,const string res_name,InnerType value) {
ansond 0:1f1f55e73248 64 this->init(logger);
ansond 0:1f1f55e73248 65 this->m_obj_name = obj_name;
ansond 0:1f1f55e73248 66 this->m_res_name = res_name;
ansond 0:1f1f55e73248 67 this->m_value = value;
ansond 0:1f1f55e73248 68 this->m_implements_observation = false;
ansond 0:1f1f55e73248 69 }
ansond 0:1f1f55e73248 70
ansond 0:1f1f55e73248 71 /**
ansond 0:1f1f55e73248 72 Copy constructor
ansond 0:1f1f55e73248 73 @param resource input the Resource that is to be deep copied
ansond 0:1f1f55e73248 74 */
ansond 0:1f1f55e73248 75 Resource(const Resource<InnerType> &resource) {
ansond 0:1f1f55e73248 76 this->init(resource.m_logger);
ansond 0:1f1f55e73248 77 this->m_endpoint = resource.m_endpoint;
ansond 0:1f1f55e73248 78 this->m_obj_name = resource.m_obj_name;
ansond 0:1f1f55e73248 79 this->m_res_name = resource.m_res_name;
ansond 0:1f1f55e73248 80 this->m_value = resource.m_value;
ansond 0:1f1f55e73248 81 this->m_implements_observation = resource.m_implements_observation;
ansond 0:1f1f55e73248 82 }
ansond 0:1f1f55e73248 83
ansond 0:1f1f55e73248 84 /**
ansond 0:1f1f55e73248 85 Destructor
ansond 0:1f1f55e73248 86 */
ansond 0:1f1f55e73248 87 virtual ~Resource() {
ansond 0:1f1f55e73248 88 }
ansond 0:1f1f55e73248 89
ansond 0:1f1f55e73248 90 /**
ansond 0:1f1f55e73248 91 Get the Object name
ansond 0:1f1f55e73248 92 @return the name of the object
ansond 0:1f1f55e73248 93 */
ansond 0:1f1f55e73248 94 string getObjName() {
ansond 0:1f1f55e73248 95 return this->m_obj_name;
ansond 0:1f1f55e73248 96 }
ansond 0:1f1f55e73248 97
ansond 0:1f1f55e73248 98 /**
ansond 0:1f1f55e73248 99 Get the Resource name
ansond 0:1f1f55e73248 100 @return the name of the resource
ansond 0:1f1f55e73248 101 */
ansond 0:1f1f55e73248 102 string getResName() {
ansond 0:1f1f55e73248 103 return this->m_res_name;
ansond 0:1f1f55e73248 104 }
ansond 0:1f1f55e73248 105
ansond 0:1f1f55e73248 106 /**
ansond 0:1f1f55e73248 107 Get the Full name
ansond 0:1f1f55e73248 108 @return the name of the object
ansond 0:1f1f55e73248 109 */
ansond 0:1f1f55e73248 110 string getFullName() {
ansond 0:1f1f55e73248 111 return this->m_obj_name + "/*/" + this->m_res_name;
ansond 0:1f1f55e73248 112 }
ansond 0:1f1f55e73248 113
ansond 0:1f1f55e73248 114 /**
ansond 0:1f1f55e73248 115 Get the resource value
ansond 0:1f1f55e73248 116 @return the value of the resource
ansond 0:1f1f55e73248 117 */
ansond 0:1f1f55e73248 118 InnerType getValue() {
ansond 0:1f1f55e73248 119 return this->m_value;
ansond 0:1f1f55e73248 120 }
ansond 0:1f1f55e73248 121
ansond 0:1f1f55e73248 122 /**
ansond 0:1f1f55e73248 123 Set the resource name
ansond 0:1f1f55e73248 124 @param name input the resource name
ansond 0:1f1f55e73248 125 */
ansond 0:1f1f55e73248 126 void setName(const string name) {
ansond 0:1f1f55e73248 127 this->m_name = name;
ansond 0:1f1f55e73248 128 }
ansond 0:1f1f55e73248 129
ansond 0:1f1f55e73248 130 /**
ansond 0:1f1f55e73248 131 Set the resource value
ansond 0:1f1f55e73248 132 @param value input the resource value
ansond 0:1f1f55e73248 133 */
ansond 0:1f1f55e73248 134 void setValue(const InnerType value) {
ansond 0:1f1f55e73248 135 this->m_value = value;
ansond 0:1f1f55e73248 136 }
ansond 0:1f1f55e73248 137
ansond 0:1f1f55e73248 138 /**
ansond 0:1f1f55e73248 139 Bind resource to endpoint
ansond 27:b8aaf7dc7023 140 @param ep input pointer to the Endpoint instance
ansond 0:1f1f55e73248 141 */
ansond 27:b8aaf7dc7023 142 virtual void bind(void *ep) = 0;
ansond 0:1f1f55e73248 143
ansond 0:1f1f55e73248 144 // access the logger()
ansond 0:1f1f55e73248 145 Logger *logger() {
ansond 0:1f1f55e73248 146 return this->m_logger;
ansond 0:1f1f55e73248 147 }
ansond 0:1f1f55e73248 148
ansond 0:1f1f55e73248 149 /**
ansond 0:1f1f55e73248 150 set the options
ansond 0:1f1f55e73248 151 */
ansond 0:1f1f55e73248 152 void setOptions(const void *options) {
ansond 0:1f1f55e73248 153 this->m_options = (void *)options;
ansond 0:1f1f55e73248 154 }
ansond 18:996d04762f32 155
ansond 18:996d04762f32 156 /**
ansond 18:996d04762f32 157 set the endpoint
ansond 18:996d04762f32 158 */
ansond 18:996d04762f32 159 void setEndpoint(const void *endpoint) {
ansond 18:996d04762f32 160 this->m_endpoint = (void *)endpoint;
ansond 18:996d04762f32 161 }
ansond 0:1f1f55e73248 162
ansond 0:1f1f55e73248 163 // this resource implements its own observation handler
ansond 0:1f1f55e73248 164 bool implementsObservation() { return this->m_implements_observation; }
ansond 0:1f1f55e73248 165
ansond 0:1f1f55e73248 166 protected:
ansond 0:1f1f55e73248 167 // initialize internals to Resource
ansond 0:1f1f55e73248 168 void init(const Logger *logger) {
ansond 0:1f1f55e73248 169 this->m_logger = (Logger *)logger;
ansond 0:1f1f55e73248 170 this->m_endpoint = NULL;
ansond 0:1f1f55e73248 171 this->m_obj_name = "";
ansond 0:1f1f55e73248 172 this->m_res_name = "";
ansond 0:1f1f55e73248 173 this->m_value = "";
ansond 0:1f1f55e73248 174 }
ansond 0:1f1f55e73248 175
ansond 0:1f1f55e73248 176 // get our options
ansond 0:1f1f55e73248 177 void *getOptions() {
ansond 0:1f1f55e73248 178 return this->m_options;
ansond 0:1f1f55e73248 179 }
ansond 0:1f1f55e73248 180
ansond 17:defb680f8fce 181 Logger *m_logger;
ansond 0:1f1f55e73248 182 void *m_endpoint;
ansond 0:1f1f55e73248 183 string m_obj_name;
ansond 0:1f1f55e73248 184 string m_res_name;
ansond 17:defb680f8fce 185 InnerType m_value;
ansond 17:defb680f8fce 186 bool m_implements_observation;
ansond 17:defb680f8fce 187 void *m_options;
ansond 0:1f1f55e73248 188 };
ansond 0:1f1f55e73248 189
ansond 0:1f1f55e73248 190 #endif // __RESOURCE_H__
ansond 0:1f1f55e73248 191