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.
Dependents: IoT_LED_demo ServoTest uWater_Project hackathon ... more
Diff: api/DynamicResource.cpp
- Revision:
- 48:4b9ee3e32f93
- Parent:
- 37:5de33aed0cac
- Child:
- 50:1a9e2184945e
--- a/api/DynamicResource.cpp Sun Apr 12 04:00:53 2015 +0000
+++ b/api/DynamicResource.cpp Mon Apr 13 23:41:34 2015 +0000
@@ -28,12 +28,12 @@
// ResourceObserver help
#include "ResourceObserver.h"
-// 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
+// Options enablement
+#include "Options.h"
+
+// GET verb can Start/Stop Observations...
+#define START_OBS 0
+#define STOP_OBS 1
// 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(""))
@@ -175,28 +175,29 @@
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...
+ // if GET controlled observation is enabled, perform it here...
+ if (((Connector::Options *)this->getOptions())->enableGETObservationControl()) {
+ // 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_len = 1;
+ this->m_obs_number++;
+ if (observer != NULL) observer->beginObservation();
+ }
+ if (OBS_command == STOP_OBS) {
+ if (observer != NULL) observer->stopObservation();
+ }
+ }
+ else {
+ // non-GET controlled observationing: 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++;
- if (observer != NULL) observer->beginObservation();
}
- 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...
@@ -319,6 +320,9 @@
if (status == 0) {
this->logger()->log("ERROR: resource(NOTIFY) send failed...");
}
+ else {
+ ++(this->m_obs_number);
+ }
// return our status
return status;