mbed Connector Endpoint interface. This interface permits a mbed endpoint to easily setup MDS resources and emit those resources to an MDS server.

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

Revision:
50:1a9e2184945e
Parent:
48:4b9ee3e32f93
Child:
51:b308658817e5
--- a/api/DynamicResource.cpp	Tue Apr 14 00:06:46 2015 +0000
+++ b/api/DynamicResource.cpp	Tue Apr 14 02:51:23 2015 +0000
@@ -34,6 +34,7 @@
 // GET verb can Start/Stop Observations...
 #define START_OBS 0
 #define STOP_OBS  1
+#define DEFAULT_MAXAGE 60
 
 // 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(""))
@@ -46,6 +47,7 @@
     this->m_obs_token_len = 0;
     this->m_data_wrapper = NULL;
     this->m_observer = NULL;
+    this->m_maxage = (uint16_t)DEFAULT_MAXAGE;
 }
 
 // constructor (input initial value)
@@ -59,6 +61,7 @@
     this->m_obs_token_len = 0;
     this->m_data_wrapper = NULL;
     this->m_observer = NULL;
+    this->m_maxage = DEFAULT_MAXAGE;
 }
 
 // constructor (strings)
@@ -72,6 +75,7 @@
     this->m_obs_token_len = 0;
     this->m_data_wrapper = NULL;
     this->m_observer = NULL;
+    this->m_maxage = DEFAULT_MAXAGE;
 }
 
 // copy constructor
@@ -85,6 +89,7 @@
     this->m_obs_token_len = resource.m_obs_token_len;
     this->m_data_wrapper = resource.m_data_wrapper;
     this->m_observer = resource.m_observer;
+    this->m_maxage = resource.m_maxage;
 }
 
 // destructor
@@ -154,6 +159,18 @@
                 coap_res_ptr->payload_ptr = (uint8_t *)value.c_str();
             }
             
+            // 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");
+                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_len = sizeof(this->m_maxage);
+            }
+            
             // Observation handling... 
             if(received_coap_ptr->token_ptr) {
                 if(this->m_obs_token_ptr) {
@@ -202,6 +219,8 @@
 
             // build out the response and send...
             sn_nsdl_send_coap_message(address,coap_res_ptr);
+            nsdl_free(coap_res_ptr->options_list_ptr);
+            coap_res_ptr->options_list_ptr = NULL;
             
             //
             // nullify note: