custom for >5 resources
Fork of mbedConnectorInterface by
api/DynamicResource.h@2:853f9ecc12df, 2015-01-27 (annotated)
- Committer:
- sam_grove
- Date:
- Tue Jan 27 23:41:34 2015 +0000
- Revision:
- 2:853f9ecc12df
- Parent:
- 0:b438482ebbfc
- Child:
- 21:8487990a3baa
Use auto-format on code and add markup to render class documentation
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 | /** |
sam_grove | 2:853f9ecc12df | 102 | Resource value setter (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); |
sam_grove | 2:853f9ecc12df | 106 | |
sam_grove | 2:853f9ecc12df | 107 | protected: |
sam_grove | 2:853f9ecc12df | 108 | |
sam_grove | 2:853f9ecc12df | 109 | private: |
sam_grove | 2:853f9ecc12df | 110 | |
sam_grove | 2:853f9ecc12df | 111 | string m_res_type; |
sam_grove | 2:853f9ecc12df | 112 | uint8_t m_res_mask; |
sam_grove | 2:853f9ecc12df | 113 | bool m_observable; |
sam_grove | 2:853f9ecc12df | 114 | |
sam_grove | 2:853f9ecc12df | 115 | // convenience method to create a string from the NSDL CoAP data buffers... |
sam_grove | 2:853f9ecc12df | 116 | string coapDataToString(uint8_t *coap_data_ptr,int coap_data_ptr_length); |
sam_grove | 2:853f9ecc12df | 117 | }; |
sam_grove | 2:853f9ecc12df | 118 | |
sam_grove | 2:853f9ecc12df | 119 | #endif // __DYNAMIC_RESOURCE_H__ |