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
api/DynamicResource.h@23:caa0260acc21, 2015-03-19 (annotated)
- Committer:
- ansond
- Date:
- Thu Mar 19 04:05:08 2015 +0000
- Revision:
- 23:caa0260acc21
- Parent:
- 21:8487990a3baa
- Child:
- 24:a6915e19814e
updates for k64f hrm
Who changed what in which revision?
User | Revision | Line number | New 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 | |
sam_grove | 2:853f9ecc12df | 32 | /** DynamicResource class |
sam_grove | 2:853f9ecc12df | 33 | */ |
sam_grove | 2:853f9ecc12df | 34 | class DynamicResource : public Resource<string> |
sam_grove | 2:853f9ecc12df | 35 | { |
sam_grove | 2:853f9ecc12df | 36 | public: |
sam_grove | 2:853f9ecc12df | 37 | /** |
sam_grove | 2:853f9ecc12df | 38 | Default constructor (char strings) |
sam_grove | 2:853f9ecc12df | 39 | @param logger input logger instance for this resource |
sam_grove | 2:853f9ecc12df | 40 | @param name input the Resource URI/Name |
sam_grove | 2:853f9ecc12df | 41 | @param res_type input type for the Resource |
sam_grove | 2:853f9ecc12df | 42 | @param res_mask input the resource enablement mask (GET, PUT, etc...) |
sam_grove | 2:853f9ecc12df | 43 | @param observable input the resource is Observable (default: FALSE) |
sam_grove | 2:853f9ecc12df | 44 | */ |
sam_grove | 2:853f9ecc12df | 45 | DynamicResource(const Logger *logger,const char *name,const char *res_type,uint8_t res_mask,const bool observable = false); |
sam_grove | 2:853f9ecc12df | 46 | |
sam_grove | 2:853f9ecc12df | 47 | /** |
sam_grove | 2:853f9ecc12df | 48 | Default constructor (char strings) |
sam_grove | 2:853f9ecc12df | 49 | @param logger input logger instance for this resource |
sam_grove | 2:853f9ecc12df | 50 | @param name input the Resource URI/Name |
sam_grove | 2:853f9ecc12df | 51 | @param res_type input type for the Resource |
sam_grove | 2:853f9ecc12df | 52 | @param value input initial value for the Resource |
sam_grove | 2:853f9ecc12df | 53 | @param res_mask input the resource enablement mask (GET, PUT, etc...) |
sam_grove | 2:853f9ecc12df | 54 | @param observable input the resource is Observable (default: FALSE) |
sam_grove | 2:853f9ecc12df | 55 | */ |
sam_grove | 2:853f9ecc12df | 56 | 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 | 57 | |
sam_grove | 2:853f9ecc12df | 58 | /** |
sam_grove | 2:853f9ecc12df | 59 | constructor with string buffer for name |
sam_grove | 2:853f9ecc12df | 60 | @param logger input logger instance for this resource |
sam_grove | 2:853f9ecc12df | 61 | @param name input the Resource URI/Name |
sam_grove | 2:853f9ecc12df | 62 | @param res_type input type for the Resource |
sam_grove | 2:853f9ecc12df | 63 | @param value input initial value for the Resource |
sam_grove | 2:853f9ecc12df | 64 | @param res_mask input the resource enablement mask (GET, PUT, etc...) |
sam_grove | 2:853f9ecc12df | 65 | @param observable input the resource is Observable (default: FALSE) |
sam_grove | 2:853f9ecc12df | 66 | */ |
sam_grove | 2:853f9ecc12df | 67 | 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 | 68 | |
sam_grove | 2:853f9ecc12df | 69 | /** |
sam_grove | 2:853f9ecc12df | 70 | Copy constructor |
sam_grove | 2:853f9ecc12df | 71 | @param resource input the DynamicResource that is to be deep copied |
sam_grove | 2:853f9ecc12df | 72 | */ |
sam_grove | 2:853f9ecc12df | 73 | DynamicResource(const DynamicResource &resource); |
sam_grove | 2:853f9ecc12df | 74 | |
sam_grove | 2:853f9ecc12df | 75 | /** |
sam_grove | 2:853f9ecc12df | 76 | Destructor |
sam_grove | 2:853f9ecc12df | 77 | */ |
sam_grove | 2:853f9ecc12df | 78 | virtual ~DynamicResource(); |
sam_grove | 2:853f9ecc12df | 79 | |
sam_grove | 2:853f9ecc12df | 80 | /** |
sam_grove | 2:853f9ecc12df | 81 | Bind resource to endpoint |
sam_grove | 2:853f9ecc12df | 82 | @param p input pointer to the endpoint resources necessary for binding |
sam_grove | 2:853f9ecc12df | 83 | */ |
sam_grove | 2:853f9ecc12df | 84 | virtual void bind(void *p); |
sam_grove | 2:853f9ecc12df | 85 | |
sam_grove | 2:853f9ecc12df | 86 | /** |
sam_grove | 2:853f9ecc12df | 87 | Process the CoAP message |
sam_grove | 2:853f9ecc12df | 88 | @param received_coap_ptr input the received coap pointer |
sam_grove | 2:853f9ecc12df | 89 | @param address input the NSDL address pointer |
sam_grove | 2:853f9ecc12df | 90 | @param proto input the NSDL protocol pointer |
sam_grove | 2:853f9ecc12df | 91 | @return 0 - success, 1 - failure |
sam_grove | 2:853f9ecc12df | 92 | */ |
sam_grove | 2:853f9ecc12df | 93 | uint8_t process(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto); |
sam_grove | 2:853f9ecc12df | 94 | |
sam_grove | 2:853f9ecc12df | 95 | /** |
sam_grove | 2:853f9ecc12df | 96 | Resource value getter (REQUIRED: must be implemented in derived class as all Binders MUST support and implement GET) |
sam_grove | 2:853f9ecc12df | 97 | @returns string value of the resource |
sam_grove | 2:853f9ecc12df | 98 | */ |
sam_grove | 2:853f9ecc12df | 99 | virtual string get() = 0; |
sam_grove | 2:853f9ecc12df | 100 | |
sam_grove | 2:853f9ecc12df | 101 | /** |
ansond | 21:8487990a3baa | 102 | Resource value setter (PUT) (OPTIONAL: defaulted noop if not derived. Binders MAY implement PUT if needed) |
sam_grove | 2:853f9ecc12df | 103 | @param string value of the resource |
sam_grove | 2:853f9ecc12df | 104 | */ |
sam_grove | 2:853f9ecc12df | 105 | virtual void put(const string value); |
ansond | 21:8487990a3baa | 106 | |
ansond | 21:8487990a3baa | 107 | /** |
ansond | 21:8487990a3baa | 108 | Resource value setter (POST) (OPTIONAL: defaulted noop if not derived. Binders MAY implement POST if needed) |
ansond | 21:8487990a3baa | 109 | @param string value of the resource |
ansond | 21:8487990a3baa | 110 | */ |
ansond | 21:8487990a3baa | 111 | virtual void post(const string value); |
ansond | 21:8487990a3baa | 112 | |
ansond | 21:8487990a3baa | 113 | /** |
ansond | 21:8487990a3baa | 114 | Resource value deleter (OPTIONAL: defaulted noop if not derived. Binders MAY implement DELETE if needed) |
ansond | 21:8487990a3baa | 115 | @param string value of the resource |
ansond | 21:8487990a3baa | 116 | */ |
ansond | 21:8487990a3baa | 117 | virtual void del(const string value); |
ansond | 21:8487990a3baa | 118 | |
ansond | 21:8487990a3baa | 119 | /** |
ansond | 21:8487990a3baa | 120 | Send notification of new data |
ansond | 21:8487990a3baa | 121 | @param data input the new data to update |
ansond | 21:8487990a3baa | 122 | @returns 1 - success, 0 - failure |
ansond | 21:8487990a3baa | 123 | */ |
ansond | 21:8487990a3baa | 124 | int notify(const string data); |
ansond | 21:8487990a3baa | 125 | |
ansond | 23:caa0260acc21 | 126 | /** |
ansond | 23:caa0260acc21 | 127 | Determine whether this dynamic resource is observable or not |
ansond | 23:caa0260acc21 | 128 | @returns true - is observable, false - otherwise |
ansond | 23:caa0260acc21 | 129 | */ |
ansond | 23:caa0260acc21 | 130 | bool isObservable() { return this->m_observable; } |
ansond | 23:caa0260acc21 | 131 | |
sam_grove | 2:853f9ecc12df | 132 | protected: |
ansond | 21:8487990a3baa | 133 | int notify(uint8_t *data,int data_length); |
sam_grove | 2:853f9ecc12df | 134 | |
sam_grove | 2:853f9ecc12df | 135 | private: |
sam_grove | 2:853f9ecc12df | 136 | |
sam_grove | 2:853f9ecc12df | 137 | string m_res_type; |
sam_grove | 2:853f9ecc12df | 138 | uint8_t m_res_mask; |
sam_grove | 2:853f9ecc12df | 139 | bool m_observable; |
ansond | 21:8487990a3baa | 140 | uint8_t m_obs_number; |
ansond | 21:8487990a3baa | 141 | uint8_t *m_obs_token_ptr; |
ansond | 21:8487990a3baa | 142 | uint8_t m_obs_token_len; |
sam_grove | 2:853f9ecc12df | 143 | |
sam_grove | 2:853f9ecc12df | 144 | // convenience method to create a string from the NSDL CoAP data buffers... |
sam_grove | 2:853f9ecc12df | 145 | string coapDataToString(uint8_t *coap_data_ptr,int coap_data_ptr_length); |
sam_grove | 2:853f9ecc12df | 146 | }; |
sam_grove | 2:853f9ecc12df | 147 | |
sam_grove | 2:853f9ecc12df | 148 | #endif // __DYNAMIC_RESOURCE_H__ |