1 /* 2 * coap_event.h -- libcoap Event API 3 * 4 * Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org> 5 * 6 * This file is part of the CoAP library libcoap. Please see README for terms 7 * of use. 8 */ 9 10 #ifndef COAP_EVENT_H_ 11 #define COAP_EVENT_H_ 12 13 #include "libcoap.h" 14 15 struct coap_context_t; 16 struct coap_session_t; 17 18 /** 19 * @defgroup events Event API 20 * API functions for event delivery from lower-layer library functions. 21 * @{ 22 */ 23 24 /** 25 * Scalar type to represent different events, e.g. DTLS events or 26 * retransmission timeouts. 27 */ 28 typedef unsigned int coap_event_t; 29 30 /** 31 * (D)TLS events for COAP_PROTO_DTLS and COAP_PROTO_TLS 32 */ 33 #define COAP_EVENT_DTLS_CLOSED 0x0000 34 #define COAP_EVENT_DTLS_CONNECTED 0x01DE 35 #define COAP_EVENT_DTLS_RENEGOTIATE 0x01DF 36 #define COAP_EVENT_DTLS_ERROR 0x0200 37 38 /** 39 * TCP events for COAP_PROTO_TCP and COAP_PROTO_TLS 40 */ 41 #define COAP_EVENT_TCP_CONNECTED 0x1001 42 #define COAP_EVENT_TCP_CLOSED 0x1002 43 #define COAP_EVENT_TCP_FAILED 0x1003 44 45 /** 46 * CSM exchange events for reliable protocols only 47 */ 48 #define COAP_EVENT_SESSION_CONNECTED 0x2001 49 #define COAP_EVENT_SESSION_CLOSED 0x2002 50 #define COAP_EVENT_SESSION_FAILED 0x2003 51 52 /** 53 * Type for event handler functions that can be registered with a CoAP 54 * context using the unction coap_set_event_handler(). When called by 55 * the library, the first argument will be the coap_context_t object 56 * where the handler function has been registered. The second argument 57 * is the event type that may be complemented by event-specific data 58 * passed as the third argument. 59 */ 60 typedef int (*coap_event_handler_t)(struct coap_context_t *, 61 coap_event_t event, 62 struct coap_session_t *session); 63 64 /** 65 * Registers the function @p hnd as callback for events from the given 66 * CoAP context @p context. Any event handler that has previously been 67 * registered with @p context will be overwritten by this operation. 68 * 69 * @param context The CoAP context to register the event handler with. 70 * @param hnd The event handler to be registered. @c NULL if to be 71 * de-registered. 72 */ 73 void coap_register_event_handler(struct coap_context_t *context, 74 coap_event_handler_t hnd); 75 76 /** 77 * Registers the function @p hnd as callback for events from the given 78 * CoAP context @p context. Any event handler that has previously been 79 * registered with @p context will be overwritten by this operation. 80 * 81 * @deprecated Use coap_register_event_handler() instead. 82 * 83 * @param context The CoAP context to register the event handler with. 84 * @param hnd The event handler to be registered. 85 */ 86 COAP_DEPRECATED 87 void coap_set_event_handler(struct coap_context_t *context, 88 coap_event_handler_t hnd); 89 90 /** 91 * Clears the event handler registered with @p context. 92 * 93 * @deprecated Use coap_register_event_handler() instead with NULL for hnd. 94 * 95 * @param context The CoAP context whose event handler is to be removed. 96 */ 97 COAP_DEPRECATED 98 void coap_clear_event_handler(struct coap_context_t *context); 99 100 /** @} */ 101 102 #endif /* COAP_EVENT_H */ 103