resource: Fix issues #90, #91 and #92

The value of the observe option is kept for each resource rather than being global to the context.
The value of the observe option must wrap to be stay below 2^24.
The value of the observe option must be different from the initial value when a notification is sent.
This commit is contained in:
jcmichelou committed 2017-10-25 20:22:01 +02:00
1 parent 3630436499
commit 3f77c117ea
5 files changed
+13 -14

No files matched your search

+1 -2
View File
@@ -114,10 +114,9 @@ hnd_get_time(coap_context_t *ctx,
my_clock_base ? COAP_RESPONSE_CODE(205) : COAP_RESPONSE_CODE(404);
if (coap_find_observer(resource, session, token)) {
/* FIXME: need to check for resource->dirty? */
coap_add_option(response,
COAP_OPTION_OBSERVE,
coap_encode_var_bytes(buf, ctx->observe), buf);
coap_encode_var_bytes(buf, resource->observe), buf);
}
if (my_clock_base)
+2 -3
View File
@@ -111,9 +111,8 @@ hnd_get_time(coap_context_t *ctx, struct coap_resource_t *resource,
my_clock_base ? COAP_RESPONSE_CODE(205) : COAP_RESPONSE_CODE(404);
if (coap_find_observer(resource, peer, token)) {
/* FIXME: need to check for resource->dirty? */
coap_add_option(response, COAP_OPTION_OBSERVE,
coap_encode_var_bytes(buf, ctx->observe), buf);
coap_encode_var_bytes(buf, resource->observe), buf);
}
if (my_clock_base)
@@ -218,7 +217,7 @@ PROCESS_THREAD(coap_server_process, ev, data)
coap_read(coap_context); /* read received data */
/* coap_dispatch(coap_context); /\* and dispatch PDUs from receivequeue *\/ */
} else if (ev == PROCESS_EVENT_TIMER && etimer_expired(&dirty_timer)) {
time_resource->dirty = 1;
coap_resource_set_dirty(time_resource, NULL);
etimer_reset(&dirty_timer);
}
}
-6
View File
@@ -120,12 +120,6 @@ typedef struct coap_context_t {
*/
uint16_t message_id;
/**
* The next value to be used for Observe. This field is global for all
* resources and will be updated when notifications are created.
*/
unsigned int observe;
coap_response_handler_t response_handler;
coap_nack_handler_t nack_handler;
+6
View File
@@ -106,6 +106,12 @@ typedef struct coap_resource_t {
str uri;
int flags;
/**
* The next value for the Observe option. This field must be increased each
* time the resource changes. Only the lower 24 bits are sent.
*/
unsigned int observe;
} coap_resource_t;
/**
+4 -3
View File
@@ -720,9 +720,6 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r) {
}
}
/* Increment value for next Observe use. */
context->observe++;
}
r->dirty = 0;
}
@@ -750,6 +747,10 @@ coap_resource_set_dirty(coap_resource_t *r, const str *query) {
} else {
r->dirty = 1;
}
/* Increment value for next Observe use. Observe value must be < 2^24 */
r->observe = (r->observe + 1) & 0xFFFFFF;
return 1;
}