Chirp Callbacks

/* clang-format off */

If you are on an embedded platform you have to set the memory functions of chirp, libuv and openssl.

/* clang-format on */

#ifndef ch_libchirp_callbacks_h
#define ch_libchirp_callbacks_h

#include "common.h"

System includes

#include <stdlib.h>
ch_alloc_cb_t

Callback used by chirp to request memory.

size_t size

The size to allocate

typedef void* (*ch_alloc_cb_t)(size_t size);
ch_done_cb_t

Callback called when chirp has closed.

ch_chirp_t* chirp

Chirp object closed.

typedef void (*ch_done_cb_t)(ch_chirp_t* chirp);
ch_free_cb_t

Callback used by chirp to free memory.

typedef void (*ch_free_cb_t)(void* buf);
ch_log_cb_t

Logging callback

char msg[]

The message to log

char error

The message is a error

typedef void (*ch_log_cb_t)(char msg[], char error);
ch_send_cb_t

Called by chirp when message is sent and can be freed.

ch_chirp_t* chirp

Chirp instance sending

int status

Error code: CH_SUCCESS, CH_TIMEOUT, CH_CANNOT_CONNECT, CH_TLS_ERROR, CH_WRITE_ERROR, CH_SHUTDOWN, CH_FATAL, CH_PROTOCOL_ERROR, CH_ENOMEM

typedef void (*ch_send_cb_t)(
        ch_chirp_t* chirp, ch_message_t* msg, ch_error_t status);
ch_recv_cb_t

Called by chirp when message is received.

ch_chirp_t* chirp

Chirp instance receiving

ch_message_t* msg

Received message. The address is the remote address, so changing only the user_data and send it, will send the message back to the sender.

typedef void (*ch_recv_cb_t)(ch_chirp_t* chirp, ch_message_t* msg);
ch_release_cb_t

Called by chirp when message is released.

ch_chirp_t* chirp

Chirp instance

uint8_t identity[CH_ID_SIZE] identity

Identity of the message released

uint32_t serial

Serial of the message released

typedef void (*ch_release_cb_t)(
        ch_chirp_t* chirp, uint8_t identity[CH_ID_SIZE], uint32_t serial);
ch_start_cb_t

Callback called when chirp is started

ch_chirp_t* chirp

Chirp instance started

typedef void (*ch_start_cb_t)(ch_chirp_t* chirp);
ch_realloc_cb_t

Callback used by chirp to request memory reallocation.

void* buf

The Buffer to reallocate

size_t new_size

The requested new size

typedef void* (*ch_realloc_cb_t)(void* buf, size_t new_size);

#endif // ch_libchirp_callbacks_h