use TCP to connect to mbed connector

Fork of mbedConnectorInterfaceWithDM by Doug Anson

Committer:
ansond
Date:
Fri Feb 19 17:32:14 2016 +0000
Revision:
0:1f1f55e73248
Child:
17:defb680f8fce
initial checkin

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 0:1f1f55e73248 45 /**
ansond 0:1f1f55e73248 46 Default constructor
ansond 0:1f1f55e73248 47 @param logger input the Logger instance this Resource is a part of
ansond 0:1f1f55e73248 48 @param obj_name input the Object Name
ansond 0:1f1f55e73248 49 @param res_name input the Resource URI/Name
ansond 0:1f1f55e73248 50 @param value input the Resource value
ansond 0:1f1f55e73248 51 */
ansond 0:1f1f55e73248 52 Resource(const Logger *logger,const string obj_name,const string res_name,InnerType value) {
ansond 0:1f1f55e73248 53 this->init(logger);
ansond 0:1f1f55e73248 54 this->m_obj_name = obj_name;
ansond 0:1f1f55e73248 55 this->m_res_name = res_name;
ansond 0:1f1f55e73248 56 this->m_value = value;
ansond 0:1f1f55e73248 57 this->m_implements_observation = false;
ansond 0:1f1f55e73248 58 }
ansond 0:1f1f55e73248 59
ansond 0:1f1f55e73248 60 /**
ansond 0:1f1f55e73248 61 Copy constructor
ansond 0:1f1f55e73248 62 @param resource input the Resource that is to be deep copied
ansond 0:1f1f55e73248 63 */
ansond 0:1f1f55e73248 64 Resource(const Resource<InnerType> &resource) {
ansond 0:1f1f55e73248 65 this->init(resource.m_logger);
ansond 0:1f1f55e73248 66 this->m_endpoint = resource.m_endpoint;
ansond 0:1f1f55e73248 67 this->m_obj_name = resource.m_obj_name;
ansond 0:1f1f55e73248 68 this->m_res_name = resource.m_res_name;
ansond 0:1f1f55e73248 69 this->m_value = resource.m_value;
ansond 0:1f1f55e73248 70 this->m_implements_observation = resource.m_implements_observation;
ansond 0:1f1f55e73248 71 }
ansond 0:1f1f55e73248 72
ansond 0:1f1f55e73248 73 /**
ansond 0:1f1f55e73248 74 Destructor
ansond 0:1f1f55e73248 75 */
ansond 0:1f1f55e73248 76 virtual ~Resource() {
ansond 0:1f1f55e73248 77 }
ansond 0:1f1f55e73248 78
ansond 0:1f1f55e73248 79 /**
ansond 0:1f1f55e73248 80 Get the Object name
ansond 0:1f1f55e73248 81 @return the name of the object
ansond 0:1f1f55e73248 82 */
ansond 0:1f1f55e73248 83 string getObjName() {
ansond 0:1f1f55e73248 84 return this->m_obj_name;
ansond 0:1f1f55e73248 85 }
ansond 0:1f1f55e73248 86
ansond 0:1f1f55e73248 87 /**
ansond 0:1f1f55e73248 88 Get the Resource name
ansond 0:1f1f55e73248 89 @return the name of the resource
ansond 0:1f1f55e73248 90 */
ansond 0:1f1f55e73248 91 string getResName() {
ansond 0:1f1f55e73248 92 return this->m_res_name;
ansond 0:1f1f55e73248 93 }
ansond 0:1f1f55e73248 94
ansond 0:1f1f55e73248 95 /**
ansond 0:1f1f55e73248 96 Get the Full name
ansond 0:1f1f55e73248 97 @return the name of the object
ansond 0:1f1f55e73248 98 */
ansond 0:1f1f55e73248 99 string getFullName() {
ansond 0:1f1f55e73248 100 return this->m_obj_name + "/*/" + this->m_res_name;
ansond 0:1f1f55e73248 101 }
ansond 0:1f1f55e73248 102
ansond 0:1f1f55e73248 103 /**
ansond 0:1f1f55e73248 104 Get the resource value
ansond 0:1f1f55e73248 105 @return the value of the resource
ansond 0:1f1f55e73248 106 */
ansond 0:1f1f55e73248 107 InnerType getValue() {
ansond 0:1f1f55e73248 108 return this->m_value;
ansond 0:1f1f55e73248 109 }
ansond 0:1f1f55e73248 110
ansond 0:1f1f55e73248 111 /**
ansond 0:1f1f55e73248 112 Set the resource name
ansond 0:1f1f55e73248 113 @param name input the resource name
ansond 0:1f1f55e73248 114 */
ansond 0:1f1f55e73248 115 void setName(const string name) {
ansond 0:1f1f55e73248 116 this->m_name = name;
ansond 0:1f1f55e73248 117 }
ansond 0:1f1f55e73248 118
ansond 0:1f1f55e73248 119 /**
ansond 0:1f1f55e73248 120 Set the resource value
ansond 0:1f1f55e73248 121 @param value input the resource value
ansond 0:1f1f55e73248 122 */
ansond 0:1f1f55e73248 123 void setValue(const InnerType value) {
ansond 0:1f1f55e73248 124 this->m_value = value;
ansond 0:1f1f55e73248 125 }
ansond 0:1f1f55e73248 126
ansond 0:1f1f55e73248 127 /**
ansond 0:1f1f55e73248 128 Bind resource to endpoint
ansond 0:1f1f55e73248 129 */
ansond 0:1f1f55e73248 130 virtual M2MObject *bind(void *p) = 0;
ansond 0:1f1f55e73248 131
ansond 0:1f1f55e73248 132 // access the logger()
ansond 0:1f1f55e73248 133 Logger *logger() {
ansond 0:1f1f55e73248 134 return this->m_logger;
ansond 0:1f1f55e73248 135 }
ansond 0:1f1f55e73248 136
ansond 0:1f1f55e73248 137 /**
ansond 0:1f1f55e73248 138 set the options
ansond 0:1f1f55e73248 139 */
ansond 0:1f1f55e73248 140 void setOptions(const void *options) {
ansond 0:1f1f55e73248 141 this->m_options = (void *)options;
ansond 0:1f1f55e73248 142 }
ansond 0:1f1f55e73248 143
ansond 0:1f1f55e73248 144 // this resource implements its own observation handler
ansond 0:1f1f55e73248 145 bool implementsObservation() { return this->m_implements_observation; }
ansond 0:1f1f55e73248 146
ansond 0:1f1f55e73248 147 protected:
ansond 0:1f1f55e73248 148 // initialize internals to Resource
ansond 0:1f1f55e73248 149 void init(const Logger *logger) {
ansond 0:1f1f55e73248 150 this->m_logger = (Logger *)logger;
ansond 0:1f1f55e73248 151 this->m_endpoint = NULL;
ansond 0:1f1f55e73248 152 this->m_obj_name = "";
ansond 0:1f1f55e73248 153 this->m_res_name = "";
ansond 0:1f1f55e73248 154 this->m_value = "";
ansond 0:1f1f55e73248 155 }
ansond 0:1f1f55e73248 156
ansond 0:1f1f55e73248 157 // get our options
ansond 0:1f1f55e73248 158 void *getOptions() {
ansond 0:1f1f55e73248 159 return this->m_options;
ansond 0:1f1f55e73248 160 }
ansond 0:1f1f55e73248 161
ansond 0:1f1f55e73248 162 Logger *m_logger;
ansond 0:1f1f55e73248 163 void *m_endpoint;
ansond 0:1f1f55e73248 164 string m_obj_name;
ansond 0:1f1f55e73248 165 string m_res_name;
ansond 0:1f1f55e73248 166 InnerType m_value;
ansond 0:1f1f55e73248 167 bool m_implements_observation;
ansond 0:1f1f55e73248 168 void *m_options;
ansond 0:1f1f55e73248 169 };
ansond 0:1f1f55e73248 170
ansond 0:1f1f55e73248 171 #endif // __RESOURCE_H__
ansond 0:1f1f55e73248 172