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
Diff: api/DynamicResource.cpp
- Revision:
- 36:1c6c45584c13
- Parent:
- 31:bacc63106754
- Child:
- 37:5de33aed0cac
--- a/api/DynamicResource.cpp Wed Apr 08 23:03:39 2015 +0000 +++ b/api/DynamicResource.cpp Thu Apr 09 03:32:11 2015 +0000 @@ -28,9 +28,12 @@ // ResourceObserver help #include "ResourceObserver.h" -// Start/Stop Observations... -#define START_OBS 0 -#define STOP_OBS 1 +// Leaving this disabled until the CoAP draft spec is further along... +#ifdef GET_ENABLE_DISABLE_OBS + // GET verb can Start/Stop Observations... + #define START_OBS 0 + #define STOP_OBS 1 +#endif // default constructor DynamicResource::DynamicResource(const Logger *logger,const char *name,const char *res_type,uint8_t res_mask,const bool observable) : Resource<string>(logger,string(name),string("")) @@ -55,6 +58,7 @@ this->m_obs_token_ptr = NULL; this->m_obs_token_len = 0; this->m_data_wrapper = NULL; + this->m_observer = NULL; } // constructor (strings) @@ -67,6 +71,7 @@ this->m_obs_token_ptr = NULL; this->m_obs_token_len = 0; this->m_data_wrapper = NULL; + this->m_observer = NULL; } // copy constructor @@ -79,6 +84,7 @@ this->m_obs_token_ptr = resource.m_obs_token_ptr; this->m_obs_token_len = resource.m_obs_token_len; this->m_data_wrapper = resource.m_data_wrapper; + this->m_observer = resource.m_observer; } // destructor @@ -164,18 +170,20 @@ } // Observation handling... - if(received_coap_ptr->options_list_ptr && received_coap_ptr->options_list_ptr->observe) { - // ResourceObserver - ResourceObserver *observer = (ResourceObserver *)this->m_observer; - + if(received_coap_ptr->options_list_ptr && received_coap_ptr->options_list_ptr->observe) { // create the options list pointer coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - + + // Leaving this disabled until the CoAP draft spec is further along... +#ifdef GET_ENABLE_DISABLE_OBS + // ResourceObserver + ResourceObserver *observer = (ResourceObserver *)this->m_observer; + // get observe start/stop value from received options list pointer uint8_t OBS_command = *received_coap_ptr->options_list_ptr->observe_ptr; if (OBS_command == START_OBS) { - coap_res_ptr->options_list_ptr->observe_ptr = &this->m_obs_number; // see nullify note below... + coap_res_ptr->options_list_ptr->observe_ptr = &this->m_obs_number; // see nullify note below... coap_res_ptr->options_list_ptr->observe_len = 1; this->m_obs_number++; if (observer != NULL) observer->beginObservation(); @@ -183,6 +191,12 @@ if (OBS_command == STOP_OBS) { if (observer != NULL) observer->stopObservation(); } +#else + // simply fill in the observation requirements... + coap_res_ptr->options_list_ptr->observe_ptr = &this->m_obs_number; // see nullify note below... + coap_res_ptr->options_list_ptr->observe_len = 1; + this->m_obs_number++; +#endif } // build out the response and send...