Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: IoT_LED_demo ServoTest uWater_Project hackathon ... more
Resource.h
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 "Logger.h" 00028 00029 // string support 00030 #include <string> 00031 00032 /** Resource class 00033 */ 00034 template <typename InnerType> class Resource 00035 { 00036 public: 00037 /** 00038 Default constructor 00039 @param logger input the Logger instance this Resource is a part of 00040 @param name input the Resource URI/Name 00041 @param value input the Resource value 00042 */ 00043 Resource(const Logger *logger,const string name,InnerType value) { 00044 this->init(logger); 00045 this->m_name = name; 00046 this->m_value = value; 00047 this->m_implements_observation = false; 00048 } 00049 00050 /** 00051 Copy constructor 00052 @param resource input the Resource that is to be deep copied 00053 */ 00054 Resource(const Resource<InnerType> &resource) { 00055 this->init(resource.m_logger); 00056 this->m_endpoint = resource.m_endpoint; 00057 this->m_name = resource.m_name; 00058 this->m_value = resource.m_value; 00059 this->m_implements_observation = resource.m_implements_observation; 00060 } 00061 00062 /** 00063 Destructor 00064 */ 00065 virtual ~Resource() { 00066 } 00067 00068 /** 00069 Get the resource name 00070 @return the name of the resource 00071 */ 00072 string getName() { 00073 return this->m_name; 00074 } 00075 00076 /** 00077 Get the resource value 00078 @return the value of the resource 00079 */ 00080 InnerType getValue() { 00081 return this->m_value; 00082 } 00083 00084 /** 00085 Set the resource name 00086 @param name input the resource name 00087 */ 00088 void setName(const string name) { 00089 this->m_name = name; 00090 } 00091 00092 /** 00093 Set the resource value 00094 @param value input the resource value 00095 */ 00096 void setValue(const InnerType value) { 00097 this->m_value = value; 00098 } 00099 00100 /** 00101 Bind resource to endpoint 00102 */ 00103 virtual void bind(void *p) = 0; 00104 00105 // access the logger() 00106 Logger *logger() { 00107 return this->m_logger; 00108 } 00109 00110 /** 00111 set the options 00112 */ 00113 void setOptions(const void *options) { 00114 this->m_options = (void *)options; 00115 } 00116 00117 // this resource implements its own observation handler 00118 bool implementsObservation() { return this->m_implements_observation; } 00119 00120 protected: 00121 // initialize internals to Resource 00122 void init(const Logger *logger) { 00123 this->m_logger = (Logger *)logger; 00124 this->m_endpoint = NULL; 00125 this->m_name = ""; 00126 this->m_value = ""; 00127 } 00128 00129 // get our options 00130 void *getOptions() { 00131 return this->m_options; 00132 } 00133 00134 Logger *m_logger; 00135 void *m_endpoint; 00136 string m_name; 00137 InnerType m_value; 00138 bool m_implements_observation; 00139 void *m_options; 00140 }; 00141 00142 #endif // __RESOURCE_H__
Generated on Tue Jul 12 2022 15:15:35 by
1.7.2
