mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface
Embed:
(wiki syntax)
Show/hide line numbers
Resource.h
Go to the documentation of this file.
00001 /** 00002 * @file Resource.h 00003 * @brief mbed CoAP Endpoint Resource base class template 00004 * @author Doug Anson/Chris Paola 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 #ifndef __RESOURCE_H__ 00024 #define __RESOURCE_H__ 00025 00026 // logging facility 00027 #include "mbed-connector-interface/Logger.h" 00028 00029 // mbed-client support 00030 #include "mbed-client/m2minterfacefactory.h" 00031 #include "mbed-client/m2mdevice.h" 00032 #include "mbed-client/m2minterfaceobserver.h" 00033 #include "mbed-client/m2minterface.h" 00034 #include "mbed-client/m2mobjectinstance.h" 00035 #include "mbed-client/m2mresource.h" 00036 00037 // string support 00038 #include <string> 00039 00040 /** Resource class 00041 */ 00042 template <typename InnerType> class Resource 00043 { 00044 public: 00045 /** 00046 Default constructor 00047 @param logger input the Logger instance this Resource is a part of 00048 @param obj_name input the Object Name 00049 @param res_name input the Resource URI/Name 00050 @param value input the Resource value 00051 */ 00052 Resource(const Logger *logger,const string obj_name,const string res_name,InnerType value) { 00053 this->init(logger); 00054 this->m_obj_name = obj_name; 00055 this->m_res_name = res_name; 00056 this->m_value = value; 00057 this->m_implements_observation = false; 00058 } 00059 00060 /** 00061 Copy constructor 00062 @param resource input the Resource that is to be deep copied 00063 */ 00064 Resource(const Resource<InnerType> &resource) { 00065 this->init(resource.m_logger); 00066 this->m_endpoint = resource.m_endpoint; 00067 this->m_obj_name = resource.m_obj_name; 00068 this->m_res_name = resource.m_res_name; 00069 this->m_value = resource.m_value; 00070 this->m_implements_observation = resource.m_implements_observation; 00071 } 00072 00073 /** 00074 Destructor 00075 */ 00076 virtual ~Resource() { 00077 } 00078 00079 /** 00080 Get the Object name 00081 @return the name of the object 00082 */ 00083 string getObjName() { 00084 return this->m_obj_name; 00085 } 00086 00087 /** 00088 Get the Resource name 00089 @return the name of the resource 00090 */ 00091 string getResName() { 00092 return this->m_res_name; 00093 } 00094 00095 /** 00096 Get the Full name 00097 @return the name of the object 00098 */ 00099 string getFullName() { 00100 return this->m_obj_name + "/*/" + this->m_res_name; 00101 } 00102 00103 /** 00104 Get the resource value 00105 @return the value of the resource 00106 */ 00107 InnerType getValue() { 00108 return this->m_value; 00109 } 00110 00111 /** 00112 Set the resource name 00113 @param name input the resource name 00114 */ 00115 void setName(const string name) { 00116 this->m_name = name; 00117 } 00118 00119 /** 00120 Set the resource value 00121 @param value input the resource value 00122 */ 00123 void setValue(const InnerType value) { 00124 this->m_value = value; 00125 } 00126 00127 /** 00128 Bind resource to endpoint 00129 */ 00130 virtual M2MObject *bind(void *p) = 0; 00131 00132 // access the logger() 00133 Logger *logger() { 00134 return this->m_logger; 00135 } 00136 00137 /** 00138 set the options 00139 */ 00140 void setOptions(const void *options) { 00141 this->m_options = (void *)options; 00142 } 00143 00144 /** 00145 set the endpoint 00146 */ 00147 void setEndpoint(const void *endpoint) { 00148 this->m_endpoint = (void *)endpoint; 00149 } 00150 00151 // this resource implements its own observation handler 00152 bool implementsObservation() { return this->m_implements_observation; } 00153 00154 protected: 00155 // initialize internals to Resource 00156 void init(const Logger *logger) { 00157 this->m_logger = (Logger *)logger; 00158 this->m_endpoint = NULL; 00159 this->m_obj_name = ""; 00160 this->m_res_name = ""; 00161 this->m_value = ""; 00162 } 00163 00164 // get our options 00165 void *getOptions() { 00166 return this->m_options; 00167 } 00168 00169 Logger *m_logger; 00170 void *m_endpoint; 00171 string m_obj_name; 00172 string m_res_name; 00173 InnerType m_value; 00174 bool m_implements_observation; 00175 void *m_options; 00176 }; 00177 00178 #endif // __RESOURCE_H__ 00179
Generated on Wed Jul 13 2022 21:59:32 by
1.7.2