use TCP to connect to mbed connector

Fork of mbedConnectorInterfaceWithDM by Doug Anson

Committer:
ansond
Date:
Tue Jun 14 19:29:30 2016 +0000
Revision:
33:1d0b855df5a5
Parent:
27:b8aaf7dc7023
Child:
45:db754b994deb
updated and unified headers

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/m2minterfaceobserver.h"
ansond 0:1f1f55e73248 32 #include "mbed-client/m2minterface.h"
ansond 0:1f1f55e73248 33 #include "mbed-client/m2mobjectinstance.h"
ansond 0:1f1f55e73248 34 #include "mbed-client/m2mresource.h"
ansond 33:1d0b855df5a5 35 #include "mbed-client/m2mdevice.h"
ansond 33:1d0b855df5a5 36 #include "mbed-client/m2mfirmware.h"
ansond 0:1f1f55e73248 37
ansond 0:1f1f55e73248 38 // string support
ansond 0:1f1f55e73248 39 #include <string>
ansond 0:1f1f55e73248 40
ansond 0:1f1f55e73248 41 /** Resource class
ansond 0:1f1f55e73248 42 */
ansond 0:1f1f55e73248 43 template <typename InnerType> class Resource
ansond 0:1f1f55e73248 44 {
ansond 0:1f1f55e73248 45 public:
ansond 27:b8aaf7dc7023 46 // Available Resource Types
ansond 27:b8aaf7dc7023 47 typedef enum {
ansond 27:b8aaf7dc7023 48 STRING,
ansond 27:b8aaf7dc7023 49 INTEGER,
ansond 27:b8aaf7dc7023 50 FLOAT,
ansond 27:b8aaf7dc7023 51 BOOLEAN,
ansond 27:b8aaf7dc7023 52 OPAQUE,
ansond 27:b8aaf7dc7023 53 TIME,
ansond 27:b8aaf7dc7023 54 OBJLINK
ansond 27:b8aaf7dc7023 55 }ResourceType;
ansond 27:b8aaf7dc7023 56
ansond 0:1f1f55e73248 57 /**
ansond 0:1f1f55e73248 58 Default constructor
ansond 0:1f1f55e73248 59 @param logger input the Logger instance this Resource is a part of
ansond 0:1f1f55e73248 60 @param obj_name input the Object Name
ansond 0:1f1f55e73248 61 @param res_name input the Resource URI/Name
ansond 0:1f1f55e73248 62 @param value input the Resource value
ansond 0:1f1f55e73248 63 */
ansond 0:1f1f55e73248 64 Resource(const Logger *logger,const string obj_name,const string res_name,InnerType value) {
ansond 0:1f1f55e73248 65 this->init(logger);
ansond 0:1f1f55e73248 66 this->m_obj_name = obj_name;
ansond 0:1f1f55e73248 67 this->m_res_name = res_name;
ansond 0:1f1f55e73248 68 this->m_value = value;
ansond 0:1f1f55e73248 69 this->m_implements_observation = false;
ansond 0:1f1f55e73248 70 }
ansond 0:1f1f55e73248 71
ansond 0:1f1f55e73248 72 /**
ansond 0:1f1f55e73248 73 Copy constructor
ansond 0:1f1f55e73248 74 @param resource input the Resource that is to be deep copied
ansond 0:1f1f55e73248 75 */
ansond 0:1f1f55e73248 76 Resource(const Resource<InnerType> &resource) {
ansond 0:1f1f55e73248 77 this->init(resource.m_logger);
ansond 0:1f1f55e73248 78 this->m_endpoint = resource.m_endpoint;
ansond 0:1f1f55e73248 79 this->m_obj_name = resource.m_obj_name;
ansond 0:1f1f55e73248 80 this->m_res_name = resource.m_res_name;
ansond 0:1f1f55e73248 81 this->m_value = resource.m_value;
ansond 0:1f1f55e73248 82 this->m_implements_observation = resource.m_implements_observation;
ansond 0:1f1f55e73248 83 }
ansond 0:1f1f55e73248 84
ansond 0:1f1f55e73248 85 /**
ansond 0:1f1f55e73248 86 Destructor
ansond 0:1f1f55e73248 87 */
ansond 0:1f1f55e73248 88 virtual ~Resource() {
ansond 0:1f1f55e73248 89 }
ansond 0:1f1f55e73248 90
ansond 0:1f1f55e73248 91 /**
ansond 0:1f1f55e73248 92 Get the Object name
ansond 0:1f1f55e73248 93 @return the name of the object
ansond 0:1f1f55e73248 94 */
ansond 0:1f1f55e73248 95 string getObjName() {
ansond 0:1f1f55e73248 96 return this->m_obj_name;
ansond 0:1f1f55e73248 97 }
ansond 0:1f1f55e73248 98
ansond 0:1f1f55e73248 99 /**
ansond 0:1f1f55e73248 100 Get the Resource name
ansond 0:1f1f55e73248 101 @return the name of the resource
ansond 0:1f1f55e73248 102 */
ansond 0:1f1f55e73248 103 string getResName() {
ansond 0:1f1f55e73248 104 return this->m_res_name;
ansond 0:1f1f55e73248 105 }
ansond 0:1f1f55e73248 106
ansond 0:1f1f55e73248 107 /**
ansond 0:1f1f55e73248 108 Get the Full name
ansond 0:1f1f55e73248 109 @return the name of the object
ansond 0:1f1f55e73248 110 */
ansond 0:1f1f55e73248 111 string getFullName() {
ansond 0:1f1f55e73248 112 return this->m_obj_name + "/*/" + this->m_res_name;
ansond 0:1f1f55e73248 113 }
ansond 0:1f1f55e73248 114
ansond 0:1f1f55e73248 115 /**
ansond 0:1f1f55e73248 116 Get the resource value
ansond 0:1f1f55e73248 117 @return the value of the resource
ansond 0:1f1f55e73248 118 */
ansond 0:1f1f55e73248 119 InnerType getValue() {
ansond 0:1f1f55e73248 120 return this->m_value;
ansond 0:1f1f55e73248 121 }
ansond 0:1f1f55e73248 122
ansond 0:1f1f55e73248 123 /**
ansond 0:1f1f55e73248 124 Set the resource name
ansond 0:1f1f55e73248 125 @param name input the resource name
ansond 0:1f1f55e73248 126 */
ansond 0:1f1f55e73248 127 void setName(const string name) {
ansond 0:1f1f55e73248 128 this->m_name = name;
ansond 0:1f1f55e73248 129 }
ansond 0:1f1f55e73248 130
ansond 0:1f1f55e73248 131 /**
ansond 0:1f1f55e73248 132 Set the resource value
ansond 0:1f1f55e73248 133 @param value input the resource value
ansond 0:1f1f55e73248 134 */
ansond 0:1f1f55e73248 135 void setValue(const InnerType value) {
ansond 0:1f1f55e73248 136 this->m_value = value;
ansond 0:1f1f55e73248 137 }
ansond 0:1f1f55e73248 138
ansond 0:1f1f55e73248 139 /**
ansond 0:1f1f55e73248 140 Bind resource to endpoint
ansond 27:b8aaf7dc7023 141 @param ep input pointer to the Endpoint instance
ansond 0:1f1f55e73248 142 */
ansond 27:b8aaf7dc7023 143 virtual void bind(void *ep) = 0;
ansond 0:1f1f55e73248 144
ansond 0:1f1f55e73248 145 // access the logger()
ansond 0:1f1f55e73248 146 Logger *logger() {
ansond 0:1f1f55e73248 147 return this->m_logger;
ansond 0:1f1f55e73248 148 }
ansond 0:1f1f55e73248 149
ansond 0:1f1f55e73248 150 /**
ansond 0:1f1f55e73248 151 set the options
ansond 0:1f1f55e73248 152 */
ansond 0:1f1f55e73248 153 void setOptions(const void *options) {
ansond 0:1f1f55e73248 154 this->m_options = (void *)options;
ansond 0:1f1f55e73248 155 }
ansond 18:996d04762f32 156
ansond 18:996d04762f32 157 /**
ansond 18:996d04762f32 158 set the endpoint
ansond 18:996d04762f32 159 */
ansond 18:996d04762f32 160 void setEndpoint(const void *endpoint) {
ansond 18:996d04762f32 161 this->m_endpoint = (void *)endpoint;
ansond 18:996d04762f32 162 }
ansond 0:1f1f55e73248 163
ansond 0:1f1f55e73248 164 // this resource implements its own observation handler
ansond 0:1f1f55e73248 165 bool implementsObservation() { return this->m_implements_observation; }
ansond 0:1f1f55e73248 166
ansond 0:1f1f55e73248 167 protected:
ansond 0:1f1f55e73248 168 // initialize internals to Resource
ansond 0:1f1f55e73248 169 void init(const Logger *logger) {
ansond 0:1f1f55e73248 170 this->m_logger = (Logger *)logger;
ansond 0:1f1f55e73248 171 this->m_endpoint = NULL;
ansond 0:1f1f55e73248 172 this->m_obj_name = "";
ansond 0:1f1f55e73248 173 this->m_res_name = "";
ansond 0:1f1f55e73248 174 this->m_value = "";
ansond 0:1f1f55e73248 175 }
ansond 0:1f1f55e73248 176
ansond 0:1f1f55e73248 177 // get our options
ansond 0:1f1f55e73248 178 void *getOptions() {
ansond 0:1f1f55e73248 179 return this->m_options;
ansond 0:1f1f55e73248 180 }
ansond 0:1f1f55e73248 181
ansond 17:defb680f8fce 182 Logger *m_logger;
ansond 0:1f1f55e73248 183 void *m_endpoint;
ansond 0:1f1f55e73248 184 string m_obj_name;
ansond 0:1f1f55e73248 185 string m_res_name;
ansond 17:defb680f8fce 186 InnerType m_value;
ansond 17:defb680f8fce 187 bool m_implements_observation;
ansond 17:defb680f8fce 188 void *m_options;
ansond 0:1f1f55e73248 189 };
ansond 0:1f1f55e73248 190
ansond 0:1f1f55e73248 191 #endif // __RESOURCE_H__
ansond 0:1f1f55e73248 192