custom for >5 resources
Fork of mbedConnectorInterface by
Diff: api/DynamicResource.cpp
- Revision:
- 54:6963bb4d0399
- Parent:
- 53:458c2730e086
- Child:
- 56:aaf84e56c422
diff -r 458c2730e086 -r 6963bb4d0399 api/DynamicResource.cpp --- a/api/DynamicResource.cpp Tue Apr 14 13:44:41 2015 +0000 +++ b/api/DynamicResource.cpp Tue Apr 14 13:54:41 2015 +0000 @@ -31,10 +31,14 @@ // Options enablement #include "Options.h" -// GET verb can Start/Stop Observations... +// GET option that can be used to Start/Stop Observations... #define START_OBS 0 #define STOP_OBS 1 + +// MaxAge support for each DynamicResource #define DEFAULT_MAXAGE 60 + +// ContentFormat defaults for each DynamicResource #define DEFAULT_CONTENT_FORMAT 0 // default constructor @@ -165,18 +169,18 @@ } // CoAP Content-Format - coap_res_ptr->content_type_ptr = &this->m_content_format; + coap_res_ptr->content_type_ptr = &this->m_content_format; coap_res_ptr->content_type_len = sizeof(this->m_content_format); // max-age cache control coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)nsdl_alloc(sizeof(sn_coap_options_list_s)); if(!coap_res_ptr->options_list_ptr){ - this->logger()->log("Cant alloc option list\r\n"); + this->logger()->log("Cant alloc options list"); coap_res_ptr->options_list_ptr = NULL; } else{ memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - coap_res_ptr->options_list_ptr->max_age_ptr = &this->m_maxage; + coap_res_ptr->options_list_ptr->max_age_ptr = &this->m_maxage; coap_res_ptr->options_list_ptr->max_age_len = sizeof(this->m_maxage); } @@ -228,6 +232,8 @@ // build out the response and send... sn_nsdl_send_coap_message(address,coap_res_ptr); + + // freeing up the options_list_ptr and clearing the content_type pointer nsdl_free(coap_res_ptr->options_list_ptr); coap_res_ptr->options_list_ptr = NULL; coap_res_ptr->content_type_ptr = NULL; @@ -238,7 +244,7 @@ // because our obs_number (assigned to observe_ptr) is part of this object instance, we dont // want to have the underlying free() try to free it... to just nullify here // - if (coap_res_ptr->options_list_ptr) coap_res_ptr->options_list_ptr->observe_ptr = 0; + if (coap_res_ptr->options_list_ptr) coap_res_ptr->options_list_ptr->observe_ptr = 0; } else { this->logger()->log("ERROR: resource(GET) mask is munged (mask: 0x%x)",this->m_res_mask);