mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-12 11:40:39 +03:00
bugfix: add flag for CON/NON notification messages
Two new flags COAP_RESOURCE_FLAGS_NOTIFY_NON and COAP_RESOURCE_FLAGS_NOTIFY_CON have been added to control the message type for notifications to send. The default type is COAP_RESOURCE_FLAGS_NOTIFY_NON which can be changed with the function coap_resource_set_mode(). The observer-specific flag has been removed.
This commit is contained in:
1 parent
11daf0545a
commit
683337890e
5 files changed
+18
-6
No files matched your search
@@ -299,7 +299,7 @@ init_resources(coap_context_t *ctx) {
|
||||
/* store clock base to use in /time */
|
||||
my_clock_base = clock_offset;
|
||||
|
||||
r = coap_resource_init((unsigned char *)"time", 4, 0);
|
||||
r = coap_resource_init((unsigned char *)"time", 4, COAP_RESOURCE_FLAGS_NOTIFY_CON);
|
||||
coap_register_handler(r, COAP_REQUEST_GET, hnd_get_time);
|
||||
coap_register_handler(r, COAP_REQUEST_PUT, hnd_put_time);
|
||||
coap_register_handler(r, COAP_REQUEST_DELETE, hnd_delete_time);
|
||||
|
||||
+14
-1
@@ -1,6 +1,6 @@
|
||||
/* resource.h -- generic resource handling
|
||||
*
|
||||
* Copyright (C) 2010,2011,2014 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2010,2011,2014,2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
@@ -59,6 +59,8 @@ typedef struct coap_attr_t {
|
||||
} coap_attr_t;
|
||||
|
||||
#define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
|
||||
#define COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0
|
||||
#define COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2
|
||||
|
||||
typedef struct coap_resource_t {
|
||||
unsigned int dirty:1; /**< set to 1 if resource has changed */
|
||||
@@ -109,6 +111,17 @@ typedef struct coap_resource_t {
|
||||
coap_resource_t *coap_resource_init(const unsigned char *uri,
|
||||
size_t len, int flags);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the notification message type of resource @p r to given
|
||||
* @p mode which must be one of @c COAP_RESOURCE_FLAGS_NOTIFY_NON
|
||||
* or @c COAP_RESOURCE_FLAGS_NOTIFY_CON.
|
||||
*/
|
||||
static inline void
|
||||
coap_resource_set_mode(coap_resource_t *r, int mode) {
|
||||
r->flags = (r->flags & !COAP_RESOURCE_FLAGS_NOTIFY_CON) | mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given @p resource for @p context. The resource must have been
|
||||
* created by coap_resource_init(), the storage allocated for the resource will
|
||||
|
||||
@@ -55,7 +55,6 @@ typedef struct coap_subscription_t {
|
||||
coap_endpoint_t local_if; /**< local communication interface */
|
||||
coap_address_t subscriber; /**< address and port of subscriber */
|
||||
|
||||
unsigned int non:1; /**< send non-confirmable notifies if @c 1 */
|
||||
unsigned int non_cnt:4; /**< up to 15 non-confirmable notifies allowed */
|
||||
unsigned int fail_cnt:2; /**< up to 3 confirmable notifies can fail */
|
||||
unsigned int dirty:1; /**< set if the notification temporarily could not be
|
||||
|
||||
@@ -1429,7 +1429,6 @@ handle_request(coap_context_t *context, coap_queue_t *node) {
|
||||
subscription = coap_add_observer(resource, &node->local_if,
|
||||
&node->remote, &token);
|
||||
if (subscription) {
|
||||
subscription->non = node->pdu->hdr->type == COAP_MESSAGE_NON;
|
||||
coap_touch_observer(context, &node->remote, &token);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
/* resource.c -- generic resource handling
|
||||
*
|
||||
* Copyright (C) 2010--2014 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2010--2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
@@ -646,7 +646,8 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r) {
|
||||
token.s = obs->token;
|
||||
|
||||
response->hdr->id = coap_new_message_id(context);
|
||||
if (obs->non && obs->non_cnt < COAP_OBS_MAX_NON) {
|
||||
if ((r->flags & COAP_RESOURCE_FLAGS_NOTIFY_CON) == 0
|
||||
&& obs->non_cnt < COAP_OBS_MAX_NON) {
|
||||
response->hdr->type = COAP_MESSAGE_NON;
|
||||
} else {
|
||||
response->hdr->type = COAP_MESSAGE_CON;
|
||||
|
||||
Reference in new issue
Block a user