Subscription lifetime update

This commit is contained in:
doganyazar 2010-11-30 13:23:30 +00:00
parent 37b47e4cf2
commit 135d5f0ace
2 changed files with 22 additions and 16 deletions

View File

@ -234,7 +234,7 @@ rest_invoke_restful_service(REQUEST* request, RESPONSE* response)
if (resource->methods_to_handle & method) { if (resource->methods_to_handle & method) {
/*FIXME Move somewhere else*/ /*FIXME Need to move somewhere else*/
#ifdef WITH_COAP #ifdef WITH_COAP
uint32_t lifetime = 0; uint32_t lifetime = 0;
if (coap_get_header_subscription_lifetime(request, &lifetime)) { if (coap_get_header_subscription_lifetime(request, &lifetime)) {
@ -248,6 +248,7 @@ rest_invoke_restful_service(REQUEST* request, RESPONSE* response)
PRINTF("Periodic Resource Found\n"); PRINTF("Periodic Resource Found\n");
PRINT6ADDR(&request->addr); PRINT6ADDR(&request->addr);
periodic_resource->lifetime = lifetime; periodic_resource->lifetime = lifetime;
stimer_set(periodic_resource->lifetime_timer, lifetime);
uip_ipaddr_copy(&periodic_resource->addr, &request->addr); uip_ipaddr_copy(&periodic_resource->addr, &request->addr);
} }
} }
@ -294,31 +295,33 @@ PROCESS_THREAD(rest_manager_process, ev, data)
periodic_resource_t* periodic_resource = NULL; periodic_resource_t* periodic_resource = NULL;
for (periodic_resource = (periodic_resource_t*)list_head(restful_periodic_services); periodic_resource; periodic_resource = periodic_resource->next) { for (periodic_resource = (periodic_resource_t*)list_head(restful_periodic_services); periodic_resource; periodic_resource = periodic_resource->next) {
if (periodic_resource->period) { if (periodic_resource->period) {
PRINTF("Set timer for Res: %s to %u\n", periodic_resource->resource->url, periodic_resource->period); PRINTF("Set timer for Res: %s to %lu\n", periodic_resource->resource->url, periodic_resource->period);
etimer_set(periodic_resource->timer, CLOCK_SECOND * periodic_resource->period); etimer_set(periodic_resource->handler_cb_timer, periodic_resource->period);
} }
} }
while(1) { while(1) {
PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT();
if (ev == PROCESS_EVENT_TIMER) { if (ev == PROCESS_EVENT_TIMER) {
for (periodic_resource=(periodic_resource_t*)list_head(restful_periodic_services);periodic_resource;periodic_resource = periodic_resource->next) { for (periodic_resource = (periodic_resource_t*)list_head(restful_periodic_services);periodic_resource;periodic_resource = periodic_resource->next) {
if (periodic_resource->period && etimer_expired(periodic_resource->timer)) { if (periodic_resource->period && etimer_expired(periodic_resource->handler_cb_timer)) {
PRINTF("Etimer expired for %s (period:%u life:%lu)\n", periodic_resource->resource->url, periodic_resource->period, periodic_resource->lifetime); PRINTF("Etimer expired for %s (period:%lu life:%lu)\n", periodic_resource->resource->url, periodic_resource->period, periodic_resource->lifetime);
/*call the periodic handler function if exists*/ /*call the periodic handler function if exists*/
if (periodic_resource->periodic_handler) { if (periodic_resource->periodic_handler) {
if ((periodic_resource->periodic_handler)(periodic_resource->resource) && periodic_resource->lifetime) { if ((periodic_resource->periodic_handler)(periodic_resource->resource)) {
resource_changed(periodic_resource); PRINTF("RES CHANGE\n");
if (!stimer_expired(periodic_resource->lifetime_timer)) {
PRINTF("TIMER NOT EXPIRED\n");
resource_changed(periodic_resource);
periodic_resource->lifetime = stimer_remaining(periodic_resource->lifetime_timer);
} else {
periodic_resource->lifetime = 0;
}
} }
/*Update lifetime*/
if (periodic_resource->lifetime > periodic_resource->period) { PRINTF("%s lifetime %lu (%lu) expired %d\n", periodic_resource->resource->url, stimer_remaining(periodic_resource->lifetime_timer), periodic_resource->lifetime, stimer_expired(periodic_resource->lifetime_timer));
periodic_resource->lifetime -= periodic_resource->period;
} else {
periodic_resource->lifetime = 0;
}
PRINTF("%s life upd:%lu\n", periodic_resource->resource->url, periodic_resource->lifetime);
} }
etimer_reset(periodic_resource->timer); etimer_reset(periodic_resource->handler_cb_timer);
} }
} }
} }

View File

@ -22,6 +22,9 @@
#define NODE_2_GLOBAL(ipaddr) uip_ip6addr(ipaddr, 0xaaaa, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202) #define NODE_2_GLOBAL(ipaddr) uip_ip6addr(ipaddr, 0xaaaa, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202)
#define NODE_2_LOCAL(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202) #define NODE_2_LOCAL(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202)
#define NODE_3_GLOBAL(ipaddr) uip_ip6addr(ipaddr, 0xaaaa, 0, 0, 0, 0x0212, 0x7403, 0x0003, 0x0303)
#define NODE_3_LOCAL(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7403, 0x0003, 0x0303)
#define NODE_6_GLOBAL(ipaddr) uip_ip6addr(ipaddr, 0xaaaa, 0, 0, 0, 0x0212, 0x7406, 0x0006, 0x0606) #define NODE_6_GLOBAL(ipaddr) uip_ip6addr(ipaddr, 0xaaaa, 0, 0, 0, 0x0212, 0x7406, 0x0006, 0x0606)
#define NODE_6_LOCAL(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7406, 0x0006, 0x0606) #define NODE_6_LOCAL(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7406, 0x0006, 0x0606)