1 /* 2 * subscribe.h -- subscription handling for CoAP 3 * see RFC7641 4 * 5 * Copyright (C) 2010-2012,2014-2021 Olaf Bergmann <bergmann@tzi.org> 6 * 7 * SPDX-License-Identifier: BSD-2-Clause 8 * 9 * This file is part of the CoAP library libcoap. Please see README for terms 10 * of use. 11 */ 12 13 /** 14 * @file subscribe.h 15 * @brief Defines the application visible subscribe information 16 */ 17 18 #ifndef COAP_SUBSCRIBE_H_ 19 #define COAP_SUBSCRIBE_H_ 20 21 /** 22 * @defgroup observe Resource Observation 23 * API functions for interfacing with the observe handling (RFC7641) 24 * @{ 25 */ 26 27 /** 28 * The value COAP_OBSERVE_ESTABLISH in a GET/FETCH request option 29 * COAP_OPTION_OBSERVE indicates a new observe relationship for (sender 30 * address, token) is requested. 31 */ 32 #define COAP_OBSERVE_ESTABLISH 0 33 34 /** 35 * The value COAP_OBSERVE_CANCEL in a GET/FETCH request option 36 * COAP_OPTION_OBSERVE indicates that the observe relationship for (sender 37 * address, token) must be cancelled. 38 */ 39 #define COAP_OBSERVE_CANCEL 1 40 41 /** 42 * Set whether a @p resource is observable. If the resource is observable 43 * and the client has set the COAP_OPTION_OBSERVE in a request packet, then 44 * whenever the state of the resource changes (a call to 45 * coap_resource_trigger_observe()), an Observer response will get sent. 46 * 47 * @param resource The CoAP resource to use. 48 * @param mode @c 1 if Observable is to be set, @c 0 otherwise. 49 * 50 */ 51 void coap_resource_set_get_observable(coap_resource_t *resource, int mode); 52 53 /** 54 * Initiate the sending of an Observe packet for all observers of @p resource, 55 * optionally matching @p query if not NULL 56 * 57 * @param resource The CoAP resource to use. 58 * @param query The Query to match against or NULL 59 * 60 * @return @c 1 if the Observe has been triggered, @c 0 otherwise. 61 */ 62 int 63 coap_resource_notify_observers(coap_resource_t *resource, 64 const coap_string_t *query); 65 66 /** @} */ 67 68 #endif /* COAP_SUBSCRIBE_H_ */ 69