diff --git a/include/zenoh-pico/api/handlers.h b/include/zenoh-pico/api/handlers.h index e8b45ccf8..752a6860e 100644 --- a/include/zenoh-pico/api/handlers.h +++ b/include/zenoh-pico/api/handlers.h @@ -37,15 +37,15 @@ \ static inline void _z_##handler_name##_elem_free(void **elem) { \ elem_drop_f((elem_owned_type *)*elem); \ - zp_free(*elem); \ + z_free(*elem); \ *elem = NULL; \ } \ static inline void _z_##handler_name##_elem_move(void *dst, void *src) { \ memcpy(dst, src, sizeof(elem_owned_type)); \ - zp_free(src); \ + z_free(src); \ } \ static inline void _z_##handler_name##_send(const elem_loaned_type *elem, void *context) { \ - elem_owned_type *internal_elem = (elem_owned_type *)zp_malloc(sizeof(elem_owned_type)); \ + elem_owned_type *internal_elem = (elem_owned_type *)z_malloc(sizeof(elem_owned_type)); \ if (internal_elem == NULL) { \ _Z_ERROR("Out of memory"); \ return; \ @@ -126,61 +126,10 @@ void *z_##kind_name##_handler_##item_name##_recv(); \ void *z_##kind_name##_handler_##item_name##_try_recv(); -// -- Channel -#define _Z_CHANNEL_DEFINE(name, send_closure_name, recv_closure_name, send_type, recv_type, collection_type, \ - collection_new_f, collection_free_f, collection_push_f, collection_pull_f, \ - collection_try_pull_f, elem_move_f, elem_convert_f, elem_drop_f) \ - typedef struct { \ - z_owned_##send_closure_name##_t send; \ - z_owned_##recv_closure_name##_t recv; \ - z_owned_##recv_closure_name##_t try_recv; \ - collection_type *collection; \ - } z_owned_##name##_t; \ - \ - static inline void _z_##name##_elem_free(void **elem) { \ - elem_drop_f((recv_type *)*elem); \ - z_free(*elem); \ - *elem = NULL; \ - } \ - static inline void _z_##name##_elem_move(void *dst, void *src) { \ - elem_move_f((recv_type *)dst, (recv_type *)src); \ - } \ - static inline void _z_##name##_send(send_type *elem, void *context) { \ - void *internal_elem = elem_convert_f(elem); \ - if (internal_elem == NULL) { \ - return; \ - } \ - int8_t ret = collection_push_f(internal_elem, context, _z_##name##_elem_free); \ - if (ret != _Z_RES_OK) { \ - _Z_ERROR("%s failed: %i", #collection_push_f, ret); \ - } \ - } \ - static inline void _z_##name##_recv(recv_type *elem, void *context) { \ - int8_t ret = collection_pull_f(elem, context, _z_##name##_elem_move); \ - if (ret != _Z_RES_OK) { \ - _Z_ERROR("%s failed: %i", #collection_pull_f, ret); \ - } \ - } \ - static inline void _z_##name##_try_recv(recv_type *elem, void *context) { \ - int8_t ret = collection_try_pull_f(elem, context, _z_##name##_elem_move); \ - if (ret != _Z_RES_OK) { \ - _Z_ERROR("%s failed: %i", #collection_try_pull_f, ret); \ - } \ - } \ - \ - static inline int8_t z_##name##_new(z_owned_##name##_t *channel, size_t capacity) { \ - channel->collection = collection_new_f(capacity); \ - z_##send_closure_name(&channel->send, _z_##name##_send, NULL, channel->collection); \ - z_##recv_closure_name(&channel->recv, _z_##name##_recv, NULL, channel->collection); \ - z_##recv_closure_name(&channel->try_recv, _z_##name##_try_recv, NULL, channel->collection); \ - return _Z_RES_OK; \ - } \ - static inline z_owned_##name##_t *z_##name##_move(z_owned_##name##_t *val) { return val; } \ - static inline void z_##name##_drop(z_owned_##name##_t *channel) { \ - collection_free_f(channel->collection, _z_##name##_elem_free); \ - z_##send_closure_name##_drop(&channel->send); \ - z_##recv_closure_name##_drop(&channel->recv); \ - } +// This macro defines: +// z_ring_channel_sample_new() +// z_owned_ring_handler_sample_t/z_loaned_ring_handler_sample_t +_Z_CHANNEL_DEFINE(sample, ring) // This macro defines: // z_fifo_channel_sample_new() diff --git a/src/api/api.c b/src/api/api.c index 386d4dc03..c1ad88e1d 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -256,21 +256,8 @@ int8_t z_encoding_clone(z_owned_encoding_t *dst, const z_loaned_encoding_t *src) const z_loaned_encoding_t *z_encoding_loan(const z_owned_encoding_t *encoding) { return encoding->_val; } -const z_loaned_bytes_t *z_value_payload(const z_loaned_value_t *value) { return &value->payload; } - z_loaned_encoding_t *z_encoding_loan_mut(z_owned_encoding_t *encoding) { return encoding->_val; } -// Convert a user owned encoding to an internal encoding, return default encoding if value invalid -static _z_encoding_t _z_encoding_from_owned(const z_owned_encoding_t *encoding) { - if (encoding == NULL) { - return _z_encoding_null(); - } - if (encoding->_val == NULL) { - return _z_encoding_null(); - } - return *encoding->_val; -} - const uint8_t *z_slice_data(const z_loaned_slice_t *slice) { return slice->start; } size_t z_slice_len(const z_loaned_slice_t *slice) { return slice->len; }