Skip to content

Commit

Permalink
Use z_result_t for all methods returning error code
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Sep 18, 2024
1 parent c9deea0 commit 95c1c48
Show file tree
Hide file tree
Showing 181 changed files with 1,870 additions and 1,842 deletions.
20 changes: 11 additions & 9 deletions include/zenoh-pico/api/handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C" {
z_free(src); \
} \
static inline void _z_##handler_name##_close(void *context) { \
int8_t ret = collection_close_f((collection_type *)context); \
z_result_t ret = collection_close_f((collection_type *)context); \
if (ret < 0) { \
_Z_ERROR("%s failed: %i", #collection_push_f, ret); \
} \
Expand All @@ -60,14 +60,16 @@ extern "C" {
return; \
} \
elem_clone_f(internal_elem, elem); \
int8_t ret = collection_push_f(internal_elem, context, _z_##handler_name##_elem_free); \
z_result_t ret = collection_push_f(internal_elem, context, _z_##handler_name##_elem_free); \
if (ret != _Z_RES_OK) { \
_Z_ERROR("%s failed: %i", #collection_push_f, ret); \
} \
} \
static inline int8_t z_##handler_name##_recv(const z_loaned_##handler_name##_t *handler, elem_owned_type *elem) { \
static inline z_result_t z_##handler_name##_recv(const z_loaned_##handler_name##_t *handler, \
elem_owned_type *elem) { \
elem_null_f(elem); \
int8_t ret = collection_pull_f(elem, (collection_type *)handler->collection, _z_##handler_name##_elem_move); \
z_result_t ret = \
collection_pull_f(elem, (collection_type *)handler->collection, _z_##handler_name##_elem_move); \
if (ret == _Z_RES_CHANNEL_CLOSED) { \
return Z_CHANNEL_DISCONNECTED; \
} \
Expand All @@ -77,10 +79,10 @@ extern "C" {
} \
return _Z_RES_OK; \
} \
static inline int8_t z_##handler_name##_try_recv(const z_loaned_##handler_name##_t *handler, \
elem_owned_type *elem) { \
static inline z_result_t z_##handler_name##_try_recv(const z_loaned_##handler_name##_t *handler, \
elem_owned_type *elem) { \
elem_null_f(elem); \
int8_t ret = \
z_result_t ret = \
collection_try_pull_f(elem, (collection_type *)handler->collection, _z_##handler_name##_elem_move); \
if (ret == _Z_RES_CHANNEL_CLOSED) { \
return Z_CHANNEL_DISCONNECTED; \
Expand Down Expand Up @@ -110,8 +112,8 @@ extern "C" {
_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_INLINE_IMPL(handler_type, handler_name, _z_##handler_name##_check, \
_z_##handler_name##_null, _z_##handler_name##_clear) \
\
static inline int8_t handler_new_f_name(callback_type *callback, z_owned_##handler_name##_t *handler, \
size_t capacity) { \
static inline z_result_t handler_new_f_name(callback_type *callback, z_owned_##handler_name##_t *handler, \
size_t capacity) { \
if (capacity < 1) { \
return _Z_ERR_INVALID; \
} \
Expand Down
26 changes: 14 additions & 12 deletions include/zenoh-pico/api/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,20 +677,22 @@ inline void z_take(z_owned_fifo_handler_reply_t* this_, z_moved_fifo_handler_rep
}

// z_clone definition
inline int8_t z_clone(z_owned_bytes_t* dst, z_loaned_bytes_t* this_) { return z_bytes_clone(dst, this_); };
inline int8_t z_clone(z_owned_config_t* dst, z_loaned_config_t* this_) { return z_config_clone(dst, this_); };
inline int8_t z_clone(z_owned_encoding_t* dst, z_loaned_encoding_t* this_) { return z_encoding_clone(dst, this_); };
inline int8_t z_clone(z_owned_keyexpr_t* dst, z_loaned_keyexpr_t* this_) { return z_keyexpr_clone(dst, this_); };
inline int8_t z_clone(z_owned_query_t* dst, z_loaned_query_t* this_) { return z_query_clone(dst, this_); };
inline int8_t z_clone(z_owned_reply_t* dst, z_loaned_reply_t* this_) { return z_reply_clone(dst, this_); };
inline int8_t z_clone(z_owned_reply_err_t* dst, z_loaned_reply_err_t* this_) { return z_reply_err_clone(dst, this_); };
inline int8_t z_clone(z_owned_sample_t* dst, z_loaned_sample_t* this_) { return z_sample_clone(dst, this_); };
inline int8_t z_clone(z_owned_slice_t* dst, z_loaned_slice_t* this_) { return z_slice_clone(dst, this_); };
inline int8_t z_clone(z_owned_string_t* dst, z_loaned_string_t* this_) { return z_string_clone(dst, this_); };
inline int8_t z_clone(z_owned_string_array_t* dst, z_loaned_string_array_t* this_) {
inline z_result_t z_clone(z_owned_bytes_t* dst, z_loaned_bytes_t* this_) { return z_bytes_clone(dst, this_); };
inline z_result_t z_clone(z_owned_config_t* dst, z_loaned_config_t* this_) { return z_config_clone(dst, this_); };
inline z_result_t z_clone(z_owned_encoding_t* dst, z_loaned_encoding_t* this_) { return z_encoding_clone(dst, this_); };
inline z_result_t z_clone(z_owned_keyexpr_t* dst, z_loaned_keyexpr_t* this_) { return z_keyexpr_clone(dst, this_); };
inline z_result_t z_clone(z_owned_query_t* dst, z_loaned_query_t* this_) { return z_query_clone(dst, this_); };
inline z_result_t z_clone(z_owned_reply_t* dst, z_loaned_reply_t* this_) { return z_reply_clone(dst, this_); };
inline z_result_t z_clone(z_owned_reply_err_t* dst, z_loaned_reply_err_t* this_) {
return z_reply_err_clone(dst, this_);
};
inline z_result_t z_clone(z_owned_sample_t* dst, z_loaned_sample_t* this_) { return z_sample_clone(dst, this_); };
inline z_result_t z_clone(z_owned_slice_t* dst, z_loaned_slice_t* this_) { return z_slice_clone(dst, this_); };
inline z_result_t z_clone(z_owned_string_t* dst, z_loaned_string_t* this_) { return z_string_clone(dst, this_); };
inline z_result_t z_clone(z_owned_string_array_t* dst, z_loaned_string_array_t* this_) {
return z_string_array_clone(dst, this_);
};
inline int8_t z_clone(z_owned_hello_t* dst, z_loaned_hello_t* this_) { return z_hello_clone(dst, this_); };
inline z_result_t z_clone(z_owned_hello_t* dst, z_loaned_hello_t* this_) { return z_hello_clone(dst, this_); };

template <class T>
struct z_loaned_to_owned_type_t {};
Expand Down
24 changes: 12 additions & 12 deletions include/zenoh-pico/api/olv_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
type _val; \
} z_view_##name##_t;

#define _Z_OWNED_FUNCTIONS_DEF(name) \
void z_internal_##name##_null(z_owned_##name##_t *obj); \
bool z_internal_##name##_check(const z_owned_##name##_t *obj); \
const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj); \
z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj); \
z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj); \
void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src); \
int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src); \
#define _Z_OWNED_FUNCTIONS_DEF(name) \
void z_internal_##name##_null(z_owned_##name##_t *obj); \
bool z_internal_##name##_check(const z_owned_##name##_t *obj); \
const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj); \
z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj); \
z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj); \
void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src); \
z_result_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src); \
void z_##name##_drop(z_moved_##name##_t *obj);

#define _Z_OWNED_FUNCTIONS_NO_COPY_DEF(name) \
Expand Down Expand Up @@ -100,7 +100,7 @@
bool z_internal_##name##_check(const z_owned_##name##_t *obj) { return f_check((&obj->_val)); } \
const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj) { return &obj->_val; } \
z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj) { return &obj->_val; } \
int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \
z_result_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \
return f_copy((&obj->_val), src); \
} \
void z_##name##_drop(z_moved_##name##_t *obj) { \
Expand Down Expand Up @@ -135,8 +135,8 @@
bool z_internal_##name##_check(const z_owned_##name##_t *val) { return !_Z_RC_IS_NULL(&val->_rc); } \
const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val) { return &val->_rc; } \
z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *val) { return &val->_rc; } \
int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \
int8_t ret = _Z_RES_OK; \
z_result_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \
z_result_t ret = _Z_RES_OK; \
obj->_rc = _z_##name##_rc_clone((z_loaned_##name##_t *)src); \
if (_Z_RC_IS_NULL(&obj->_rc)) { \
ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; \
Expand Down Expand Up @@ -186,7 +186,7 @@
obj->_this._val.context = NULL; \
} \
const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val) { return &val->_val; } \
int8_t z_##name(z_owned_##name##_t *closure, f_call call, f_drop drop, void *context) { \
z_result_t z_##name(z_owned_##name##_t *closure, f_call call, f_drop drop, void *context) { \
closure->_val.call = call; \
closure->_val.drop = drop; \
closure->_val.context = context; \
Expand Down
Loading

0 comments on commit 95c1c48

Please sign in to comment.