From 8ce139d349bc273fdf82f372635784373a32db89 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 31 Jul 2021 17:08:10 +0100 Subject: [PATCH] coap_event.h: Make coap_event_t an enum examples/coap-client.c: examples/coap-server.c: Explicitly define each enum case to remove complier warnings. --- examples/coap-client.c | 8 ++++++++ examples/coap-server.c | 8 ++++++++ include/coap3/coap_event.h | 28 ++++++++++++++-------------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/examples/coap-client.c b/examples/coap-client.c index 92f522ae89..243b64a5c1 100644 --- a/examples/coap-client.c +++ b/examples/coap-client.c @@ -280,6 +280,14 @@ event_handler(coap_session_t *session COAP_UNUSED, case COAP_EVENT_SESSION_CLOSED: quit = 1; break; + case COAP_EVENT_DTLS_CONNECTED: + case COAP_EVENT_DTLS_RENEGOTIATE: + case COAP_EVENT_DTLS_ERROR: + case COAP_EVENT_TCP_CONNECTED: + case COAP_EVENT_TCP_FAILED: + case COAP_EVENT_SESSION_CONNECTED: + case COAP_EVENT_SESSION_FAILED: + case COAP_EVENT_PARTIAL_BLOCK: default: break; } diff --git a/examples/coap-server.c b/examples/coap-server.c index 0c6a19fad1..5687932f0c 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -1585,6 +1585,14 @@ proxy_event_handler(coap_session_t *session, /* Need to remove any proxy associations */ remove_proxy_association(session, 0); break; + case COAP_EVENT_DTLS_CONNECTED: + case COAP_EVENT_DTLS_RENEGOTIATE: + case COAP_EVENT_DTLS_ERROR: + case COAP_EVENT_TCP_CONNECTED: + case COAP_EVENT_TCP_FAILED: + case COAP_EVENT_SESSION_CONNECTED: + case COAP_EVENT_SESSION_FAILED: + case COAP_EVENT_PARTIAL_BLOCK: default: break; } diff --git a/include/coap3/coap_event.h b/include/coap3/coap_event.h index 89b2a63967..b6ea60524a 100644 --- a/include/coap3/coap_event.h +++ b/include/coap3/coap_event.h @@ -24,34 +24,34 @@ * Scalar type to represent different events, e.g. DTLS events or * retransmission timeouts. */ - typedef unsigned int coap_event_t; - +typedef enum coap_event_t { /** * (D)TLS events for COAP_PROTO_DTLS and COAP_PROTO_TLS */ -#define COAP_EVENT_DTLS_CLOSED 0x0000 -#define COAP_EVENT_DTLS_CONNECTED 0x01DE -#define COAP_EVENT_DTLS_RENEGOTIATE 0x01DF -#define COAP_EVENT_DTLS_ERROR 0x0200 + COAP_EVENT_DTLS_CLOSED = 0x0000, + COAP_EVENT_DTLS_CONNECTED = 0x01DE, + COAP_EVENT_DTLS_RENEGOTIATE = 0x01DF, + COAP_EVENT_DTLS_ERROR = 0x0200, /** * TCP events for COAP_PROTO_TCP and COAP_PROTO_TLS */ -#define COAP_EVENT_TCP_CONNECTED 0x1001 -#define COAP_EVENT_TCP_CLOSED 0x1002 -#define COAP_EVENT_TCP_FAILED 0x1003 + COAP_EVENT_TCP_CONNECTED = 0x1001, + COAP_EVENT_TCP_CLOSED = 0x1002, + COAP_EVENT_TCP_FAILED = 0x1003, /** * CSM exchange events for reliable protocols only */ -#define COAP_EVENT_SESSION_CONNECTED 0x2001 -#define COAP_EVENT_SESSION_CLOSED 0x2002 -#define COAP_EVENT_SESSION_FAILED 0x2003 + COAP_EVENT_SESSION_CONNECTED = 0x2001, + COAP_EVENT_SESSION_CLOSED = 0x2002, + COAP_EVENT_SESSION_FAILED = 0x2003, /** - * BLOCK2 receive errors + * (Q-)BLOCK receive errors */ -#define COAP_EVENT_PARTIAL_BLOCK 0x3001 + COAP_EVENT_PARTIAL_BLOCK = 0x3001 +} coap_event_t; /** * Type for event handler functions that can be registered with a CoAP