coap_event.[hc]: pass library events to application

An application can register a callback function of type
coap_event_handler_t that will be called by the library on certain
events. Currently, the DTLS implementation invokes coap_handle_event()
with session-specific events such as session close or
renegotiation.
This commit is contained in:
Olaf Bergmann committed 2016-04-08 15:14:20 +02:00
1 parent 578b38dbfa
commit b734208ed2
6 files changed
+119

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
/*
* coap_event.c -- libcoap Event API
*
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#include "coap_event.h"
#include "net.h"
void
coap_set_event_handler(struct coap_context_t *context, coap_event_handler_t hnd) {
context->handle_event = hnd;
}
void
coap_clear_event_handler(struct coap_context_t *context) {
context->handle_event = NULL;
}
+11
View File
@@ -1717,6 +1717,17 @@ coap_dispatch(coap_context_t *context, coap_queue_t *rcvd) {
}
}
int
coap_handle_event(coap_context_t *context, coap_event_t event, void *data) {
coap_log(LOG_DEBUG, "*** EVENT: 0x%04x\n", event);
if (context->handle_event) {
return context->handle_event(context, event, data);
} else {
return 0;
}
}
int
coap_can_exit( coap_context_t *context ) {
return !context || (context->sendqueue == NULL);