custom for >5 resources

Fork of mbedConnectorInterface by Doug Anson

Committer:
michaeljkoster
Date:
Tue Apr 14 04:00:01 2015 +0000
Revision:
52:822611156e35
Parent:
51:b308658817e5
Child:
53:458c2730e086
added interfaces for max-age and content-format

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:b438482ebbfc 1 /**
ansond 0:b438482ebbfc 2 * @file DynamicResource.h
ansond 0:b438482ebbfc 3 * @brief mbed CoAP Endpoint Dynamic Resource class
ansond 0:b438482ebbfc 4 * @author Doug Anson/Chris Paola
ansond 0:b438482ebbfc 5 * @version 1.0
sam_grove 2:853f9ecc12df 6 * @see
ansond 0:b438482ebbfc 7 *
ansond 0:b438482ebbfc 8 * Copyright (c) 2014
ansond 0:b438482ebbfc 9 *
ansond 0:b438482ebbfc 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 0:b438482ebbfc 11 * you may not use this file except in compliance with the License.
ansond 0:b438482ebbfc 12 * You may obtain a copy of the License at
ansond 0:b438482ebbfc 13 *
ansond 0:b438482ebbfc 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 0:b438482ebbfc 15 *
ansond 0:b438482ebbfc 16 * Unless required by applicable law or agreed to in writing, software
ansond 0:b438482ebbfc 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 0:b438482ebbfc 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 0:b438482ebbfc 19 * See the License for the specific language governing permissions and
ansond 0:b438482ebbfc 20 * limitations under the License.
ansond 0:b438482ebbfc 21 */
sam_grove 2:853f9ecc12df 22
sam_grove 2:853f9ecc12df 23 #ifndef __DYNAMIC_RESOURCE_H__
sam_grove 2:853f9ecc12df 24 #define __DYNAMIC_RESOURCE_H__
sam_grove 2:853f9ecc12df 25
sam_grove 2:853f9ecc12df 26 // Base Class
sam_grove 2:853f9ecc12df 27 #include "Resource.h"
sam_grove 2:853f9ecc12df 28
sam_grove 2:853f9ecc12df 29 // NSDL Support
sam_grove 2:853f9ecc12df 30 #include "nsdl_support.h"
sam_grove 2:853f9ecc12df 31
ansond 24:a6915e19814e 32 // DataWrapper support
ansond 24:a6915e19814e 33 #include "DataWrapper.h"
ansond 24:a6915e19814e 34
sam_grove 2:853f9ecc12df 35 /** DynamicResource class
sam_grove 2:853f9ecc12df 36 */
sam_grove 2:853f9ecc12df 37 class DynamicResource : public Resource<string>
sam_grove 2:853f9ecc12df 38 {
sam_grove 2:853f9ecc12df 39 public:
sam_grove 2:853f9ecc12df 40 /**
sam_grove 2:853f9ecc12df 41 Default constructor (char strings)
sam_grove 2:853f9ecc12df 42 @param logger input logger instance for this resource
sam_grove 2:853f9ecc12df 43 @param name input the Resource URI/Name
sam_grove 2:853f9ecc12df 44 @param res_type input type for the Resource
sam_grove 2:853f9ecc12df 45 @param res_mask input the resource enablement mask (GET, PUT, etc...)
sam_grove 2:853f9ecc12df 46 @param observable input the resource is Observable (default: FALSE)
sam_grove 2:853f9ecc12df 47 */
sam_grove 2:853f9ecc12df 48 DynamicResource(const Logger *logger,const char *name,const char *res_type,uint8_t res_mask,const bool observable = false);
sam_grove 2:853f9ecc12df 49
sam_grove 2:853f9ecc12df 50 /**
sam_grove 2:853f9ecc12df 51 Default constructor (char strings)
sam_grove 2:853f9ecc12df 52 @param logger input logger instance for this resource
sam_grove 2:853f9ecc12df 53 @param name input the Resource URI/Name
sam_grove 2:853f9ecc12df 54 @param res_type input type for the Resource
sam_grove 2:853f9ecc12df 55 @param value input initial value for the Resource
sam_grove 2:853f9ecc12df 56 @param res_mask input the resource enablement mask (GET, PUT, etc...)
sam_grove 2:853f9ecc12df 57 @param observable input the resource is Observable (default: FALSE)
sam_grove 2:853f9ecc12df 58 */
sam_grove 2:853f9ecc12df 59 DynamicResource(const Logger *logger,const char *name,const char *res_type,const string value,uint8_t res_mask,const bool observable = false);
sam_grove 2:853f9ecc12df 60
sam_grove 2:853f9ecc12df 61 /**
sam_grove 2:853f9ecc12df 62 constructor with string buffer for name
sam_grove 2:853f9ecc12df 63 @param logger input logger instance for this resource
sam_grove 2:853f9ecc12df 64 @param name input the Resource URI/Name
sam_grove 2:853f9ecc12df 65 @param res_type input type for the Resource
sam_grove 2:853f9ecc12df 66 @param value input initial value for the Resource
sam_grove 2:853f9ecc12df 67 @param res_mask input the resource enablement mask (GET, PUT, etc...)
sam_grove 2:853f9ecc12df 68 @param observable input the resource is Observable (default: FALSE)
sam_grove 2:853f9ecc12df 69 */
sam_grove 2:853f9ecc12df 70 DynamicResource(const Logger *logger,const string name,const string res_type,const string value,uint8_t res_mask,const bool observable = false);
ansond 0:b438482ebbfc 71
sam_grove 2:853f9ecc12df 72 /**
sam_grove 2:853f9ecc12df 73 Copy constructor
sam_grove 2:853f9ecc12df 74 @param resource input the DynamicResource that is to be deep copied
sam_grove 2:853f9ecc12df 75 */
sam_grove 2:853f9ecc12df 76 DynamicResource(const DynamicResource &resource);
sam_grove 2:853f9ecc12df 77
sam_grove 2:853f9ecc12df 78 /**
sam_grove 2:853f9ecc12df 79 Destructor
sam_grove 2:853f9ecc12df 80 */
sam_grove 2:853f9ecc12df 81 virtual ~DynamicResource();
sam_grove 2:853f9ecc12df 82
sam_grove 2:853f9ecc12df 83 /**
sam_grove 2:853f9ecc12df 84 Bind resource to endpoint
sam_grove 2:853f9ecc12df 85 @param p input pointer to the endpoint resources necessary for binding
sam_grove 2:853f9ecc12df 86 */
sam_grove 2:853f9ecc12df 87 virtual void bind(void *p);
sam_grove 2:853f9ecc12df 88
sam_grove 2:853f9ecc12df 89 /**
sam_grove 2:853f9ecc12df 90 Process the CoAP message
sam_grove 2:853f9ecc12df 91 @param received_coap_ptr input the received coap pointer
sam_grove 2:853f9ecc12df 92 @param address input the NSDL address pointer
sam_grove 2:853f9ecc12df 93 @param proto input the NSDL protocol pointer
sam_grove 2:853f9ecc12df 94 @return 0 - success, 1 - failure
sam_grove 2:853f9ecc12df 95 */
sam_grove 2:853f9ecc12df 96 uint8_t process(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto);
sam_grove 2:853f9ecc12df 97
sam_grove 2:853f9ecc12df 98 /**
sam_grove 2:853f9ecc12df 99 Resource value getter (REQUIRED: must be implemented in derived class as all Binders MUST support and implement GET)
sam_grove 2:853f9ecc12df 100 @returns string value of the resource
sam_grove 2:853f9ecc12df 101 */
sam_grove 2:853f9ecc12df 102 virtual string get() = 0;
sam_grove 2:853f9ecc12df 103
sam_grove 2:853f9ecc12df 104 /**
ansond 21:8487990a3baa 105 Resource value setter (PUT) (OPTIONAL: defaulted noop if not derived. Binders MAY implement PUT if needed)
sam_grove 2:853f9ecc12df 106 @param string value of the resource
sam_grove 2:853f9ecc12df 107 */
sam_grove 2:853f9ecc12df 108 virtual void put(const string value);
ansond 21:8487990a3baa 109
ansond 21:8487990a3baa 110 /**
ansond 21:8487990a3baa 111 Resource value setter (POST) (OPTIONAL: defaulted noop if not derived. Binders MAY implement POST if needed)
ansond 21:8487990a3baa 112 @param string value of the resource
ansond 21:8487990a3baa 113 */
ansond 21:8487990a3baa 114 virtual void post(const string value);
ansond 21:8487990a3baa 115
ansond 21:8487990a3baa 116 /**
ansond 21:8487990a3baa 117 Resource value deleter (OPTIONAL: defaulted noop if not derived. Binders MAY implement DELETE if needed)
ansond 21:8487990a3baa 118 @param string value of the resource
ansond 21:8487990a3baa 119 */
ansond 21:8487990a3baa 120 virtual void del(const string value);
ansond 21:8487990a3baa 121
ansond 21:8487990a3baa 122 /**
ansond 21:8487990a3baa 123 Send notification of new data
ansond 21:8487990a3baa 124 @param data input the new data to update
ansond 21:8487990a3baa 125 @returns 1 - success, 0 - failure
ansond 21:8487990a3baa 126 */
ansond 21:8487990a3baa 127 int notify(const string data);
ansond 21:8487990a3baa 128
ansond 23:caa0260acc21 129 /**
ansond 23:caa0260acc21 130 Determine whether this dynamic resource is observable or not
ansond 23:caa0260acc21 131 @returns true - is observable, false - otherwise
ansond 23:caa0260acc21 132 */
ansond 23:caa0260acc21 133 bool isObservable() { return this->m_observable; }
ansond 23:caa0260acc21 134
ansond 24:a6915e19814e 135 /**
ansond 31:bacc63106754 136 Set the observer pointer
ansond 31:bacc63106754 137 @param observer input the pointer to the ResourceObserver observing this resource
ansond 31:bacc63106754 138 */
ansond 31:bacc63106754 139 void setObserver(void *observer);
ansond 31:bacc63106754 140
ansond 31:bacc63106754 141 /**
michaeljkoster 52:822611156e35 142 Set the content format for responses
michaeljkoster 52:822611156e35 143 @param content_format short integer CoAP content-format ID
michaeljkoster 52:822611156e35 144 */
michaeljkoster 52:822611156e35 145 void set_content_format(uint8_t content_format);
michaeljkoster 52:822611156e35 146
michaeljkoster 52:822611156e35 147 /**
michaeljkoster 52:822611156e35 148 Set the max-age for cache control of responses in a proxy cache
michaeljkoster 52:822611156e35 149 @param maxage short integer CoAP max-age in seconds
michaeljkoster 52:822611156e35 150 */
michaeljkoster 52:822611156e35 151 void set_maxage(uint8_t maxage);
michaeljkoster 52:822611156e35 152
michaeljkoster 52:822611156e35 153 /**
ansond 24:a6915e19814e 154 Set the data wrapper
ansond 24:a6915e19814e 155 @param data_wrapper input the data wrapper instance
ansond 24:a6915e19814e 156 */
ansond 24:a6915e19814e 157 void setDataWrapper(DataWrapper *data_wrapper) { this->m_data_wrapper = data_wrapper; }
ansond 24:a6915e19814e 158
ansond 30:113c2a1d8db2 159 /**
ansond 30:113c2a1d8db2 160 observe the resource
ansond 30:113c2a1d8db2 161 */
ansond 30:113c2a1d8db2 162 virtual void observe();
ansond 30:113c2a1d8db2 163
sam_grove 2:853f9ecc12df 164 protected:
ansond 21:8487990a3baa 165 int notify(uint8_t *data,int data_length);
ansond 24:a6915e19814e 166 DataWrapper *getDataWrapper() { return this->m_data_wrapper; }
ansond 30:113c2a1d8db2 167 bool m_observable;
ansond 30:113c2a1d8db2 168
sam_grove 2:853f9ecc12df 169 private:
sam_grove 2:853f9ecc12df 170
ansond 30:113c2a1d8db2 171 string m_res_type;
ansond 30:113c2a1d8db2 172 uint8_t m_res_mask;
ansond 30:113c2a1d8db2 173 uint8_t m_obs_number;
ansond 30:113c2a1d8db2 174 uint8_t *m_obs_token_ptr;
ansond 30:113c2a1d8db2 175 uint8_t m_obs_token_len;
ansond 30:113c2a1d8db2 176 DataWrapper *m_data_wrapper;
ansond 31:bacc63106754 177 void *m_observer;
michaeljkoster 50:1a9e2184945e 178 uint8_t m_maxage;
michaeljkoster 51:b308658817e5 179 uint8_t m_content_format;
sam_grove 2:853f9ecc12df 180
sam_grove 2:853f9ecc12df 181 // convenience method to create a string from the NSDL CoAP data buffers...
sam_grove 2:853f9ecc12df 182 string coapDataToString(uint8_t *coap_data_ptr,int coap_data_ptr_length);
sam_grove 2:853f9ecc12df 183 };
sam_grove 2:853f9ecc12df 184
sam_grove 2:853f9ecc12df 185 #endif // __DYNAMIC_RESOURCE_H__