custom for >5 resources
Fork of mbedConnectorInterface by
api/DynamicResource.h@0:b438482ebbfc, 2015-01-27 (annotated)
- Committer:
- ansond
- Date:
- Tue Jan 27 22:23:51 2015 +0000
- Revision:
- 0:b438482ebbfc
- Child:
- 2:853f9ecc12df
initial check in
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 |
ansond | 0:b438482ebbfc | 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 | */ |
ansond | 0:b438482ebbfc | 22 | |
ansond | 0:b438482ebbfc | 23 | #ifndef __DYNAMIC_RESOURCE_H__ |
ansond | 0:b438482ebbfc | 24 | #define __DYNAMIC_RESOURCE_H__ |
ansond | 0:b438482ebbfc | 25 | |
ansond | 0:b438482ebbfc | 26 | // Base Class |
ansond | 0:b438482ebbfc | 27 | #include "Resource.h" |
ansond | 0:b438482ebbfc | 28 | |
ansond | 0:b438482ebbfc | 29 | // NSDL Support |
ansond | 0:b438482ebbfc | 30 | #include "nsdl_support.h" |
ansond | 0:b438482ebbfc | 31 | |
ansond | 0:b438482ebbfc | 32 | class DynamicResource : public Resource<string> { |
ansond | 0:b438482ebbfc | 33 | public: |
ansond | 0:b438482ebbfc | 34 | /** |
ansond | 0:b438482ebbfc | 35 | Default constructor (char strings) |
ansond | 0:b438482ebbfc | 36 | @param logger input logger instance for this resource |
ansond | 0:b438482ebbfc | 37 | @param name input the Resource URI/Name |
ansond | 0:b438482ebbfc | 38 | @param res_type input type for the Resource |
ansond | 0:b438482ebbfc | 39 | @param res_mask input the resource enablement mask (GET, PUT, etc...) |
ansond | 0:b438482ebbfc | 40 | @param observable input the resource is Observable (default: FALSE) |
ansond | 0:b438482ebbfc | 41 | */ |
ansond | 0:b438482ebbfc | 42 | DynamicResource(const Logger *logger,const char *name,const char *res_type,uint8_t res_mask,const bool observable = false); |
ansond | 0:b438482ebbfc | 43 | |
ansond | 0:b438482ebbfc | 44 | /** |
ansond | 0:b438482ebbfc | 45 | Default constructor (char strings) |
ansond | 0:b438482ebbfc | 46 | @param logger input logger instance for this resource |
ansond | 0:b438482ebbfc | 47 | @param name input the Resource URI/Name |
ansond | 0:b438482ebbfc | 48 | @param res_type input type for the Resource |
ansond | 0:b438482ebbfc | 49 | @param value input initial value for the Resource |
ansond | 0:b438482ebbfc | 50 | @param res_mask input the resource enablement mask (GET, PUT, etc...) |
ansond | 0:b438482ebbfc | 51 | @param observable input the resource is Observable (default: FALSE) |
ansond | 0:b438482ebbfc | 52 | */ |
ansond | 0:b438482ebbfc | 53 | DynamicResource(const Logger *logger,const char *name,const char *res_type,const string value,uint8_t res_mask,const bool observable = false); |
ansond | 0:b438482ebbfc | 54 | |
ansond | 0:b438482ebbfc | 55 | /** |
ansond | 0:b438482ebbfc | 56 | constructor with string buffer for name |
ansond | 0:b438482ebbfc | 57 | @param logger input logger instance for this resource |
ansond | 0:b438482ebbfc | 58 | @param name input the Resource URI/Name |
ansond | 0:b438482ebbfc | 59 | @param res_type input type for the Resource |
ansond | 0:b438482ebbfc | 60 | @param value input initial value for the Resource |
ansond | 0:b438482ebbfc | 61 | @param res_mask input the resource enablement mask (GET, PUT, etc...) |
ansond | 0:b438482ebbfc | 62 | @param observable input the resource is Observable (default: FALSE) |
ansond | 0:b438482ebbfc | 63 | */ |
ansond | 0:b438482ebbfc | 64 | 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 | 65 | |
ansond | 0:b438482ebbfc | 66 | /** |
ansond | 0:b438482ebbfc | 67 | Copy constructor |
ansond | 0:b438482ebbfc | 68 | @param resource input the DynamicResource that is to be deep copied |
ansond | 0:b438482ebbfc | 69 | */ |
ansond | 0:b438482ebbfc | 70 | DynamicResource(const DynamicResource &resource); |
ansond | 0:b438482ebbfc | 71 | |
ansond | 0:b438482ebbfc | 72 | /** |
ansond | 0:b438482ebbfc | 73 | Destructor |
ansond | 0:b438482ebbfc | 74 | */ |
ansond | 0:b438482ebbfc | 75 | virtual ~DynamicResource(); |
ansond | 0:b438482ebbfc | 76 | |
ansond | 0:b438482ebbfc | 77 | /** |
ansond | 0:b438482ebbfc | 78 | Bind resource to endpoint |
ansond | 0:b438482ebbfc | 79 | @param p input pointer to the endpoint resources necessary for binding |
ansond | 0:b438482ebbfc | 80 | */ |
ansond | 0:b438482ebbfc | 81 | virtual void bind(void *p); |
ansond | 0:b438482ebbfc | 82 | |
ansond | 0:b438482ebbfc | 83 | /** |
ansond | 0:b438482ebbfc | 84 | Process the CoAP message |
ansond | 0:b438482ebbfc | 85 | @param received_coap_ptr input the received coap pointer |
ansond | 0:b438482ebbfc | 86 | @param address input the NSDL address pointer |
ansond | 0:b438482ebbfc | 87 | @param proto input the NSDL protocol pointer |
ansond | 0:b438482ebbfc | 88 | @return 0 - success, 1 - failure |
ansond | 0:b438482ebbfc | 89 | */ |
ansond | 0:b438482ebbfc | 90 | uint8_t process(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto); |
ansond | 0:b438482ebbfc | 91 | |
ansond | 0:b438482ebbfc | 92 | /** |
ansond | 0:b438482ebbfc | 93 | Resource value getter (REQUIRED: must be implemented in derived class as all Binders MUST support and implement GET) |
ansond | 0:b438482ebbfc | 94 | @returns string value of the resource |
ansond | 0:b438482ebbfc | 95 | */ |
ansond | 0:b438482ebbfc | 96 | virtual string get() = 0; |
ansond | 0:b438482ebbfc | 97 | |
ansond | 0:b438482ebbfc | 98 | /** |
ansond | 0:b438482ebbfc | 99 | Resource value setter (OPTIONAL: defaulted noop if not derived. Binders MAY implement PUT if needed) |
ansond | 0:b438482ebbfc | 100 | @param string value of the resource |
ansond | 0:b438482ebbfc | 101 | */ |
ansond | 0:b438482ebbfc | 102 | virtual void put(const string value); |
ansond | 0:b438482ebbfc | 103 | |
ansond | 0:b438482ebbfc | 104 | protected: |
ansond | 0:b438482ebbfc | 105 | |
ansond | 0:b438482ebbfc | 106 | private: |
ansond | 0:b438482ebbfc | 107 | |
ansond | 0:b438482ebbfc | 108 | string m_res_type; |
ansond | 0:b438482ebbfc | 109 | uint8_t m_res_mask; |
ansond | 0:b438482ebbfc | 110 | bool m_observable; |
ansond | 0:b438482ebbfc | 111 | |
ansond | 0:b438482ebbfc | 112 | // convenience method to create a string from the NSDL CoAP data buffers... |
ansond | 0:b438482ebbfc | 113 | string coapDataToString(uint8_t *coap_data_ptr,int coap_data_ptr_length); |
ansond | 0:b438482ebbfc | 114 | }; |
ansond | 0:b438482ebbfc | 115 | |
ansond | 0:b438482ebbfc | 116 | #endif // __DYNAMIC_RESOURCE_H__ |