Loading...
Searching...
No Matches
Event Handling
Application API

API for event delivery from lower-layer library functions. More...

Collaboration diagram for Event Handling:

## Typedefs

typedef int(* | coap_event_handler_t) (coap_session_t *session, const coap_event_t event)
| Type for event handler functions that can be registered with a CoAP context using the function coap_set_event_handler().

## Enumerations

enum

coap_event_t {
COAP_EVENT_DTLS_CLOSED = 0x0000 , COAP_EVENT_DTLS_CONNECTED = 0x01DE , COAP_EVENT_DTLS_RENEGOTIATE = 0x01DF , COAP_EVENT_DTLS_ERROR = 0x0200 ,
COAP_EVENT_TCP_CONNECTED = 0x1001 , COAP_EVENT_TCP_CLOSED = 0x1002 , COAP_EVENT_TCP_FAILED = 0x1003 , COAP_EVENT_SESSION_CONNECTED = 0x2001 ,
COAP_EVENT_SESSION_CLOSED = 0x2002 , COAP_EVENT_SESSION_FAILED = 0x2003 , COAP_EVENT_PARTIAL_BLOCK = 0x3001 , COAP_EVENT_XMIT_BLOCK_FAIL = 0x3002 ,
COAP_EVENT_SERVER_SESSION_NEW = 0x4001 , COAP_EVENT_SERVER_SESSION_DEL = 0x4002 , COAP_EVENT_BAD_PACKET = 0x5001 , COAP_EVENT_MSG_RETRANSMITTED = 0x5002 ,
COAP_EVENT_OSCORE_DECRYPTION_FAILURE = 0x6001 , COAP_EVENT_OSCORE_NOT_ENABLED , COAP_EVENT_OSCORE_NO_PROTECTED_PAYLOAD , COAP_EVENT_OSCORE_NO_SECURITY ,
COAP_EVENT_OSCORE_INTERNAL_ERROR , COAP_EVENT_OSCORE_DECODE_ERROR , COAP_EVENT_WS_PACKET_SIZE = 0x7001 , COAP_EVENT_WS_CONNECTED ,
COAP_EVENT_WS_CLOSED , COAP_EVENT_KEEPALIVE_FAILURE = 0x8001
}

| Scalar type to represent different events, e.g. More...

## Functions

void | coap_register_event_handler (coap_context_t *context, coap_event_handler_t hnd)
| Registers the function `hnd` as callback for events from the given CoAP context `context`.

## Detailed Description

API for event delivery from lower-layer library functions.

## Typedef Documentation

## coap_event_handler_t

typedef int(* coap_event_handler_t) (coap_session_t *session, const coap_event_t event)

Type for event handler functions that can be registered with a CoAP context using the function coap_set_event_handler().

When called by the library, the first argument will be the current coap_session_t object which is associated with the original CoAP context. The second parameter is the event type.

Definition at line 142 of file coap_event.h.

## Enumeration Type Documentation

## coap_event_t

enum coap_event_t

Scalar type to represent different events, e.g.

DTLS events or retransmission timeouts.

Enumerator
COAP_EVENT_DTLS_CLOSED | Triggerred when (D)TLS session closed.
COAP_EVENT_DTLS_CONNECTED | Triggered when (D)TLS session connected.
COAP_EVENT_DTLS_RENEGOTIATE | Triggered when (D)TLS session renegotiated.
COAP_EVENT_DTLS_ERROR | Triggered when (D)TLS error occurs.
COAP_EVENT_TCP_CONNECTED | Triggered when TCP layer connects.
COAP_EVENT_TCP_CLOSED | Triggered when TCP layer is closed.
COAP_EVENT_TCP_FAILED | Triggered when TCP layer fails for some reason.
COAP_EVENT_SESSION_CONNECTED | Triggered when TCP layer completes exchange of CSM information.
COAP_EVENT_SESSION_CLOSED | Triggered when TCP layer closes following exchange of CSM information.
COAP_EVENT_SESSION_FAILED | Triggered when TCP layer fails following exchange of CSM information.
COAP_EVENT_PARTIAL_BLOCK | Triggered when not all of a large body has been received.
COAP_EVENT_XMIT_BLOCK_FAIL | Triggered when not all of a large body has been transmitted.
COAP_EVENT_SERVER_SESSION_NEW | Called in the CoAP IO loop if a new server-side session is created due to an incoming connection. Note that the session might not be a fully established connection yet, it might also refer to, e.g., a DTLS session in a handshake stage.
COAP_EVENT_SERVER_SESSION_DEL | Called in the CoAP IO loop if a server session is deleted (e.g., due to inactivity or because the maximum number of idle sessions was exceeded). The session will still contain valid data when the event handler is called.
COAP_EVENT_BAD_PACKET | Triggered when badly formatted packet received.
COAP_EVENT_MSG_RETRANSMITTED | Triggered when a message is retransmitted.
COAP_EVENT_OSCORE_DECRYPTION_FAILURE | Triggered when there is an OSCORE decryption failure.
COAP_EVENT_OSCORE_NOT_ENABLED | Triggered when trying to use OSCORE to decrypt, but it is not enabled.
COAP_EVENT_OSCORE_NO_PROTECTED_PAYLOAD | Triggered when there is no OSCORE encrypted payload provided.
COAP_EVENT_OSCORE_NO_SECURITY | Triggered when there is no OSCORE security definition found.
COAP_EVENT_OSCORE_INTERNAL_ERROR | Triggered when there is an OSCORE internal error i.e malloc failed.
COAP_EVENT_OSCORE_DECODE_ERROR | Triggered when there is an OSCORE decode of OSCORE option failure.
COAP_EVENT_WS_PACKET_SIZE | Triggered when there is an oversize WebSockets packet.
COAP_EVENT_WS_CONNECTED | Triggered when the WebSockets layer is up.
COAP_EVENT_WS_CLOSED | Triggered when the WebSockets layer is closed.
COAP_EVENT_KEEPALIVE_FAILURE | Triggered when no response to a keep alive (ping) packet.

Definition at line 34 of file coap_event.h.

## Function Documentation

## coap_register_event_handler()

void coap_register_event_handler | ( | coap_context_t * | context,
|  | coap_event_handler_t | hnd
| ) |  |

Registers the function `hnd` as callback for events from the given CoAP context `context`.

Any event handler that has previously been registered with `context` will be overwritten by this operation.

Parameters

  context | The CoAP context to register the event handler with.
  hnd | The event handler to be registered. `NULL` if to be de-registered.

Definition at line 24 of file coap_event.c.