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.
Fork of mbedConnectorInterface by
DynamicResource.h
00001 /** 00002 * @file DynamicResource.h 00003 * @brief mbed CoAP Endpoint Dynamic Resource class 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 __DYNAMIC_RESOURCE_H__ 00024 #define __DYNAMIC_RESOURCE_H__ 00025 00026 // Base Class 00027 #include "Resource.h" 00028 00029 // NSDL Support 00030 #include "nsdl_support.h" 00031 00032 // DataWrapper support 00033 #include "DataWrapper.h" 00034 00035 /** DynamicResource class 00036 */ 00037 class DynamicResource : public Resource<string> 00038 { 00039 public: 00040 /** 00041 Default constructor (char strings) 00042 @param logger input logger instance for this resource 00043 @param name input the Resource URI/Name 00044 @param res_type input type for the Resource 00045 @param res_mask input the resource enablement mask (GET, PUT, etc...) 00046 @param observable input the resource is Observable (default: FALSE) 00047 */ 00048 DynamicResource(const Logger *logger,const char *name,const char *res_type,uint8_t res_mask,const bool observable = false); 00049 00050 /** 00051 Default constructor (char strings) 00052 @param logger input logger instance for this resource 00053 @param name input the Resource URI/Name 00054 @param res_type input type for the Resource 00055 @param value input initial value for the Resource 00056 @param res_mask input the resource enablement mask (GET, PUT, etc...) 00057 @param observable input the resource is Observable (default: FALSE) 00058 */ 00059 DynamicResource(const Logger *logger,const char *name,const char *res_type,const string value,uint8_t res_mask,const bool observable = false); 00060 00061 /** 00062 constructor with string buffer for name 00063 @param logger input logger instance for this resource 00064 @param name input the Resource URI/Name 00065 @param res_type input type for the Resource 00066 @param value input initial value for the Resource 00067 @param res_mask input the resource enablement mask (GET, PUT, etc...) 00068 @param observable input the resource is Observable (default: FALSE) 00069 */ 00070 DynamicResource(const Logger *logger,const string name,const string res_type,const string value,uint8_t res_mask,const bool observable = false); 00071 00072 /** 00073 Copy constructor 00074 @param resource input the DynamicResource that is to be deep copied 00075 */ 00076 DynamicResource(const DynamicResource &resource); 00077 00078 /** 00079 Destructor 00080 */ 00081 virtual ~DynamicResource(); 00082 00083 /** 00084 Bind resource to endpoint 00085 @param p input pointer to the endpoint resources necessary for binding 00086 */ 00087 virtual void bind(void *p); 00088 00089 /** 00090 Process the CoAP message 00091 @param received_coap_ptr input the received coap pointer 00092 @param address input the NSDL address pointer 00093 @param proto input the NSDL protocol pointer 00094 @return 0 - success, 1 - failure 00095 */ 00096 uint8_t process(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto); 00097 00098 /** 00099 Resource value getter (REQUIRED: must be implemented in derived class as all Binders MUST support and implement GET) 00100 @returns string value of the resource 00101 */ 00102 virtual string get() = 0; 00103 00104 /** 00105 Resource value setter (PUT) (OPTIONAL: defaulted noop if not derived. Binders MAY implement PUT if needed) 00106 @param string value of the resource 00107 */ 00108 virtual void put(const string value); 00109 00110 /** 00111 Resource value setter (POST) (OPTIONAL: defaulted noop if not derived. Binders MAY implement POST if needed) 00112 @param string value of the resource 00113 */ 00114 virtual void post(const string value); 00115 00116 /** 00117 Resource value deleter (OPTIONAL: defaulted noop if not derived. Binders MAY implement DELETE if needed) 00118 @param string value of the resource 00119 */ 00120 virtual void del(const string value); 00121 00122 /** 00123 Send notification of new data 00124 @param data input the new data to update 00125 @returns 1 - success, 0 - failure 00126 */ 00127 int notify(const string data); 00128 00129 /** 00130 Determine whether this dynamic resource is observable or not 00131 @returns true - is observable, false - otherwise 00132 */ 00133 bool isObservable() { return this->m_observable; } 00134 00135 /** 00136 Set the observer pointer 00137 @param observer input the pointer to the ResourceObserver observing this resource 00138 */ 00139 void setObserver(void *observer); 00140 00141 /** 00142 Set the content format for responses 00143 @param content_format short integer CoAP content-format ID 00144 */ 00145 void setContentFormat(uint8_t content_format); 00146 00147 /** 00148 Set the max-age for cache control of responses in a proxy cache 00149 @param maxage short integer CoAP max-age in seconds 00150 */ 00151 void setMaxAge(uint8_t maxage); 00152 00153 /** 00154 Set the data wrapper 00155 @param data_wrapper input the data wrapper instance 00156 */ 00157 void setDataWrapper(DataWrapper *data_wrapper) { this->m_data_wrapper = data_wrapper; } 00158 00159 /** 00160 observe the resource 00161 */ 00162 virtual void observe(); 00163 00164 protected: 00165 int notify(uint8_t *data,int data_length); 00166 DataWrapper *getDataWrapper() { return this->m_data_wrapper; } 00167 bool m_observable; 00168 00169 private: 00170 00171 string m_res_type; 00172 uint8_t m_res_mask; 00173 uint8_t m_obs_number; 00174 uint8_t *m_obs_token_ptr; 00175 uint8_t m_obs_token_len; 00176 DataWrapper *m_data_wrapper; 00177 void *m_observer; 00178 uint8_t m_maxage; 00179 uint8_t m_content_format; 00180 00181 // convenience method to create a string from the NSDL CoAP data buffers... 00182 string coapDataToString(uint8_t *coap_data_ptr,int coap_data_ptr_length); 00183 }; 00184 00185 #endif // __DYNAMIC_RESOURCE_H__
Generated on Wed Jul 13 2022 02:58:57 by
1.7.2
