diff --git a/include/zenoh-pico/api/handlers.h b/include/zenoh-pico/api/handlers.h index d578e24a9..52e3f2ce4 100644 --- a/include/zenoh-pico/api/handlers.h +++ b/include/zenoh-pico/api/handlers.h @@ -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); \ } \ @@ -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; \ } \ @@ -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; \ @@ -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; \ } \ diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index 541203ad5..9ca304f41 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -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 struct z_loaned_to_owned_type_t {}; diff --git a/include/zenoh-pico/api/olv_macros.h b/include/zenoh-pico/api/olv_macros.h index 42d60e143..006fd2024 100644 --- a/include/zenoh-pico/api/olv_macros.h +++ b/include/zenoh-pico/api/olv_macros.h @@ -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) \ @@ -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) { \ @@ -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; \ @@ -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; \ diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 5b14558a2..37edbaba2 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -42,7 +42,7 @@ extern "C" { * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_view_string_from_str(z_view_string_t *str, const char *value); +z_result_t z_view_string_from_str(z_view_string_t *str, const char *value); /** * Builds a :c:type:`z_view_string_t` by wrapping a ``const char *`` substring. @@ -55,7 +55,7 @@ int8_t z_view_string_from_str(z_view_string_t *str, const char *value); * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_view_string_from_substr(z_view_string_t *str, const char *value, size_t len); +z_result_t z_view_string_from_substr(z_view_string_t *str, const char *value, size_t len); /** * Builds a :c:type:`z_keyexpr_t` from a null-terminated string. @@ -69,7 +69,7 @@ int8_t z_view_string_from_substr(z_view_string_t *str, const char *value, size_t * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_view_keyexpr_from_str(z_view_keyexpr_t *keyexpr, const char *name); +z_result_t z_view_keyexpr_from_str(z_view_keyexpr_t *keyexpr, const char *name); /** * Builds a :c:type:`z_keyexpr_t` from a null-terminated string. @@ -96,7 +96,7 @@ void z_view_keyexpr_from_str_unchecked(z_view_keyexpr_t *keyexpr, const char *na * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_view_keyexpr_from_str_autocanonize(z_view_keyexpr_t *keyexpr, char *name); +z_result_t z_view_keyexpr_from_str_autocanonize(z_view_keyexpr_t *keyexpr, char *name); /** * Builds a :c:type:`z_keyexpr_t` by aliasing a substring. @@ -152,7 +152,7 @@ void z_view_keyexpr_from_substr_unchecked(z_view_keyexpr_t *keyexpr, const char * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_keyexpr_as_view_string(const z_loaned_keyexpr_t *keyexpr, z_view_string_t *str); +z_result_t z_keyexpr_as_view_string(const z_loaned_keyexpr_t *keyexpr, z_view_string_t *str); /** * Constructs key expression by concatenation of key expression in `left` with a string in `right`. @@ -170,7 +170,7 @@ int8_t z_keyexpr_as_view_string(const z_loaned_keyexpr_t *keyexpr, z_view_string * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const char *right, size_t len); +z_result_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const char *right, size_t len); /** * Constructs key expression by performing path-joining (automatically inserting '/'). The resulting key expression is @@ -184,7 +184,7 @@ int8_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_keyexpr_join(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const z_loaned_keyexpr_t *right); +z_result_t z_keyexpr_join(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const z_loaned_keyexpr_t *right); /** * Returns the relation between `left` and `right` from `left`'s point of view. @@ -212,7 +212,7 @@ z_keyexpr_intersection_level_t z_keyexpr_relation_to(const z_loaned_keyexpr_t *l * ``0`` if passed string is a valid (and canon) key expression, or a ``negative value`` otherwise. * Error codes are defined in :c:enum:`zp_keyexpr_canon_status_t`. */ -int8_t z_keyexpr_is_canon(const char *start, size_t len); +z_result_t z_keyexpr_is_canon(const char *start, size_t len); /** * Canonizes of a given keyexpr in string representation. @@ -226,7 +226,7 @@ int8_t z_keyexpr_is_canon(const char *start, size_t len); * ``0`` if canonization successful, or a ``negative value`` otherwise. * Error codes are defined in :c:enum:`zp_keyexpr_canon_status_t`. */ -int8_t z_keyexpr_canonize(char *start, size_t *len); +z_result_t z_keyexpr_canonize(char *start, size_t *len); /** * Canonizes of a given keyexpr in string representation. @@ -239,7 +239,7 @@ int8_t z_keyexpr_canonize(char *start, size_t *len); * ``0`` if canonization successful, or a ``negative value`` otherwise. * Error codes are defined in :c:enum:`zp_keyexpr_canon_status_t`. */ -int8_t z_keyexpr_canonize_null_terminated(char *start); +z_result_t z_keyexpr_canonize_null_terminated(char *start); /** * Checks if a given keyexpr contains another keyexpr in its set. @@ -298,7 +298,7 @@ void z_config_new(z_owned_config_t *config); * Return: * `0`` in case of success, or a ``negative value`` otherwise. */ -int8_t z_config_default(z_owned_config_t *config); +z_result_t z_config_default(z_owned_config_t *config); /** * Gets the property with the given integer key from the configuration. @@ -323,7 +323,7 @@ const char *zp_config_get(const z_loaned_config_t *config, uint8_t key); * Return: * ``0`` if insertion successful, ``negative value`` otherwise. */ -int8_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char *value); +z_result_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char *value); /** * Builds a :c:type:`z_owned_encoding_t` from a null terminated string. @@ -335,7 +335,7 @@ int8_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char *valu * Return: * ``0`` if creation successful,``negative value`` otherwise. */ -int8_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s); +z_result_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s); /** * Builds a :c:type:`z_owned_encoding_t` from a null terminated string. @@ -348,7 +348,7 @@ int8_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s); * Return: * ``0`` if creation successful,``negative value`` otherwise. */ -int8_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len); +z_result_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len); /** * Sets a schema to this encoding from a null-terminated string. Zenoh does not define what a schema is and its @@ -360,7 +360,7 @@ int8_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_ * Return: * ``0`` in case of success,``negative value`` otherwise. */ -int8_t z_encoding_set_schema_from_str(z_loaned_encoding_t *encoding, const char *schema); +z_result_t z_encoding_set_schema_from_str(z_loaned_encoding_t *encoding, const char *schema); /** * Sets a schema to this encoding from a substring. Zenoh does not define what a schema is and its semantics is left @@ -373,7 +373,7 @@ int8_t z_encoding_set_schema_from_str(z_loaned_encoding_t *encoding, const char * Return: * ``0`` if in case of success,``negative value`` otherwise. */ -int8_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const char *schema, size_t len); +z_result_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const char *schema, size_t len); /** * Builds a string from a :c:type:`z_loaned_encoding_t`. @@ -385,7 +385,7 @@ int8_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const ch * Return: * ``0`` if creation successful,``negative value`` otherwise. */ -int8_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_t *string); +z_result_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_t *string); /** * Gets the bytes data from a reply error payload by aliasing it. @@ -420,7 +420,7 @@ const z_loaned_encoding_t *z_reply_err_encoding(const z_loaned_reply_err_t *repl * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_slice_copy_from_buf(z_owned_slice_t *slice, const uint8_t *data, size_t len); +z_result_t z_slice_copy_from_buf(z_owned_slice_t *slice, const uint8_t *data, size_t len); /** * Builds a :c:type:`z_owned_slice_t` by transferring ownership over a data to it. @@ -436,8 +436,8 @@ int8_t z_slice_copy_from_buf(z_owned_slice_t *slice, const uint8_t *data, size_t * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_slice_from_buf(z_owned_slice_t *slice, uint8_t *data, size_t len, void (*deleter)(void *data, void *context), - void *context); +z_result_t z_slice_from_buf(z_owned_slice_t *slice, uint8_t *data, size_t len, + void (*deleter)(void *data, void *context), void *context); /** * Builds an empty :c:type:`z_owned_slice_t`. @@ -489,7 +489,7 @@ bool z_slice_is_empty(const z_loaned_slice_t *slice); * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_int8(const z_loaned_bytes_t *bytes, int8_t *dst); +z_result_t z_bytes_deserialize_into_int8(const z_loaned_bytes_t *bytes, int8_t *dst); /** * Decodes data into a `int16_t` signed integer. @@ -501,7 +501,7 @@ int8_t z_bytes_deserialize_into_int8(const z_loaned_bytes_t *bytes, int8_t *dst) * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_int16(const z_loaned_bytes_t *bytes, int16_t *dst); +z_result_t z_bytes_deserialize_into_int16(const z_loaned_bytes_t *bytes, int16_t *dst); /** * Decodes data into a `int32_t` signed integer. @@ -513,7 +513,7 @@ int8_t z_bytes_deserialize_into_int16(const z_loaned_bytes_t *bytes, int16_t *ds * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_int32(const z_loaned_bytes_t *bytes, int32_t *dst); +z_result_t z_bytes_deserialize_into_int32(const z_loaned_bytes_t *bytes, int32_t *dst); /** * Decodes data into a `int64_t` signed integer. @@ -525,7 +525,7 @@ int8_t z_bytes_deserialize_into_int32(const z_loaned_bytes_t *bytes, int32_t *ds * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_int64(const z_loaned_bytes_t *bytes, int64_t *dst); +z_result_t z_bytes_deserialize_into_int64(const z_loaned_bytes_t *bytes, int64_t *dst); /** * Decodes data into a `uint8_t` unsigned integer. @@ -537,7 +537,7 @@ int8_t z_bytes_deserialize_into_int64(const z_loaned_bytes_t *bytes, int64_t *ds * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_uint8(const z_loaned_bytes_t *bytes, uint8_t *dst); +z_result_t z_bytes_deserialize_into_uint8(const z_loaned_bytes_t *bytes, uint8_t *dst); /** * Decodes data into a `uint16_t` unsigned integer. @@ -549,7 +549,7 @@ int8_t z_bytes_deserialize_into_uint8(const z_loaned_bytes_t *bytes, uint8_t *ds * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_uint16(const z_loaned_bytes_t *bytes, uint16_t *dst); +z_result_t z_bytes_deserialize_into_uint16(const z_loaned_bytes_t *bytes, uint16_t *dst); /** * Decodes data into a `uint32_t` unsigned integer. @@ -561,7 +561,7 @@ int8_t z_bytes_deserialize_into_uint16(const z_loaned_bytes_t *bytes, uint16_t * * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_uint32(const z_loaned_bytes_t *bytes, uint32_t *dst); +z_result_t z_bytes_deserialize_into_uint32(const z_loaned_bytes_t *bytes, uint32_t *dst); /** * Decodes data into a `uint64_t` unsigned integer. @@ -573,7 +573,7 @@ int8_t z_bytes_deserialize_into_uint32(const z_loaned_bytes_t *bytes, uint32_t * * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_uint64(const z_loaned_bytes_t *bytes, uint64_t *dst); +z_result_t z_bytes_deserialize_into_uint64(const z_loaned_bytes_t *bytes, uint64_t *dst); /** * Decodes data into a `float` floating number. @@ -585,7 +585,7 @@ int8_t z_bytes_deserialize_into_uint64(const z_loaned_bytes_t *bytes, uint64_t * * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_float(const z_loaned_bytes_t *bytes, float *dst); +z_result_t z_bytes_deserialize_into_float(const z_loaned_bytes_t *bytes, float *dst); /** * Decodes data into a `double` floating number. @@ -597,7 +597,7 @@ int8_t z_bytes_deserialize_into_float(const z_loaned_bytes_t *bytes, float *dst) * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_double(const z_loaned_bytes_t *bytes, double *dst); +z_result_t z_bytes_deserialize_into_double(const z_loaned_bytes_t *bytes, double *dst); /** * Decodes data into a :c:type:`z_owned_slice_t` @@ -609,7 +609,7 @@ int8_t z_bytes_deserialize_into_double(const z_loaned_bytes_t *bytes, double *ds * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_slice(const z_loaned_bytes_t *bytes, z_owned_slice_t *dst); +z_result_t z_bytes_deserialize_into_slice(const z_loaned_bytes_t *bytes, z_owned_slice_t *dst); /** * Decodes data into a :c:type:`z_owned_string_t` @@ -621,7 +621,7 @@ int8_t z_bytes_deserialize_into_slice(const z_loaned_bytes_t *bytes, z_owned_sli * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_string(const z_loaned_bytes_t *bytes, z_owned_string_t *str); +z_result_t z_bytes_deserialize_into_string(const z_loaned_bytes_t *bytes, z_owned_string_t *str); /** * Decodes data into a pair of :c:type:`z_owned_bytes_t` @@ -634,7 +634,8 @@ int8_t z_bytes_deserialize_into_string(const z_loaned_bytes_t *bytes, z_owned_st * Return: * ``0`` if decode successful, or a ``negative value`` otherwise. */ -int8_t z_bytes_deserialize_into_pair(const z_loaned_bytes_t *bytes, z_owned_bytes_t *first, z_owned_bytes_t *second); +z_result_t z_bytes_deserialize_into_pair(const z_loaned_bytes_t *bytes, z_owned_bytes_t *first, + z_owned_bytes_t *second); /** * Encodes a signed integer into a :c:type:`z_owned_bytes_t` @@ -646,7 +647,7 @@ int8_t z_bytes_deserialize_into_pair(const z_loaned_bytes_t *bytes, z_owned_byte * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_int8(z_owned_bytes_t *bytes, int8_t val); +z_result_t z_bytes_serialize_from_int8(z_owned_bytes_t *bytes, int8_t val); /** * Encodes a signed integer into a :c:type:`z_owned_bytes_t` @@ -658,7 +659,7 @@ int8_t z_bytes_serialize_from_int8(z_owned_bytes_t *bytes, int8_t val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_int16(z_owned_bytes_t *bytes, int16_t val); +z_result_t z_bytes_serialize_from_int16(z_owned_bytes_t *bytes, int16_t val); /** * Encodes a signed integer into a :c:type:`z_owned_bytes_t` @@ -670,7 +671,7 @@ int8_t z_bytes_serialize_from_int16(z_owned_bytes_t *bytes, int16_t val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_int32(z_owned_bytes_t *bytes, int32_t val); +z_result_t z_bytes_serialize_from_int32(z_owned_bytes_t *bytes, int32_t val); /** * Encodes a signed integer into a :c:type:`z_owned_bytes_t` @@ -682,7 +683,7 @@ int8_t z_bytes_serialize_from_int32(z_owned_bytes_t *bytes, int32_t val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_int64(z_owned_bytes_t *bytes, int64_t val); +z_result_t z_bytes_serialize_from_int64(z_owned_bytes_t *bytes, int64_t val); /** * Encodes an unsigned integer into a :c:type:`z_owned_bytes_t` @@ -694,7 +695,7 @@ int8_t z_bytes_serialize_from_int64(z_owned_bytes_t *bytes, int64_t val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_uint8(z_owned_bytes_t *bytes, uint8_t val); +z_result_t z_bytes_serialize_from_uint8(z_owned_bytes_t *bytes, uint8_t val); /** * Encodes an unsigned integer into a :c:type:`z_owned_bytes_t` @@ -706,7 +707,7 @@ int8_t z_bytes_serialize_from_uint8(z_owned_bytes_t *bytes, uint8_t val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_uint16(z_owned_bytes_t *bytes, uint16_t val); +z_result_t z_bytes_serialize_from_uint16(z_owned_bytes_t *bytes, uint16_t val); /** * Encodes an unsigned integer into a :c:type:`z_owned_bytes_t` @@ -718,7 +719,7 @@ int8_t z_bytes_serialize_from_uint16(z_owned_bytes_t *bytes, uint16_t val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_uint32(z_owned_bytes_t *bytes, uint32_t val); +z_result_t z_bytes_serialize_from_uint32(z_owned_bytes_t *bytes, uint32_t val); /** * Encodes an unsigned integer into a :c:type:`z_owned_bytes_t` @@ -730,7 +731,7 @@ int8_t z_bytes_serialize_from_uint32(z_owned_bytes_t *bytes, uint32_t val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_uint64(z_owned_bytes_t *bytes, uint64_t val); +z_result_t z_bytes_serialize_from_uint64(z_owned_bytes_t *bytes, uint64_t val); /** * Encodes a floating number into a :c:type:`z_owned_bytes_t` @@ -742,7 +743,7 @@ int8_t z_bytes_serialize_from_uint64(z_owned_bytes_t *bytes, uint64_t val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_float(z_owned_bytes_t *bytes, float val); +z_result_t z_bytes_serialize_from_float(z_owned_bytes_t *bytes, float val); /** * Encodes a floating number into a :c:type:`z_owned_bytes_t` @@ -754,7 +755,7 @@ int8_t z_bytes_serialize_from_float(z_owned_bytes_t *bytes, float val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_double(z_owned_bytes_t *bytes, double val); +z_result_t z_bytes_serialize_from_double(z_owned_bytes_t *bytes, double val); /** * Encodes a slice into a :c:type:`z_owned_bytes_t` by copying. @@ -766,7 +767,7 @@ int8_t z_bytes_serialize_from_double(z_owned_bytes_t *bytes, double val); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_slice(z_owned_bytes_t *bytes, const z_loaned_slice_t *slice); +z_result_t z_bytes_serialize_from_slice(z_owned_bytes_t *bytes, const z_loaned_slice_t *slice); /** * Encodes a slice into a :c:type:`z_owned_bytes_t`. @@ -778,7 +779,7 @@ int8_t z_bytes_serialize_from_slice(z_owned_bytes_t *bytes, const z_loaned_slice * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_slice(z_owned_bytes_t *bytes, z_moved_slice_t *slice); +z_result_t z_bytes_from_slice(z_owned_bytes_t *bytes, z_moved_slice_t *slice); /** * Encodes data into a :c:type:`z_owned_bytes_t`. @@ -794,8 +795,8 @@ int8_t z_bytes_from_slice(z_owned_bytes_t *bytes, z_moved_slice_t *slice); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_buf(z_owned_bytes_t *bytes, uint8_t *data, size_t len, void (*deleter)(void *data, void *context), - void *context); +z_result_t z_bytes_from_buf(z_owned_bytes_t *bytes, uint8_t *data, size_t len, + void (*deleter)(void *data, void *context), void *context); /** * Encodes statically allocated constant data into a :c:type:`z_owned_bytes_t` by aliasing. @@ -808,7 +809,7 @@ int8_t z_bytes_from_buf(z_owned_bytes_t *bytes, uint8_t *data, size_t len, void * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_static_buf(z_owned_bytes_t *bytes, const uint8_t *data, size_t len); +z_result_t z_bytes_from_static_buf(z_owned_bytes_t *bytes, const uint8_t *data, size_t len); /** * Encodes data into a :c:type:`z_owned_bytes_t` by copying. @@ -821,7 +822,7 @@ int8_t z_bytes_from_static_buf(z_owned_bytes_t *bytes, const uint8_t *data, size * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_buf(z_owned_bytes_t *bytes, const uint8_t *data, size_t len); +z_result_t z_bytes_serialize_from_buf(z_owned_bytes_t *bytes, const uint8_t *data, size_t len); /** * Encodes a string into a :c:type:`z_owned_bytes_t` by copying. @@ -833,7 +834,7 @@ int8_t z_bytes_serialize_from_buf(z_owned_bytes_t *bytes, const uint8_t *data, s * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_string(z_owned_bytes_t *bytes, const z_loaned_string_t *s); +z_result_t z_bytes_serialize_from_string(z_owned_bytes_t *bytes, const z_loaned_string_t *s); /** * Encodes a string into a :c:type:`z_owned_bytes_t`. @@ -845,7 +846,7 @@ int8_t z_bytes_serialize_from_string(z_owned_bytes_t *bytes, const z_loaned_stri * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t *s); +z_result_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t *s); /** * Encodes a null-terminated string into a :c:type:`z_owned_bytes_t`. @@ -859,8 +860,8 @@ int8_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t *s); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_str(z_owned_bytes_t *bytes, char *value, void (*deleter)(void *value, void *context), - void *context); +z_result_t z_bytes_from_str(z_owned_bytes_t *bytes, char *value, void (*deleter)(void *value, void *context), + void *context); /** * Encodes a statically allocated constant null-terminated string into a :c:type:`z_owned_bytes_t` by aliasing. @@ -872,7 +873,7 @@ int8_t z_bytes_from_str(z_owned_bytes_t *bytes, char *value, void (*deleter)(voi * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_static_str(z_owned_bytes_t *bytes, const char *value); +z_result_t z_bytes_from_static_str(z_owned_bytes_t *bytes, const char *value); /** * Encodes a null-terminated string into a :c:type:`z_owned_bytes_t` by copying. * @@ -883,7 +884,7 @@ int8_t z_bytes_from_static_str(z_owned_bytes_t *bytes, const char *value); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_serialize_from_str(z_owned_bytes_t *bytes, const char *value); +z_result_t z_bytes_serialize_from_str(z_owned_bytes_t *bytes, const char *value); /** * Constructs payload from an iterator to `z_owned_bytes_t`. @@ -895,8 +896,8 @@ int8_t z_bytes_serialize_from_str(z_owned_bytes_t *bytes, const char *value); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_iter(z_owned_bytes_t *bytes, bool (*iterator_body)(z_owned_bytes_t *data, void *context), - void *context); +z_result_t z_bytes_from_iter(z_owned_bytes_t *bytes, bool (*iterator_body)(z_owned_bytes_t *data, void *context), + void *context); /** * Append a pair of `z_owned_bytes` objects which are consumed in the process. @@ -909,7 +910,7 @@ int8_t z_bytes_from_iter(z_owned_bytes_t *bytes, bool (*iterator_body)(z_owned_b * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_pair(z_owned_bytes_t *bytes, z_moved_bytes_t *first, z_moved_bytes_t *second); +z_result_t z_bytes_from_pair(z_owned_bytes_t *bytes, z_moved_bytes_t *first, z_moved_bytes_t *second); /** * Parameters: @@ -1013,7 +1014,7 @@ z_bytes_reader_t z_bytes_get_reader(const z_loaned_bytes_t *bytes); * Return: * ​0​ upon success, negative error code otherwise. */ -int8_t z_bytes_reader_read_bounded(z_bytes_reader_t *reader, z_owned_bytes_t *dst); +z_result_t z_bytes_reader_read_bounded(z_bytes_reader_t *reader, z_owned_bytes_t *dst); /** * Reads data into specified destination. @@ -1041,7 +1042,7 @@ size_t z_bytes_reader_read(z_bytes_reader_t *reader, uint8_t *dst, size_t len); * Return: * ​0​ upon success, negative error code otherwise. */ -int8_t z_bytes_reader_seek(z_bytes_reader_t *reader, int64_t offset, int origin); +z_result_t z_bytes_reader_seek(z_bytes_reader_t *reader, int64_t offset, int origin); /** * Gets the read position indicator. * @@ -1075,7 +1076,7 @@ z_bytes_writer_t z_bytes_get_writer(z_loaned_bytes_t *bytes); * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_writer_write_all(z_bytes_writer_t *writer, const uint8_t *src, size_t len); +z_result_t z_bytes_writer_write_all(z_bytes_writer_t *writer, const uint8_t *src, size_t len); /** * Appends bytes. @@ -1089,7 +1090,7 @@ int8_t z_bytes_writer_write_all(z_bytes_writer_t *writer, const uint8_t *src, si * Return: * 0 in case of success, negative error code otherwise */ -int8_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t *bytes); +z_result_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t *bytes); /** * Appends bytes, with boundaries information. It would allow to read the same piece of data using @@ -1102,7 +1103,7 @@ int8_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t *bytes); * Return: * 0 in case of success, negative error code otherwise */ -int8_t z_bytes_writer_append_bounded(z_bytes_writer_t *writer, z_moved_bytes_t *bytes); +z_result_t z_bytes_writer_append_bounded(z_bytes_writer_t *writer, z_moved_bytes_t *bytes); /** * Create timestamp. @@ -1114,7 +1115,7 @@ int8_t z_bytes_writer_append_bounded(z_bytes_writer_t *writer, z_moved_bytes_t * * Return: * ``0`` if encode successful, ``negative value`` otherwise (for example if RTC is not available on the system). */ -int8_t z_timestamp_new(z_timestamp_t *ts, const z_loaned_session_t *zs); +z_result_t z_timestamp_new(z_timestamp_t *ts, const z_loaned_session_t *zs); /** * Returns NTP64 time associated with this timestamp. @@ -1261,8 +1262,8 @@ const z_loaned_keyexpr_t *z_query_keyexpr(const z_loaned_query_t *query); * Return: * The sample closure. */ -int8_t z_closure_sample(z_owned_closure_sample_t *closure, z_data_handler_t call, z_dropper_handler_t drop, - void *context); +z_result_t z_closure_sample(z_owned_closure_sample_t *closure, z_data_handler_t call, z_dropper_handler_t drop, + void *context); /** * Builds a new query closure. @@ -1276,8 +1277,8 @@ int8_t z_closure_sample(z_owned_closure_sample_t *closure, z_data_handler_t call * Return: * The query closure. */ -int8_t z_closure_query(z_owned_closure_query_t *closure, z_queryable_handler_t call, z_dropper_handler_t drop, - void *context); +z_result_t z_closure_query(z_owned_closure_query_t *closure, z_queryable_handler_t call, z_dropper_handler_t drop, + void *context); /** * Builds a new reply closure. @@ -1291,8 +1292,8 @@ int8_t z_closure_query(z_owned_closure_query_t *closure, z_queryable_handler_t c * Return: * The reply closure. */ -int8_t z_closure_reply(z_owned_closure_reply_t *closure, z_reply_handler_t call, z_dropper_handler_t drop, - void *context); +z_result_t z_closure_reply(z_owned_closure_reply_t *closure, z_reply_handler_t call, z_dropper_handler_t drop, + void *context); /** * Builds a new hello closure. @@ -1306,8 +1307,8 @@ int8_t z_closure_reply(z_owned_closure_reply_t *closure, z_reply_handler_t call, * Return: * The hello closure. */ -int8_t z_closure_hello(z_owned_closure_hello_t *closure, z_loaned_hello_handler_t call, z_dropper_handler_t drop, - void *context); +z_result_t z_closure_hello(z_owned_closure_hello_t *closure, z_loaned_hello_handler_t call, z_dropper_handler_t drop, + void *context); /** * Builds a new zid closure. @@ -1321,7 +1322,7 @@ int8_t z_closure_hello(z_owned_closure_hello_t *closure, z_loaned_hello_handler_ * Return: * The hello closure. */ -int8_t z_closure_zid(z_owned_closure_zid_t *closure, z_id_handler_t call, z_dropper_handler_t drop, void *context); +z_result_t z_closure_zid(z_owned_closure_zid_t *closure, z_id_handler_t call, z_dropper_handler_t drop, void *context); /**************** Loans ****************/ _Z_OWNED_FUNCTIONS_DEF(string) @@ -1394,7 +1395,7 @@ size_t z_string_len(const z_loaned_string_t *str); * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_string_copy_from_str(z_owned_string_t *str, const char *value); +z_result_t z_string_copy_from_str(z_owned_string_t *str, const char *value); /** * Builds a :c:type:`z_owned_string_t` by transferring ownership over a null-terminated string to it. @@ -1409,8 +1410,8 @@ int8_t z_string_copy_from_str(z_owned_string_t *str, const char *value); * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_string_from_str(z_owned_string_t *str, char *value, void (*deleter)(void *value, void *context), - void *context); +z_result_t z_string_from_str(z_owned_string_t *str, char *value, void (*deleter)(void *value, void *context), + void *context); /** * Builds an empty :c:type:`z_owned_string_t`. @@ -1431,7 +1432,7 @@ void z_string_empty(z_owned_string_t *str); * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_string_copy_from_substr(z_owned_string_t *str, const char *value, size_t len); +z_result_t z_string_copy_from_substr(z_owned_string_t *str, const char *value, size_t len); /** * Checks if string is empty @@ -1510,7 +1511,7 @@ void z_hello_locators(const z_loaned_hello_t *hello, z_owned_string_array_t *loc * Return: * ``0`` in case of success, ``negative value`` otherwise. */ -int8_t z_whatami_to_view_string(z_whatami_t whatami, z_view_string_t *str_out); +z_result_t z_whatami_to_view_string(z_whatami_t whatami, z_view_string_t *str_out); /************* Primitives **************/ /** @@ -1524,7 +1525,7 @@ int8_t z_whatami_to_view_string(z_whatami_t whatami, z_view_string_t *str_out); * Return: * ``0`` if scouting successfully triggered, ``negative value`` otherwise. */ -int8_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, const z_scout_options_t *options); +z_result_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, const z_scout_options_t *options); /** * Opens a Zenoh session. @@ -1536,7 +1537,7 @@ int8_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, cons * Return: * ``0`` if open successful, ``negative value`` otherwise. */ -int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config, const z_open_options_t *options); +z_result_t z_open(z_owned_session_t *zs, z_moved_config_t *config, const z_open_options_t *options); /** * Closes a Zenoh session. @@ -1547,7 +1548,7 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config, const z_open_opti * Return: * ``0`` if close successful, ``negative value`` otherwise. */ -int8_t z_close(z_moved_session_t *zs, const z_close_options_t *options); +z_result_t z_close(z_moved_session_t *zs, const z_close_options_t *options); /** * Fetches Zenoh IDs of all connected peers. @@ -1562,7 +1563,7 @@ int8_t z_close(z_moved_session_t *zs, const z_close_options_t *options); * Return: * ``0`` if operation successfully triggered, ``negative value`` otherwise. */ -int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback); +z_result_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback); /** * Fetches Zenoh IDs of all connected routers. @@ -1577,7 +1578,7 @@ int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *cal * Return: * ``0`` if operation successfully triggered, ``negative value`` otherwise. */ -int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback); +z_result_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback); /** * Gets the local Zenoh ID associated to a given Zenoh session. @@ -1746,8 +1747,8 @@ void z_delete_options_default(z_delete_options_t *options); * Return: * ``0`` if put operation successful, ``negative value`` otherwise. */ -int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, - const z_put_options_t *options); +z_result_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, + const z_put_options_t *options); /** * Deletes data for a given keyexpr. @@ -1760,7 +1761,7 @@ int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_ * Return: * ``0`` if delete operation successful, ``negative value`` otherwise. */ -int8_t z_delete(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const z_delete_options_t *options); +z_result_t z_delete(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const z_delete_options_t *options); /** * Builds a :c:type:`z_publisher_options_t` with default values. @@ -1784,8 +1785,8 @@ void z_publisher_options_default(z_publisher_options_t *options); * Return: * ``0`` if declare successful, ``negative value`` otherwise. */ -int8_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, - const z_publisher_options_t *options); +z_result_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *zs, + const z_loaned_keyexpr_t *keyexpr, const z_publisher_options_t *options); /** * Undeclares and clears the publisher. @@ -1796,7 +1797,7 @@ int8_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *z * Return: * ``0`` if undeclare successful, ``negative value`` otherwise. */ -int8_t z_undeclare_publisher(z_moved_publisher_t *pub); +z_result_t z_undeclare_publisher(z_moved_publisher_t *pub); /** * Builds a :c:type:`z_publisher_put_options_t` with default values. @@ -1825,8 +1826,8 @@ void z_publisher_delete_options_default(z_publisher_delete_options_t *options); * Return: * ``0`` if put operation successful, ``negative value`` otherwise. */ -int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t *payload, - const z_publisher_put_options_t *options); +z_result_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t *payload, + const z_publisher_put_options_t *options); /** * Deletes data from the keyexpr bound to the given publisher. @@ -1838,7 +1839,7 @@ int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t *payload * Return: * ``0`` if delete operation successful, ``negative value`` otherwise. */ -int8_t z_publisher_delete(const z_loaned_publisher_t *pub, const z_publisher_delete_options_t *options); +z_result_t z_publisher_delete(const z_loaned_publisher_t *pub, const z_publisher_delete_options_t *options); /** * Gets the keyexpr from a publisher. @@ -1874,8 +1875,8 @@ void z_get_options_default(z_get_options_t *options); * Return: * ``0`` if put operation successful, ``negative value`` otherwise. */ -int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const char *parameters, - z_moved_closure_reply_t *callback, z_get_options_t *options); +z_result_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const char *parameters, + z_moved_closure_reply_t *callback, z_get_options_t *options); /** * Checks if queryable answered with an OK, which allows this value to be treated as a sample. * @@ -1950,9 +1951,9 @@ void z_queryable_options_default(z_queryable_options_t *options); * Return: * ``0`` if declare operation successful, ``negative value`` otherwise. */ -int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_session_t *zs, - const z_loaned_keyexpr_t *keyexpr, z_moved_closure_query_t *callback, - const z_queryable_options_t *options); +z_result_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_session_t *zs, + const z_loaned_keyexpr_t *keyexpr, z_moved_closure_query_t *callback, + const z_queryable_options_t *options); /** * Undeclares and clears the queryable. @@ -1963,7 +1964,7 @@ int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_sessio * Return: * ``0`` if undeclare operation successful, ``negative value`` otherwise. */ -int8_t z_undeclare_queryable(z_moved_queryable_t *queryable); +z_result_t z_undeclare_queryable(z_moved_queryable_t *queryable); /** * Builds a :c:type:`z_query_reply_options_t` with default values. @@ -1990,8 +1991,8 @@ void z_query_reply_options_default(z_query_reply_options_t *options); * Return: * ``0`` if reply operation successful, ``negative value`` otherwise. */ -int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, - const z_query_reply_options_t *options); +z_result_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, + const z_query_reply_options_t *options); /** * Builds a :c:type:`z_query_reply_del_options_t` with default values. @@ -2017,8 +2018,8 @@ void z_query_reply_del_options_default(z_query_reply_del_options_t *options); * Return: * ``0`` if reply operation successful, ``negative value`` otherwise. */ -int8_t z_query_reply_del(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, - const z_query_reply_del_options_t *options); +z_result_t z_query_reply_del(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, + const z_query_reply_del_options_t *options); /** * Builds a :c:type:`z_query_reply_err_options_t` with default values. @@ -2044,8 +2045,8 @@ void z_query_reply_err_options_default(z_query_reply_err_options_t *options); * Return: * ``0`` if reply operation successful, ``negative value`` otherwise. */ -int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t *payload, - const z_query_reply_err_options_t *options); +z_result_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t *payload, + const z_query_reply_err_options_t *options); #endif @@ -2059,7 +2060,7 @@ int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t *payload * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_keyexpr_from_str(z_owned_keyexpr_t *keyexpr, const char *name); +z_result_t z_keyexpr_from_str(z_owned_keyexpr_t *keyexpr, const char *name); /** * Builds a new keyexpr from a substring. @@ -2072,7 +2073,7 @@ int8_t z_keyexpr_from_str(z_owned_keyexpr_t *keyexpr, const char *name); * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_keyexpr_from_substr(z_owned_keyexpr_t *keyexpr, const char *name, size_t len); +z_result_t z_keyexpr_from_substr(z_owned_keyexpr_t *keyexpr, const char *name, size_t len); /** * Builds a :c:type:`z_owned_keyexpr_t` from a null-terminated string with auto canonization. @@ -2084,7 +2085,7 @@ int8_t z_keyexpr_from_substr(z_owned_keyexpr_t *keyexpr, const char *name, size_ * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_keyexpr_from_str_autocanonize(z_owned_keyexpr_t *keyexpr, const char *name); +z_result_t z_keyexpr_from_str_autocanonize(z_owned_keyexpr_t *keyexpr, const char *name); /** * Builds a :c:type:`z_owned_keyexpr_t` from a substring with auto canonization. @@ -2098,7 +2099,7 @@ int8_t z_keyexpr_from_str_autocanonize(z_owned_keyexpr_t *keyexpr, const char *n * Return: * ``0`` if creation successful, ``negative value`` otherwise. */ -int8_t z_keyexpr_from_substr_autocanonize(z_owned_keyexpr_t *keyexpr, const char *name, size_t *len); +z_result_t z_keyexpr_from_substr_autocanonize(z_owned_keyexpr_t *keyexpr, const char *name, size_t *len); /** * Declares a keyexpr, so that it is mapped on a numerical id. @@ -2114,8 +2115,8 @@ int8_t z_keyexpr_from_substr_autocanonize(z_owned_keyexpr_t *keyexpr, const char * Return: * ``0`` if declare successful, ``negative value`` otherwise. */ -int8_t z_declare_keyexpr(z_owned_keyexpr_t *declared_keyexpr, const z_loaned_session_t *zs, - const z_loaned_keyexpr_t *keyexpr); +z_result_t z_declare_keyexpr(z_owned_keyexpr_t *declared_keyexpr, const z_loaned_session_t *zs, + const z_loaned_keyexpr_t *keyexpr); /** * Undeclares a keyexpr. @@ -2127,7 +2128,7 @@ int8_t z_declare_keyexpr(z_owned_keyexpr_t *declared_keyexpr, const z_loaned_ses * Return: * ``0`` if undeclare successful, ``negative value`` otherwise. */ -int8_t z_undeclare_keyexpr(z_moved_keyexpr_t *keyexpr, const z_loaned_session_t *zs); +z_result_t z_undeclare_keyexpr(z_moved_keyexpr_t *keyexpr, const z_loaned_session_t *zs); #if Z_FEATURE_SUBSCRIPTION == 1 /** @@ -2154,8 +2155,9 @@ void z_subscriber_options_default(z_subscriber_options_t *options); * Return: * ``0`` if declare successful, ``negative value`` otherwise. */ -int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, - z_moved_closure_sample_t *callback, const z_subscriber_options_t *options); +z_result_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t *zs, + const z_loaned_keyexpr_t *keyexpr, z_moved_closure_sample_t *callback, + const z_subscriber_options_t *options); /** * Undeclares and clears the subscriber. @@ -2166,7 +2168,7 @@ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t * Return: * ``0`` if undeclare successful, ``negative value`` otherwise. */ -int8_t z_undeclare_subscriber(z_moved_subscriber_t *sub); +z_result_t z_undeclare_subscriber(z_moved_subscriber_t *sub); /** * Gets the keyexpr from a subscriber. @@ -2202,7 +2204,7 @@ void zp_task_read_options_default(zp_task_read_options_t *options); * Return: * ``0`` if task started successfully, ``negative value`` otherwise. */ -int8_t zp_start_read_task(z_loaned_session_t *zs, const zp_task_read_options_t *options); +z_result_t zp_start_read_task(z_loaned_session_t *zs, const zp_task_read_options_t *options); /** * Stops the read task. @@ -2215,7 +2217,7 @@ int8_t zp_start_read_task(z_loaned_session_t *zs, const zp_task_read_options_t * * Return: * ``0`` if task stopped successfully, ``negative value`` otherwise. */ -int8_t zp_stop_read_task(z_loaned_session_t *zs); +z_result_t zp_stop_read_task(z_loaned_session_t *zs); /** * Builds a :c:type:`zp_task_lease_options_t` with default value. @@ -2240,7 +2242,7 @@ void zp_task_lease_options_default(zp_task_lease_options_t *options); * Return: * ``0`` if task started successfully, ``negative value`` otherwise. */ -int8_t zp_start_lease_task(z_loaned_session_t *zs, const zp_task_lease_options_t *options); +z_result_t zp_start_lease_task(z_loaned_session_t *zs, const zp_task_lease_options_t *options); /** * Stops the lease task. @@ -2253,7 +2255,7 @@ int8_t zp_start_lease_task(z_loaned_session_t *zs, const zp_task_lease_options_t * Return: * ``0`` if task stopped successfully, ``negative value`` otherwise. */ -int8_t zp_stop_lease_task(z_loaned_session_t *zs); +z_result_t zp_stop_lease_task(z_loaned_session_t *zs); /************* Single Thread helpers **************/ /** @@ -2274,7 +2276,7 @@ void zp_read_options_default(zp_read_options_t *options); * Return: * ``0`` if execution was successful, ``negative value`` otherwise. */ -int8_t zp_read(const z_loaned_session_t *zs, const zp_read_options_t *options); +z_result_t zp_read(const z_loaned_session_t *zs, const zp_read_options_t *options); /** * Builds a :c:type:`zp_send_keep_alive_options_t` with default value. @@ -2294,7 +2296,7 @@ void zp_send_keep_alive_options_default(zp_send_keep_alive_options_t *options); * Return: * ``0`` if execution was successful, ``negative value`` otherwise. */ -int8_t zp_send_keep_alive(const z_loaned_session_t *zs, const zp_send_keep_alive_options_t *options); +z_result_t zp_send_keep_alive(const z_loaned_session_t *zs, const zp_send_keep_alive_options_t *options); /** * Builds a :c:type:`zp_send_join_options_t` with default value. @@ -2322,7 +2324,7 @@ void z_scout_options_default(z_scout_options_t *options); * Return: * ``0`` if execution was successful, ``negative value`` otherwise. */ -int8_t zp_send_join(const z_loaned_session_t *zs, const zp_send_join_options_t *options); +z_result_t zp_send_join(const z_loaned_session_t *zs, const zp_send_join_options_t *options); #ifdef __cplusplus } diff --git a/include/zenoh-pico/collections/arc_slice.h b/include/zenoh-pico/collections/arc_slice.h index 2454fb0b2..fa45140cd 100644 --- a/include/zenoh-pico/collections/arc_slice.h +++ b/include/zenoh-pico/collections/arc_slice.h @@ -48,8 +48,8 @@ _z_arc_slice_t _z_arc_slice_get_subslice(const _z_arc_slice_t* s, size_t offset, size_t _z_arc_slice_len(const _z_arc_slice_t* s); bool _z_arc_slice_is_empty(const _z_arc_slice_t* s); const uint8_t* _z_arc_slice_data(const _z_arc_slice_t* s); -int8_t _z_arc_slice_copy(_z_arc_slice_t* dst, const _z_arc_slice_t* src); -int8_t _z_arc_slice_move(_z_arc_slice_t* dst, _z_arc_slice_t* src); -int8_t _z_arc_slice_drop(_z_arc_slice_t* s); +z_result_t _z_arc_slice_copy(_z_arc_slice_t* dst, const _z_arc_slice_t* src); +z_result_t _z_arc_slice_move(_z_arc_slice_t* dst, _z_arc_slice_t* src); +z_result_t _z_arc_slice_drop(_z_arc_slice_t* s); #endif /* ZENOH_PICO_COLLECTIONS_ARC_SLICE_H */ diff --git a/include/zenoh-pico/collections/bytes.h b/include/zenoh-pico/collections/bytes.h index 3090bf5bf..99e70f178 100644 --- a/include/zenoh-pico/collections/bytes.h +++ b/include/zenoh-pico/collections/bytes.h @@ -47,9 +47,9 @@ typedef struct { bool _z_bytes_check(const _z_bytes_t *bytes); _z_bytes_t _z_bytes_null(void); -int8_t _z_bytes_append_bytes(_z_bytes_t *dst, _z_bytes_t *src); -int8_t _z_bytes_append_slice(_z_bytes_t *dst, _z_arc_slice_t *s); -int8_t _z_bytes_copy(_z_bytes_t *dst, const _z_bytes_t *src); +z_result_t _z_bytes_append_bytes(_z_bytes_t *dst, _z_bytes_t *src); +z_result_t _z_bytes_append_slice(_z_bytes_t *dst, _z_arc_slice_t *s); +z_result_t _z_bytes_copy(_z_bytes_t *dst, const _z_bytes_t *src); _z_bytes_t _z_bytes_duplicate(const _z_bytes_t *src); void _z_bytes_move(_z_bytes_t *dst, _z_bytes_t *src); void _z_bytes_drop(_z_bytes_t *bytes); @@ -58,24 +58,24 @@ size_t _z_bytes_num_slices(const _z_bytes_t *bs); _z_arc_slice_t *_z_bytes_get_slice(const _z_bytes_t *bs, size_t i); size_t _z_bytes_len(const _z_bytes_t *bs); bool _z_bytes_is_empty(const _z_bytes_t *bs); -int8_t _z_bytes_to_uint8(const _z_bytes_t *bs, uint8_t *u); -int8_t _z_bytes_to_uint16(const _z_bytes_t *bs, uint16_t *u); -int8_t _z_bytes_to_uint32(const _z_bytes_t *bs, uint32_t *u); -int8_t _z_bytes_to_uint64(const _z_bytes_t *bs, uint64_t *u); -int8_t _z_bytes_to_float(const _z_bytes_t *bs, float *f); -int8_t _z_bytes_to_double(const _z_bytes_t *bs, double *d); -int8_t _z_bytes_to_slice(const _z_bytes_t *bytes, _z_slice_t *s); -int8_t _z_bytes_from_slice(_z_bytes_t *b, _z_slice_t s); -int8_t _z_bytes_from_uint8(_z_bytes_t *b, uint8_t val); -int8_t _z_bytes_from_uint16(_z_bytes_t *b, uint16_t val); -int8_t _z_bytes_from_uint32(_z_bytes_t *b, uint32_t val); -int8_t _z_bytes_from_uint64(_z_bytes_t *b, uint64_t val); -int8_t _z_bytes_from_float(_z_bytes_t *b, float val); -int8_t _z_bytes_from_double(_z_bytes_t *b, double val); +z_result_t _z_bytes_to_uint8(const _z_bytes_t *bs, uint8_t *u); +z_result_t _z_bytes_to_uint16(const _z_bytes_t *bs, uint16_t *u); +z_result_t _z_bytes_to_uint32(const _z_bytes_t *bs, uint32_t *u); +z_result_t _z_bytes_to_uint64(const _z_bytes_t *bs, uint64_t *u); +z_result_t _z_bytes_to_float(const _z_bytes_t *bs, float *f); +z_result_t _z_bytes_to_double(const _z_bytes_t *bs, double *d); +z_result_t _z_bytes_to_slice(const _z_bytes_t *bytes, _z_slice_t *s); +z_result_t _z_bytes_from_slice(_z_bytes_t *b, _z_slice_t s); +z_result_t _z_bytes_from_uint8(_z_bytes_t *b, uint8_t val); +z_result_t _z_bytes_from_uint16(_z_bytes_t *b, uint16_t val); +z_result_t _z_bytes_from_uint32(_z_bytes_t *b, uint32_t val); +z_result_t _z_bytes_from_uint64(_z_bytes_t *b, uint64_t val); +z_result_t _z_bytes_from_float(_z_bytes_t *b, float val); +z_result_t _z_bytes_from_double(_z_bytes_t *b, double val); size_t _z_bytes_to_buf(const _z_bytes_t *bytes, uint8_t *dst, size_t len); -int8_t _z_bytes_from_buf(_z_bytes_t *b, const uint8_t *src, size_t len); -int8_t _z_bytes_from_pair(_z_bytes_t *out, _z_bytes_t *first, _z_bytes_t *second); -int8_t _z_bytes_deserialize_into_pair(const _z_bytes_t *bs, _z_bytes_t *first_out, _z_bytes_t *second_out); +z_result_t _z_bytes_from_buf(_z_bytes_t *b, const uint8_t *src, size_t len); +z_result_t _z_bytes_from_pair(_z_bytes_t *out, _z_bytes_t *first, _z_bytes_t *second); +z_result_t _z_bytes_deserialize_into_pair(const _z_bytes_t *bs, _z_bytes_t *first_out, _z_bytes_t *second_out); _z_slice_t _z_bytes_try_get_contiguous(const _z_bytes_t *bs); typedef struct { @@ -86,9 +86,9 @@ typedef struct { } _z_bytes_reader_t; _z_bytes_reader_t _z_bytes_get_reader(const _z_bytes_t *bytes); -int8_t _z_bytes_reader_seek(_z_bytes_reader_t *reader, int64_t offset, int origin); +z_result_t _z_bytes_reader_seek(_z_bytes_reader_t *reader, int64_t offset, int origin); int64_t _z_bytes_reader_tell(const _z_bytes_reader_t *reader); -int8_t _z_bytes_reader_read_slices(_z_bytes_reader_t *reader, size_t len, _z_bytes_t *out); +z_result_t _z_bytes_reader_read_slices(_z_bytes_reader_t *reader, size_t len, _z_bytes_t *out); size_t _z_bytes_reader_read(_z_bytes_reader_t *reader, uint8_t *buf, size_t len); typedef struct { @@ -96,7 +96,7 @@ typedef struct { } _z_bytes_iterator_t; _z_bytes_iterator_t _z_bytes_get_iterator(const _z_bytes_t *bytes); -int8_t _z_bytes_iterator_next(_z_bytes_iterator_t *iter, _z_bytes_t *b); +z_result_t _z_bytes_iterator_next(_z_bytes_iterator_t *iter, _z_bytes_t *b); typedef struct { uint8_t *cache; @@ -105,14 +105,14 @@ typedef struct { } _z_bytes_writer_t; _z_bytes_writer_t _z_bytes_get_writer(_z_bytes_t *bytes, size_t cache_size); -int8_t _z_bytes_writer_write_all(_z_bytes_writer_t *writer, const uint8_t *src, size_t len); -int8_t _z_bytes_writer_append(_z_bytes_writer_t *writer, _z_bytes_t *bytes); -int8_t _z_bytes_writer_ensure_cache(_z_bytes_writer_t *writer); +z_result_t _z_bytes_writer_write_all(_z_bytes_writer_t *writer, const uint8_t *src, size_t len); +z_result_t _z_bytes_writer_append(_z_bytes_writer_t *writer, _z_bytes_t *bytes); +z_result_t _z_bytes_writer_ensure_cache(_z_bytes_writer_t *writer); typedef struct { _z_bytes_writer_t writer; } _z_bytes_iterator_writer_t; _z_bytes_iterator_writer_t _z_bytes_get_iterator_writer(_z_bytes_t *bytes, size_t cache_size); -int8_t _z_bytes_iterator_writer_write(_z_bytes_iterator_writer_t *writer, _z_bytes_t *bytes); +z_result_t _z_bytes_iterator_writer_write(_z_bytes_iterator_writer_t *writer, _z_bytes_t *bytes); #endif /* ZENOH_PICO_COLLECTIONS_BYTES_H */ diff --git a/include/zenoh-pico/collections/fifo.h b/include/zenoh-pico/collections/fifo.h index c3f3dae61..3e36bb509 100644 --- a/include/zenoh-pico/collections/fifo.h +++ b/include/zenoh-pico/collections/fifo.h @@ -25,7 +25,7 @@ typedef struct { _z_ring_t _ring; } _z_fifo_t; -int8_t _z_fifo_init(_z_fifo_t *fifo, size_t capacity); +z_result_t _z_fifo_init(_z_fifo_t *fifo, size_t capacity); _z_fifo_t _z_fifo_make(size_t capacity); size_t _z_fifo_capacity(const _z_fifo_t *r); @@ -44,7 +44,7 @@ void _z_fifo_free(_z_fifo_t **xs, z_element_free_f f_f); #define _Z_FIFO_DEFINE(name, type) \ typedef _z_fifo_t name##_fifo_t; \ - static inline int8_t name##_fifo_init(name##_fifo_t *fifo, size_t capacity) { \ + static inline z_result_t name##_fifo_init(name##_fifo_t *fifo, size_t capacity) { \ return _z_fifo_init(fifo, capacity); \ } \ static inline name##_fifo_t name##_fifo_make(size_t capacity) { return _z_fifo_make(capacity); } \ diff --git a/include/zenoh-pico/collections/fifo_mt.h b/include/zenoh-pico/collections/fifo_mt.h index 224e178ad..80f78894f 100644 --- a/include/zenoh-pico/collections/fifo_mt.h +++ b/include/zenoh-pico/collections/fifo_mt.h @@ -35,17 +35,17 @@ typedef struct { #endif } _z_fifo_mt_t; -int8_t _z_fifo_mti_init(size_t capacity); +z_result_t _z_fifo_mti_init(size_t capacity); _z_fifo_mt_t *_z_fifo_mt_new(size_t capacity); -int8_t _z_fifo_mt_close(_z_fifo_mt_t *fifo); +z_result_t _z_fifo_mt_close(_z_fifo_mt_t *fifo); void _z_fifo_mt_clear(_z_fifo_mt_t *fifo, z_element_free_f free_f); void _z_fifo_mt_free(_z_fifo_mt_t *fifo, z_element_free_f free_f); -int8_t _z_fifo_mt_push(const void *src, void *context, z_element_free_f element_free); +z_result_t _z_fifo_mt_push(const void *src, void *context, z_element_free_f element_free); -int8_t _z_fifo_mt_pull(void *dst, void *context, z_element_move_f element_move); -int8_t _z_fifo_mt_try_pull(void *dst, void *context, z_element_move_f element_move); +z_result_t _z_fifo_mt_pull(void *dst, void *context, z_element_move_f element_move); +z_result_t _z_fifo_mt_try_pull(void *dst, void *context, z_element_move_f element_move); #ifdef __cplusplus } diff --git a/include/zenoh-pico/collections/intmap.h b/include/zenoh-pico/collections/intmap.h index 737ee4428..c897e2e50 100644 --- a/include/zenoh-pico/collections/intmap.h +++ b/include/zenoh-pico/collections/intmap.h @@ -61,7 +61,7 @@ size_t _z_int_void_map_capacity(const _z_int_void_map_t *map); size_t _z_int_void_map_len(const _z_int_void_map_t *map); bool _z_int_void_map_is_empty(const _z_int_void_map_t *map); -int8_t _z_int_void_map_copy(_z_int_void_map_t *dst, const _z_int_void_map_t *src, z_element_clone_f f_c); +z_result_t _z_int_void_map_copy(_z_int_void_map_t *dst, const _z_int_void_map_t *src, z_element_clone_f f_c); _z_int_void_map_t _z_int_void_map_clone(const _z_int_void_map_t *src, z_element_clone_f f_c, z_element_free_f f_f); void _z_int_void_map_clear(_z_int_void_map_t *map, z_element_free_f f); diff --git a/include/zenoh-pico/collections/lifo.h b/include/zenoh-pico/collections/lifo.h index b17a85f5d..cf696b994 100644 --- a/include/zenoh-pico/collections/lifo.h +++ b/include/zenoh-pico/collections/lifo.h @@ -26,7 +26,7 @@ typedef struct { size_t _len; } _z_lifo_t; -int8_t _z_lifo_init(_z_lifo_t *lifo, size_t capacity); +z_result_t _z_lifo_init(_z_lifo_t *lifo, size_t capacity); _z_lifo_t _z_lifo_make(size_t capacity); size_t _z_lifo_capacity(const _z_lifo_t *r); @@ -45,7 +45,7 @@ void _z_lifo_free(_z_lifo_t **xs, z_element_free_f f_f); #define _Z_LIFO_DEFINE(name, type) \ typedef _z_lifo_t name##_lifo_t; \ - static inline int8_t name##_lifo_init(name##_lifo_t *lifo, size_t capacity) { \ + static inline z_result_t name##_lifo_init(name##_lifo_t *lifo, size_t capacity) { \ return _z_lifo_init(lifo, capacity); \ } \ static inline name##_lifo_t name##_lifo_make(size_t capacity) { return _z_lifo_make(capacity); } \ diff --git a/include/zenoh-pico/collections/refcount.h b/include/zenoh-pico/collections/refcount.h index c005ab6a7..854633b5e 100644 --- a/include/zenoh-pico/collections/refcount.h +++ b/include/zenoh-pico/collections/refcount.h @@ -24,12 +24,12 @@ extern "C" { #endif -int8_t _z_rc_init(void **cnt); -int8_t _z_rc_increase_strong(void *cnt); -int8_t _z_rc_increase_weak(void *cnt); +z_result_t _z_rc_init(void **cnt); +z_result_t _z_rc_increase_strong(void *cnt); +z_result_t _z_rc_increase_weak(void *cnt); bool _z_rc_decrease_strong(void **cnt); bool _z_rc_decrease_weak(void **cnt); -int8_t _z_rc_weak_upgrade(void *cnt); +z_result_t _z_rc_weak_upgrade(void *cnt); size_t _z_rc_weak_count(void *cnt); size_t _z_rc_strong_count(void *cnt); diff --git a/include/zenoh-pico/collections/ring.h b/include/zenoh-pico/collections/ring.h index 3cdcc057c..de8743e58 100644 --- a/include/zenoh-pico/collections/ring.h +++ b/include/zenoh-pico/collections/ring.h @@ -28,7 +28,7 @@ typedef struct { size_t _w_idx; } _z_ring_t; -int8_t _z_ring_init(_z_ring_t *ring, size_t capacity); +z_result_t _z_ring_init(_z_ring_t *ring, size_t capacity); _z_ring_t _z_ring_make(size_t capacity); size_t _z_ring_capacity(const _z_ring_t *r); @@ -48,7 +48,7 @@ void _z_ring_free(_z_ring_t **xs, z_element_free_f f_f); #define _Z_RING_DEFINE(name, type) \ typedef _z_ring_t name##_ring_t; \ - static inline int8_t name##_ring_init(name##_ring_t *ring, size_t capacity) { \ + static inline z_result_t name##_ring_init(name##_ring_t *ring, size_t capacity) { \ return _z_ring_init(ring, capacity); \ } \ static inline name##_ring_t name##_ring_make(size_t capacity) { return _z_ring_make(capacity); } \ diff --git a/include/zenoh-pico/collections/ring_mt.h b/include/zenoh-pico/collections/ring_mt.h index f957b4e98..24256fd50 100644 --- a/include/zenoh-pico/collections/ring_mt.h +++ b/include/zenoh-pico/collections/ring_mt.h @@ -34,17 +34,17 @@ typedef struct { #endif } _z_ring_mt_t; -int8_t _z_ring_mt_init(_z_ring_mt_t *ring, size_t capacity); +z_result_t _z_ring_mt_init(_z_ring_mt_t *ring, size_t capacity); _z_ring_mt_t *_z_ring_mt_new(size_t capacity); -int8_t _z_ring_mt_close(_z_ring_mt_t *ring); +z_result_t _z_ring_mt_close(_z_ring_mt_t *ring); void _z_ring_mt_clear(_z_ring_mt_t *ring, z_element_free_f free_f); void _z_ring_mt_free(_z_ring_mt_t *ring, z_element_free_f free_f); -int8_t _z_ring_mt_push(const void *src, void *context, z_element_free_f element_free); +z_result_t _z_ring_mt_push(const void *src, void *context, z_element_free_f element_free); -int8_t _z_ring_mt_pull(void *dst, void *context, z_element_move_f element_move); -int8_t _z_ring_mt_try_pull(void *dst, void *context, z_element_move_f element_move); +z_result_t _z_ring_mt_pull(void *dst, void *context, z_element_move_f element_move); +z_result_t _z_ring_mt_try_pull(void *dst, void *context, z_element_move_f element_move); #ifdef __cplusplus } diff --git a/include/zenoh-pico/collections/slice.h b/include/zenoh-pico/collections/slice.h index fd09c0c19..8027f6b1c 100644 --- a/include/zenoh-pico/collections/slice.h +++ b/include/zenoh-pico/collections/slice.h @@ -19,6 +19,8 @@ #include #include +#include "zenoh-pico/utils/result.h" + typedef struct { void (*deleter)(void *data, void *context); void *context; @@ -47,15 +49,15 @@ typedef struct { _z_slice_t _z_slice_empty(void); inline static bool _z_slice_check(const _z_slice_t *slice) { return slice->start != NULL; } -int8_t _z_slice_init(_z_slice_t *bs, size_t capacity); +z_result_t _z_slice_init(_z_slice_t *bs, size_t capacity); _z_slice_t _z_slice_make(size_t capacity); _z_slice_t _z_slice_alias_buf(const uint8_t *bs, size_t len); _z_slice_t _z_slice_from_buf_custom_deleter(const uint8_t *p, size_t len, _z_delete_context_t dc); _z_slice_t _z_slice_copy_from_buf(const uint8_t *bs, size_t len); _z_slice_t _z_slice_steal(_z_slice_t *b); _z_slice_t _z_slice_alias(const _z_slice_t *bs); -int8_t _z_slice_copy(_z_slice_t *dst, const _z_slice_t *src); -int8_t _z_slice_n_copy(_z_slice_t *dst, const _z_slice_t *src, size_t offset, size_t len); +z_result_t _z_slice_copy(_z_slice_t *dst, const _z_slice_t *src); +z_result_t _z_slice_n_copy(_z_slice_t *dst, const _z_slice_t *src, size_t offset, size_t len); _z_slice_t _z_slice_duplicate(const _z_slice_t *src); void _z_slice_move(_z_slice_t *dst, _z_slice_t *src); void _z_slice_reset(_z_slice_t *bs); diff --git a/include/zenoh-pico/collections/string.h b/include/zenoh-pico/collections/string.h index 04b0a0876..f2ebd15ac 100644 --- a/include/zenoh-pico/collections/string.h +++ b/include/zenoh-pico/collections/string.h @@ -53,9 +53,9 @@ void _z_str_intmap_onto_str(char *dst, size_t dst_len, const _z_str_intmap_t *s, _z_str_intmapping_t argv[]); char *_z_str_intmap_to_str(const _z_str_intmap_t *s, uint8_t argc, _z_str_intmapping_t argv[]); -int8_t _z_str_intmap_from_str(_z_str_intmap_t *strint, const char *s, uint8_t argc, _z_str_intmapping_t argv[]); -int8_t _z_str_intmap_from_strn(_z_str_intmap_t *strint, const char *s, uint8_t argc, _z_str_intmapping_t argv[], - size_t n); +z_result_t _z_str_intmap_from_str(_z_str_intmap_t *strint, const char *s, uint8_t argc, _z_str_intmapping_t argv[]); +z_result_t _z_str_intmap_from_strn(_z_str_intmap_t *strint, const char *s, uint8_t argc, _z_str_intmapping_t argv[], + size_t n); /*-------- string --------*/ /** @@ -80,8 +80,8 @@ char *_z_string_pbrk(_z_string_t *str, const char *filter); size_t _z_string_len(const _z_string_t *s); const char *_z_string_data(const _z_string_t *s); -int8_t _z_string_copy(_z_string_t *dst, const _z_string_t *src); -int8_t _z_string_copy_substring(_z_string_t *dst, const _z_string_t *src, size_t offset, size_t len); +z_result_t _z_string_copy(_z_string_t *dst, const _z_string_t *src); +z_result_t _z_string_copy_substring(_z_string_t *dst, const _z_string_t *src, size_t offset, size_t len); void _z_string_move(_z_string_t *dst, _z_string_t *src); _z_string_t _z_string_steal(_z_string_t *str); _z_string_t _z_string_alias(const _z_string_t *str); diff --git a/include/zenoh-pico/link/config/bt.h b/include/zenoh-pico/link/config/bt.h index 9910e9886..630b9ae41 100644 --- a/include/zenoh-pico/link/config/bt.h +++ b/include/zenoh-pico/link/config/bt.h @@ -46,8 +46,8 @@ size_t _z_bt_config_strlen(const _z_str_intmap_t *s); void _z_bt_config_onto_str(char *dst, size_t dst_len, const _z_str_intmap_t *s); char *_z_bt_config_to_str(const _z_str_intmap_t *s); -int8_t _z_bt_config_from_str(_z_str_intmap_t *strint, const char *s); -int8_t _z_bt_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); +z_result_t _z_bt_config_from_str(_z_str_intmap_t *strint, const char *s); +z_result_t _z_bt_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); #endif #endif /* ZENOH_PICO_LINK_CONFIG_BT_H */ diff --git a/include/zenoh-pico/link/config/raweth.h b/include/zenoh-pico/link/config/raweth.h index 89313d8b6..a301a09ed 100644 --- a/include/zenoh-pico/link/config/raweth.h +++ b/include/zenoh-pico/link/config/raweth.h @@ -22,10 +22,10 @@ #define RAWETH_SCHEMA "reth" -int8_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint); -int8_t _z_new_link_raweth(_z_link_t *zl, _z_endpoint_t endpoint); +z_result_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint); +z_result_t _z_new_link_raweth(_z_link_t *zl, _z_endpoint_t endpoint); size_t _z_raweth_config_strlen(const _z_str_intmap_t *s); char *_z_raweth_config_to_str(const _z_str_intmap_t *s); -int8_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s); +z_result_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s); #endif /* ZENOH_PICO_LINK_CONFIG_RAWETH_H */ diff --git a/include/zenoh-pico/link/config/serial.h b/include/zenoh-pico/link/config/serial.h index 6960d2ea6..6180d0a59 100644 --- a/include/zenoh-pico/link/config/serial.h +++ b/include/zenoh-pico/link/config/serial.h @@ -62,8 +62,8 @@ size_t _z_serial_config_strlen(const _z_str_intmap_t *s); void _z_serial_config_onto_str(char *dst, size_t dst_len, const _z_str_intmap_t *s); char *_z_serial_config_to_str(const _z_str_intmap_t *s); -int8_t _z_serial_config_from_str(_z_str_intmap_t *strint, const char *s); -int8_t _z_serial_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); +z_result_t _z_serial_config_from_str(_z_str_intmap_t *strint, const char *s); +z_result_t _z_serial_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); #endif #endif /* ZENOH_PICO_LINK_CONFIG_SERIAL_H */ diff --git a/include/zenoh-pico/link/config/tcp.h b/include/zenoh-pico/link/config/tcp.h index 9e3e0f5a8..51792c8ac 100644 --- a/include/zenoh-pico/link/config/tcp.h +++ b/include/zenoh-pico/link/config/tcp.h @@ -36,8 +36,8 @@ size_t _z_tcp_config_strlen(const _z_str_intmap_t *s); void _z_tcp_config_onto_str(char *dst, size_t dst_len, const _z_str_intmap_t *s); char *_z_tcp_config_to_str(const _z_str_intmap_t *s); -int8_t _z_tcp_config_from_str(_z_str_intmap_t *strint, const char *s); -int8_t _z_tcp_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); +z_result_t _z_tcp_config_from_str(_z_str_intmap_t *strint, const char *s); +z_result_t _z_tcp_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); #endif #endif /* ZENOH_PICO_LINK_CONFIG_TCP_H */ diff --git a/include/zenoh-pico/link/config/udp.h b/include/zenoh-pico/link/config/udp.h index fb6ee2c64..8af8b5d47 100644 --- a/include/zenoh-pico/link/config/udp.h +++ b/include/zenoh-pico/link/config/udp.h @@ -44,8 +44,8 @@ size_t _z_udp_config_strlen(const _z_str_intmap_t *s); void _z_udp_config_onto_str(char *dst, size_t dst_len, const _z_str_intmap_t *s); char *_z_udp_config_to_str(const _z_str_intmap_t *s); -int8_t _z_udp_config_from_str(_z_str_intmap_t *strint, const char *s); -int8_t _z_udp_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); +z_result_t _z_udp_config_from_str(_z_str_intmap_t *strint, const char *s); +z_result_t _z_udp_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); #endif #endif /* ZENOH_PICO_LINK_CONFIG_UDP_H */ diff --git a/include/zenoh-pico/link/config/ws.h b/include/zenoh-pico/link/config/ws.h index 82ef8d596..e9c3e6be6 100644 --- a/include/zenoh-pico/link/config/ws.h +++ b/include/zenoh-pico/link/config/ws.h @@ -35,8 +35,8 @@ size_t _z_ws_config_strlen(const _z_str_intmap_t *s); void _z_ws_config_onto_str(char *dst, size_t dst_len, const _z_str_intmap_t *s); char *_z_ws_config_to_str(const _z_str_intmap_t *s); -int8_t _z_ws_config_from_str(_z_str_intmap_t *strint, const char *s); -int8_t _z_ws_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); +z_result_t _z_ws_config_from_str(_z_str_intmap_t *strint, const char *s); +z_result_t _z_ws_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); #endif #endif /* ZENOH_PICO_LINK_CONFIG_WS_H */ diff --git a/include/zenoh-pico/link/endpoint.h b/include/zenoh-pico/link/endpoint.h index 689046b6b..4868f4d44 100644 --- a/include/zenoh-pico/link/endpoint.h +++ b/include/zenoh-pico/link/endpoint.h @@ -50,7 +50,7 @@ bool _z_locator_eq(const _z_locator_t *left, const _z_locator_t *right); void _z_locator_init(_z_locator_t *locator); _z_string_t _z_locator_to_string(const _z_locator_t *loc); -int8_t _z_locator_from_string(_z_locator_t *lc, _z_string_t *s); +z_result_t _z_locator_from_string(_z_locator_t *lc, _z_string_t *s); size_t _z_locator_size(_z_locator_t *lc); void _z_locator_clear(_z_locator_t *lc); @@ -68,7 +68,7 @@ typedef struct { } _z_endpoint_t; _z_string_t _z_endpoint_to_string(const _z_endpoint_t *e); -int8_t _z_endpoint_from_string(_z_endpoint_t *ep, _z_string_t *s); +z_result_t _z_endpoint_from_string(_z_endpoint_t *ep, _z_string_t *s); void _z_endpoint_clear(_z_endpoint_t *ep); void _z_endpoint_free(_z_endpoint_t **ep); diff --git a/include/zenoh-pico/link/link.h b/include/zenoh-pico/link/link.h index e4c83d78a..6356af3cf 100644 --- a/include/zenoh-pico/link/link.h +++ b/include/zenoh-pico/link/link.h @@ -89,8 +89,8 @@ typedef struct _z_link_capabilities_t { struct _z_link_t; // Forward declaration to be used in _z_f_link_* -typedef int8_t (*_z_f_link_open)(struct _z_link_t *self); -typedef int8_t (*_z_f_link_listen)(struct _z_link_t *self); +typedef z_result_t (*_z_f_link_open)(struct _z_link_t *self); +typedef z_result_t (*_z_f_link_listen)(struct _z_link_t *self); typedef void (*_z_f_link_close)(struct _z_link_t *self); typedef size_t (*_z_f_link_write)(const struct _z_link_t *self, const uint8_t *ptr, size_t len); typedef size_t (*_z_f_link_write_all)(const struct _z_link_t *self, const uint8_t *ptr, size_t len); @@ -137,10 +137,10 @@ typedef struct _z_link_t { void _z_link_clear(_z_link_t *zl); void _z_link_free(_z_link_t **zl); -int8_t _z_open_link(_z_link_t *zl, _z_string_t *locator); -int8_t _z_listen_link(_z_link_t *zl, _z_string_t *locator); +z_result_t _z_open_link(_z_link_t *zl, _z_string_t *locator); +z_result_t _z_listen_link(_z_link_t *zl, _z_string_t *locator); -int8_t _z_link_send_wbuf(const _z_link_t *zl, const _z_wbuf_t *wbf); +z_result_t _z_link_send_wbuf(const _z_link_t *zl, const _z_wbuf_t *wbf); size_t _z_link_recv_zbuf(const _z_link_t *zl, _z_zbuf_t *zbf, _z_slice_t *addr); size_t _z_link_recv_exact_zbuf(const _z_link_t *zl, _z_zbuf_t *zbf, size_t len, _z_slice_t *addr); diff --git a/include/zenoh-pico/link/manager.h b/include/zenoh-pico/link/manager.h index f494784e4..e0aba1f93 100644 --- a/include/zenoh-pico/link/manager.h +++ b/include/zenoh-pico/link/manager.h @@ -20,28 +20,28 @@ #include "zenoh-pico/link/link.h" #if Z_FEATURE_LINK_TCP == 1 -int8_t _z_endpoint_tcp_valid(_z_endpoint_t *ep); -int8_t _z_new_link_tcp(_z_link_t *zl, _z_endpoint_t *ep); +z_result_t _z_endpoint_tcp_valid(_z_endpoint_t *ep); +z_result_t _z_new_link_tcp(_z_link_t *zl, _z_endpoint_t *ep); #endif #if Z_FEATURE_LINK_UDP_UNICAST == 1 -int8_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *ep); -int8_t _z_new_link_udp_unicast(_z_link_t *zl, _z_endpoint_t ep); +z_result_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *ep); +z_result_t _z_new_link_udp_unicast(_z_link_t *zl, _z_endpoint_t ep); #endif #if Z_FEATURE_LINK_UDP_MULTICAST == 1 -int8_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *ep); -int8_t _z_new_link_udp_multicast(_z_link_t *zl, _z_endpoint_t ep); +z_result_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *ep); +z_result_t _z_new_link_udp_multicast(_z_link_t *zl, _z_endpoint_t ep); #endif #if Z_FEATURE_LINK_BLUETOOTH == 1 -int8_t _z_endpoint_bt_valid(_z_endpoint_t *ep); -int8_t _z_new_link_bt(_z_link_t *zl, _z_endpoint_t ep); +z_result_t _z_endpoint_bt_valid(_z_endpoint_t *ep); +z_result_t _z_new_link_bt(_z_link_t *zl, _z_endpoint_t ep); #endif #if Z_FEATURE_LINK_SERIAL == 1 -int8_t _z_endpoint_serial_valid(_z_endpoint_t *ep); -int8_t _z_new_link_serial(_z_link_t *zl, _z_endpoint_t ep); +z_result_t _z_endpoint_serial_valid(_z_endpoint_t *ep); +z_result_t _z_new_link_serial(_z_link_t *zl, _z_endpoint_t ep); #endif #if Z_FEATURE_LINK_WS == 1 -int8_t _z_endpoint_ws_valid(_z_endpoint_t *ep); -int8_t _z_new_link_ws(_z_link_t *zl, _z_endpoint_t *ep); +z_result_t _z_endpoint_ws_valid(_z_endpoint_t *ep); +z_result_t _z_new_link_ws(_z_link_t *zl, _z_endpoint_t *ep); #endif #endif /* ZENOH_PICO_LINK_MANAGER_H */ diff --git a/include/zenoh-pico/net/config.h b/include/zenoh-pico/net/config.h index 24418c730..fabc7415f 100644 --- a/include/zenoh-pico/net/config.h +++ b/include/zenoh-pico/net/config.h @@ -35,7 +35,7 @@ _z_config_t _z_config_empty(void); * Returns: * `0`` in case of success, or a ``negative value`` otherwise. */ -int8_t _z_config_default(_z_config_t *config); +z_result_t _z_config_default(_z_config_t *config); /** * Create a default set of properties for client mode zenoh-net session configuration. @@ -48,6 +48,6 @@ int8_t _z_config_default(_z_config_t *config); * Returns: * `0`` in case of success, or a ``negative value`` otherwise. */ -int8_t _z_config_client(_z_config_t *config, const char *locator); +z_result_t _z_config_client(_z_config_t *config, const char *locator); #endif /* ZENOH_PICO_CONFIG_NETAPI_H */ diff --git a/include/zenoh-pico/net/encoding.h b/include/zenoh-pico/net/encoding.h index 7e92c5699..88ac5f0d1 100644 --- a/include/zenoh-pico/net/encoding.h +++ b/include/zenoh-pico/net/encoding.h @@ -27,12 +27,12 @@ typedef struct _z_encoding_t { uint16_t id; } _z_encoding_t; -int8_t _z_encoding_make(_z_encoding_t *encoding, uint16_t id, const char *schema, size_t len); +z_result_t _z_encoding_make(_z_encoding_t *encoding, uint16_t id, const char *schema, size_t len); _z_encoding_t _z_encoding_wrap(uint16_t id, const char *schema); _z_encoding_t _z_encoding_null(void); void _z_encoding_clear(_z_encoding_t *encoding); bool _z_encoding_check(const _z_encoding_t *encoding); -int8_t _z_encoding_copy(_z_encoding_t *dst, const _z_encoding_t *src); +z_result_t _z_encoding_copy(_z_encoding_t *dst, const _z_encoding_t *src); void _z_encoding_move(_z_encoding_t *dst, _z_encoding_t *src); _z_encoding_t _z_encoding_steal(_z_encoding_t *val); diff --git a/include/zenoh-pico/net/filtering.h b/include/zenoh-pico/net/filtering.h index 9327a0c34..4af9e74bc 100644 --- a/include/zenoh-pico/net/filtering.h +++ b/include/zenoh-pico/net/filtering.h @@ -41,8 +41,8 @@ typedef struct _z_write_filter_t { typedef struct _z_publisher_t _z_publisher_t; -int8_t _z_write_filter_create(_z_publisher_t *pub); -int8_t _z_write_filter_destroy(const _z_publisher_t *pub); +z_result_t _z_write_filter_create(_z_publisher_t *pub); +z_result_t _z_write_filter_destroy(const _z_publisher_t *pub); bool _z_write_filter_active(const _z_publisher_t *pub); #endif /* ZENOH_PICO_FILTERING_NETAPI_H */ diff --git a/include/zenoh-pico/net/primitives.h b/include/zenoh-pico/net/primitives.h index 682e0e720..ba30b5830 100644 --- a/include/zenoh-pico/net/primitives.h +++ b/include/zenoh-pico/net/primitives.h @@ -70,7 +70,7 @@ uint16_t _z_declare_resource(_z_session_t *zn, _z_keyexpr_t keyexpr); * Returns: * 0 if success, or a negative value identifying the error. */ -int8_t _z_undeclare_resource(_z_session_t *zn, uint16_t rid); +z_result_t _z_undeclare_resource(_z_session_t *zn, uint16_t rid); #if Z_FEATURE_PUBLICATION == 1 /** @@ -102,7 +102,7 @@ _z_publisher_t _z_declare_publisher(const _z_session_rc_t *zn, _z_keyexpr_t keye * Returns: * 0 if success, or a negative value identifying the error. */ -int8_t _z_undeclare_publisher(_z_publisher_t *pub); +z_result_t _z_undeclare_publisher(_z_publisher_t *pub); /** * Write data corresponding to a given resource key, allowing the definition of @@ -124,10 +124,10 @@ int8_t _z_undeclare_publisher(_z_publisher_t *pub); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, _z_bytes_t payload, const _z_encoding_t *encoding, - const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, z_priority_t priority, - bool is_express, const _z_timestamp_t *timestamp, const _z_bytes_t attachment, - z_reliability_t reliability); +z_result_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, _z_bytes_t payload, const _z_encoding_t *encoding, + const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, z_priority_t priority, + bool is_express, const _z_timestamp_t *timestamp, const _z_bytes_t attachment, + z_reliability_t reliability); #endif #if Z_FEATURE_SUBSCRIPTION == 1 @@ -156,7 +156,7 @@ _z_subscriber_t _z_declare_subscriber(const _z_session_rc_t *zn, _z_keyexpr_t ke * Returns: * 0 if success, or a negative value identifying the error. */ -int8_t _z_undeclare_subscriber(_z_subscriber_t *sub); +z_result_t _z_undeclare_subscriber(_z_subscriber_t *sub); #endif #if Z_FEATURE_QUERYABLE == 1 @@ -186,7 +186,7 @@ _z_queryable_t _z_declare_queryable(const _z_session_rc_t *zn, _z_keyexpr_t keye * Returns: * 0 if success, or a negative value identifying the error. */ -int8_t _z_undeclare_queryable(_z_queryable_t *qle); +z_result_t _z_undeclare_queryable(_z_queryable_t *qle); /** * Send a reply to a query. @@ -203,10 +203,10 @@ int8_t _z_undeclare_queryable(_z_queryable_t *qle); * kind: The type of operation. * attachment: An optional attachment to the reply. */ -int8_t _z_send_reply(const _z_query_t *query, const _z_session_rc_t *zsrc, const _z_keyexpr_t keyexpr, - const _z_value_t payload, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, - z_priority_t priority, bool is_express, const _z_timestamp_t *timestamp, - const _z_bytes_t attachment); +z_result_t _z_send_reply(const _z_query_t *query, const _z_session_rc_t *zsrc, const _z_keyexpr_t keyexpr, + const _z_value_t payload, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, + z_priority_t priority, bool is_express, const _z_timestamp_t *timestamp, + const _z_bytes_t attachment); /** * Send a reply error to a query. * @@ -220,7 +220,7 @@ int8_t _z_send_reply(const _z_query_t *query, const _z_session_rc_t *zsrc, const * key: The resource key of this reply. The caller keeps the ownership. * payload: The value of this reply, the caller keeps ownership. */ -int8_t _z_send_reply_err(const _z_query_t *query, const _z_session_rc_t *zsrc, const _z_value_t payload); +z_result_t _z_send_reply_err(const _z_query_t *query, const _z_session_rc_t *zsrc, const _z_value_t payload); #endif #if Z_FEATURE_QUERY == 1 @@ -244,16 +244,16 @@ int8_t _z_send_reply_err(const _z_query_t *query, const _z_session_rc_t *zsrc, c * priority: The priority of the query. * */ -int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target, - const z_consolidation_mode_t consolidation, const _z_value_t value, _z_reply_handler_t callback, - _z_drop_handler_t dropper, void *arg, uint64_t timeout_ms, const _z_bytes_t attachment, - z_congestion_control_t cong_ctrl, z_priority_t priority, bool is_express); +z_result_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target, + const z_consolidation_mode_t consolidation, const _z_value_t value, _z_reply_handler_t callback, + _z_drop_handler_t dropper, void *arg, uint64_t timeout_ms, const _z_bytes_t attachment, + z_congestion_control_t cong_ctrl, z_priority_t priority, bool is_express); #endif #if Z_FEATURE_INTEREST == 1 uint32_t _z_add_interest(_z_session_t *zn, _z_keyexpr_t keyexpr, _z_interest_handler_t callback, uint8_t flags, void *arg); -int8_t _z_remove_interest(_z_session_t *zn, uint32_t interest_id); +z_result_t _z_remove_interest(_z_session_t *zn, uint32_t interest_id); #endif #endif /* INCLUDE_ZENOH_PICO_NET_PRIMITIVES_H */ diff --git a/include/zenoh-pico/net/query.h b/include/zenoh-pico/net/query.h index 12c70d6b2..5e57c1eee 100644 --- a/include/zenoh-pico/net/query.h +++ b/include/zenoh-pico/net/query.h @@ -36,7 +36,7 @@ typedef struct _z_query_t { _z_query_t _z_query_null(void); void _z_query_clear(_z_query_t *q); -int8_t _z_query_copy(_z_query_t *dst, const _z_query_t *src); +z_result_t _z_query_copy(_z_query_t *dst, const _z_query_t *src); void _z_query_free(_z_query_t **query); _Z_REFCOUNT_DEFINE(_z_query, _z_query) diff --git a/include/zenoh-pico/net/reply.h b/include/zenoh-pico/net/reply.h index b3f78b6a2..14ef1b232 100644 --- a/include/zenoh-pico/net/reply.h +++ b/include/zenoh-pico/net/reply.h @@ -58,7 +58,7 @@ typedef struct _z_reply_data_t { } _z_reply_data_t; void _z_reply_data_clear(_z_reply_data_t *rd); -int8_t _z_reply_data_copy(_z_reply_data_t *dst, const _z_reply_data_t *src); +z_result_t _z_reply_data_copy(_z_reply_data_t *dst, const _z_reply_data_t *src); _Z_ELEM_DEFINE(_z_reply_data, _z_reply_data_t, _z_noop_size, _z_reply_data_clear, _z_noop_copy) _Z_LIST_DEFINE(_z_reply_data, _z_reply_data_t) @@ -81,7 +81,7 @@ _z_reply_t _z_reply_move(_z_reply_t *src_reply); _z_reply_t _z_reply_null(void); void _z_reply_clear(_z_reply_t *src); void _z_reply_free(_z_reply_t **hello); -int8_t _z_reply_copy(_z_reply_t *dst, const _z_reply_t *src); +z_result_t _z_reply_copy(_z_reply_t *dst, const _z_reply_t *src); _z_reply_t _z_reply_create(_z_keyexpr_t keyexpr, _z_id_t id, const _z_bytes_t payload, const _z_timestamp_t *timestamp, _z_encoding_t *encoding, z_sample_kind_t kind, const _z_bytes_t attachment); _z_reply_t _z_reply_err_create(const _z_bytes_t payload, _z_encoding_t *encoding); diff --git a/include/zenoh-pico/net/sample.h b/include/zenoh-pico/net/sample.h index ee8720077..9fadfbc76 100644 --- a/include/zenoh-pico/net/sample.h +++ b/include/zenoh-pico/net/sample.h @@ -52,7 +52,7 @@ void _z_sample_move(_z_sample_t *dst, _z_sample_t *src); */ void _z_sample_free(_z_sample_t **sample); -int8_t _z_sample_copy(_z_sample_t *dst, const _z_sample_t *src); +z_result_t _z_sample_copy(_z_sample_t *dst, const _z_sample_t *src); _z_sample_t _z_sample_duplicate(const _z_sample_t *src); _z_sample_t _z_sample_create(_z_keyexpr_t *key, const _z_bytes_t payload, const _z_timestamp_t *timestamp, diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index 541e762e5..ba6f849fa 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -84,7 +84,7 @@ _Z_REFCOUNT_DEFINE(_z_session, _z_session) * ``0`` in case of success, or a ``negative value`` in case of failure. * */ -int8_t _z_open(_z_session_rc_t *zn, _z_config_t *config); +z_result_t _z_open(_z_session_rc_t *zn, _z_config_t *config); /** * Close a zenoh-net session. @@ -115,7 +115,7 @@ _z_config_t *_z_info(const _z_session_t *session); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _zp_read(_z_session_t *z); +z_result_t _zp_read(_z_session_t *z); /** * Send a KeepAlive message. @@ -125,7 +125,7 @@ int8_t _zp_read(_z_session_t *z); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _zp_send_keep_alive(_z_session_t *z); +z_result_t _zp_send_keep_alive(_z_session_t *z); /** * Send a Join message. @@ -135,7 +135,7 @@ int8_t _zp_send_keep_alive(_z_session_t *z); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _zp_send_join(_z_session_t *z); +z_result_t _zp_send_join(_z_session_t *z); #if Z_FEATURE_MULTI_THREAD == 1 /** @@ -148,7 +148,7 @@ int8_t _zp_send_join(_z_session_t *z); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _zp_start_read_task(_z_session_t *z, z_task_attr_t *attr); +z_result_t _zp_start_read_task(_z_session_t *z, z_task_attr_t *attr); /** * Stop the read task. This may result in stopping a thread or a process depending @@ -159,7 +159,7 @@ int8_t _zp_start_read_task(_z_session_t *z, z_task_attr_t *attr); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _zp_stop_read_task(_z_session_t *z); +z_result_t _zp_stop_read_task(_z_session_t *z); /** * Start a separate task to handle the session lease. This task will send ``KeepAlive`` @@ -175,7 +175,7 @@ int8_t _zp_stop_read_task(_z_session_t *z); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _zp_start_lease_task(_z_session_t *z, z_task_attr_t *attr); +z_result_t _zp_start_lease_task(_z_session_t *z, z_task_attr_t *attr); /** * Stop the lease task. This may result in stopping a thread or a process depending @@ -186,7 +186,7 @@ int8_t _zp_start_lease_task(_z_session_t *z, z_task_attr_t *attr); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _zp_stop_lease_task(_z_session_t *z); +z_result_t _zp_stop_lease_task(_z_session_t *z); #endif // Z_FEATURE_MULTI_THREAD == 1 #endif /* INCLUDE_ZENOH_PICO_NET_SESSION_H */ diff --git a/include/zenoh-pico/protocol/codec/core.h b/include/zenoh-pico/protocol/codec/core.h index 29afa1005..c86d1b18c 100644 --- a/include/zenoh-pico/protocol/codec/core.h +++ b/include/zenoh-pico/protocol/codec/core.h @@ -24,64 +24,64 @@ #include "zenoh-pico/utils/config.h" #include "zenoh-pico/utils/result.h" -typedef int8_t (*__z_single_byte_reader_t)(uint8_t *, void *context); +typedef z_result_t (*__z_single_byte_reader_t)(uint8_t *, void *context); /*------------------ Internal Zenoh-net Macros ------------------*/ -int8_t _z_consolidation_mode_encode(_z_wbuf_t *wbf, z_consolidation_mode_t en); -int8_t _z_consolidation_mode_decode(z_consolidation_mode_t *en, _z_zbuf_t *zbf); -int8_t _z_query_target_encode(_z_wbuf_t *wbf, z_query_target_t en); -int8_t _z_query_target_decode(z_query_target_t *en, _z_zbuf_t *zbf); -int8_t _z_whatami_encode(_z_wbuf_t *wbf, z_whatami_t en); -int8_t _z_whatami_decode(z_whatami_t *en, _z_zbuf_t *zbf); +z_result_t _z_consolidation_mode_encode(_z_wbuf_t *wbf, z_consolidation_mode_t en); +z_result_t _z_consolidation_mode_decode(z_consolidation_mode_t *en, _z_zbuf_t *zbf); +z_result_t _z_query_target_encode(_z_wbuf_t *wbf, z_query_target_t en); +z_result_t _z_query_target_decode(z_query_target_t *en, _z_zbuf_t *zbf); +z_result_t _z_whatami_encode(_z_wbuf_t *wbf, z_whatami_t en); +z_result_t _z_whatami_decode(z_whatami_t *en, _z_zbuf_t *zbf); uint8_t _z_whatami_to_uint8(z_whatami_t whatami); z_whatami_t _z_whatami_from_uint8(uint8_t b); -int8_t _z_uint8_encode(_z_wbuf_t *buf, uint8_t v); -int8_t _z_uint8_decode(uint8_t *u8, _z_zbuf_t *buf); +z_result_t _z_uint8_encode(_z_wbuf_t *buf, uint8_t v); +z_result_t _z_uint8_decode(uint8_t *u8, _z_zbuf_t *buf); -int8_t _z_uint16_encode(_z_wbuf_t *buf, uint16_t v); -int8_t _z_uint16_decode(uint16_t *u16, _z_zbuf_t *buf); +z_result_t _z_uint16_encode(_z_wbuf_t *buf, uint16_t v); +z_result_t _z_uint16_decode(uint16_t *u16, _z_zbuf_t *buf); uint8_t _z_zint_len(uint64_t v); uint8_t _z_zint64_encode_buf(uint8_t *buf, uint64_t v); static inline uint8_t _z_zsize_encode_buf(uint8_t *buf, _z_zint_t v) { return _z_zint64_encode_buf(buf, (uint64_t)v); } -int8_t _z_zsize_encode(_z_wbuf_t *buf, _z_zint_t v); -int8_t _z_zint64_encode(_z_wbuf_t *buf, uint64_t v); -int8_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *buf); -int8_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *buf); -int8_t _z_zint64_decode(uint64_t *zint, _z_zbuf_t *buf); -int8_t _z_zint64_decode_with_reader(uint64_t *zint, __z_single_byte_reader_t reader, void *context); -int8_t _z_zsize_decode_with_reader(_z_zint_t *zint, __z_single_byte_reader_t reader, void *context); -int8_t _z_zsize_decode(_z_zint_t *zint, _z_zbuf_t *buf); - -int8_t _z_slice_val_encode(_z_wbuf_t *buf, const _z_slice_t *bs); -int8_t _z_slice_val_decode(_z_slice_t *bs, _z_zbuf_t *buf); -int8_t _z_slice_val_decode_na(_z_slice_t *bs, _z_zbuf_t *zbf); - -int8_t _z_slice_encode(_z_wbuf_t *buf, const _z_slice_t *bs); -int8_t _z_slice_decode(_z_slice_t *bs, _z_zbuf_t *buf); -int8_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *zbf); -int8_t _z_bytes_encode(_z_wbuf_t *wbf, const _z_bytes_t *bs); -int8_t _z_zbuf_read_exact(_z_zbuf_t *zbf, uint8_t *dest, size_t length); - -int8_t _z_str_encode(_z_wbuf_t *buf, const char *s); -int8_t _z_str_decode(char **str, _z_zbuf_t *buf); -int8_t _z_string_encode(_z_wbuf_t *wbf, const _z_string_t *s); -int8_t _z_string_decode(_z_string_t *str, _z_zbuf_t *zbf); +z_result_t _z_zsize_encode(_z_wbuf_t *buf, _z_zint_t v); +z_result_t _z_zint64_encode(_z_wbuf_t *buf, uint64_t v); +z_result_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *buf); +z_result_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *buf); +z_result_t _z_zint64_decode(uint64_t *zint, _z_zbuf_t *buf); +z_result_t _z_zint64_decode_with_reader(uint64_t *zint, __z_single_byte_reader_t reader, void *context); +z_result_t _z_zsize_decode_with_reader(_z_zint_t *zint, __z_single_byte_reader_t reader, void *context); +z_result_t _z_zsize_decode(_z_zint_t *zint, _z_zbuf_t *buf); + +z_result_t _z_slice_val_encode(_z_wbuf_t *buf, const _z_slice_t *bs); +z_result_t _z_slice_val_decode(_z_slice_t *bs, _z_zbuf_t *buf); +z_result_t _z_slice_val_decode_na(_z_slice_t *bs, _z_zbuf_t *zbf); + +z_result_t _z_slice_encode(_z_wbuf_t *buf, const _z_slice_t *bs); +z_result_t _z_slice_decode(_z_slice_t *bs, _z_zbuf_t *buf); +z_result_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *zbf); +z_result_t _z_bytes_encode(_z_wbuf_t *wbf, const _z_bytes_t *bs); +z_result_t _z_zbuf_read_exact(_z_zbuf_t *zbf, uint8_t *dest, size_t length); + +z_result_t _z_str_encode(_z_wbuf_t *buf, const char *s); +z_result_t _z_str_decode(char **str, _z_zbuf_t *buf); +z_result_t _z_string_encode(_z_wbuf_t *wbf, const _z_string_t *s); +z_result_t _z_string_decode(_z_string_t *str, _z_zbuf_t *zbf); size_t _z_encoding_len(const _z_encoding_t *en); -int8_t _z_encoding_encode(_z_wbuf_t *wbf, const _z_encoding_t *en); -int8_t _z_encoding_decode(_z_encoding_t *en, _z_zbuf_t *zbf); +z_result_t _z_encoding_encode(_z_wbuf_t *wbf, const _z_encoding_t *en); +z_result_t _z_encoding_decode(_z_encoding_t *en, _z_zbuf_t *zbf); -int8_t _z_value_encode(_z_wbuf_t *wbf, const _z_value_t *en); -int8_t _z_value_decode(_z_value_t *en, _z_zbuf_t *zbf); +z_result_t _z_value_encode(_z_wbuf_t *wbf, const _z_value_t *en); +z_result_t _z_value_decode(_z_value_t *en, _z_zbuf_t *zbf); -int8_t _z_keyexpr_encode(_z_wbuf_t *buf, bool has_suffix, const _z_keyexpr_t *ke); -int8_t _z_keyexpr_decode(_z_keyexpr_t *ke, _z_zbuf_t *buf, bool has_suffix); +z_result_t _z_keyexpr_encode(_z_wbuf_t *buf, bool has_suffix, const _z_keyexpr_t *ke); +z_result_t _z_keyexpr_decode(_z_keyexpr_t *ke, _z_zbuf_t *buf, bool has_suffix); -int8_t _z_timestamp_encode(_z_wbuf_t *buf, const _z_timestamp_t *ts); -int8_t _z_timestamp_encode_ext(_z_wbuf_t *buf, const _z_timestamp_t *ts); -int8_t _z_timestamp_decode(_z_timestamp_t *ts, _z_zbuf_t *buf); +z_result_t _z_timestamp_encode(_z_wbuf_t *buf, const _z_timestamp_t *ts); +z_result_t _z_timestamp_encode_ext(_z_wbuf_t *buf, const _z_timestamp_t *ts); +z_result_t _z_timestamp_decode(_z_timestamp_t *ts, _z_zbuf_t *buf); #endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_CORE_H */ diff --git a/include/zenoh-pico/protocol/codec/declarations.h b/include/zenoh-pico/protocol/codec/declarations.h index d41f875b7..86efb1a64 100644 --- a/include/zenoh-pico/protocol/codec/declarations.h +++ b/include/zenoh-pico/protocol/codec/declarations.h @@ -30,24 +30,24 @@ #define _Z_UNDECL_TOKEN_MID 7 #define _Z_DECL_FINAL_MID 0x1a -int8_t _z_decl_kexpr_encode(_z_wbuf_t *wbf, const _z_decl_kexpr_t *decl); -int8_t _z_decl_kexpr_decode(_z_decl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_undecl_kexpr_encode(_z_wbuf_t *wbf, const _z_undecl_kexpr_t *decl); -int8_t _z_undecl_kexpr_decode(_z_undecl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_decl_subscriber_encode(_z_wbuf_t *wbf, const _z_decl_subscriber_t *decl); -int8_t _z_decl_subscriber_decode(_z_decl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_undecl_subscriber_encode(_z_wbuf_t *wbf, const _z_undecl_subscriber_t *decl); -int8_t _z_undecl_subscriber_decode(_z_undecl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_decl_queryable_encode(_z_wbuf_t *wbf, const _z_decl_queryable_t *decl); -int8_t _z_decl_queryable_decode(_z_decl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_undecl_queryable_encode(_z_wbuf_t *wbf, const _z_undecl_queryable_t *decl); -int8_t _z_undecl_queryable_decode(_z_undecl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_decl_token_encode(_z_wbuf_t *wbf, const _z_decl_token_t *decl); -int8_t _z_decl_token_decode(_z_decl_token_t *decl, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_undecl_token_encode(_z_wbuf_t *wbf, const _z_undecl_token_t *decl); -int8_t _z_undecl_token_decode(_z_undecl_token_t *decl, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_decl_kexpr_encode(_z_wbuf_t *wbf, const _z_decl_kexpr_t *decl); +z_result_t _z_decl_kexpr_decode(_z_decl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_undecl_kexpr_encode(_z_wbuf_t *wbf, const _z_undecl_kexpr_t *decl); +z_result_t _z_undecl_kexpr_decode(_z_undecl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_decl_subscriber_encode(_z_wbuf_t *wbf, const _z_decl_subscriber_t *decl); +z_result_t _z_decl_subscriber_decode(_z_decl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_undecl_subscriber_encode(_z_wbuf_t *wbf, const _z_undecl_subscriber_t *decl); +z_result_t _z_undecl_subscriber_decode(_z_undecl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_decl_queryable_encode(_z_wbuf_t *wbf, const _z_decl_queryable_t *decl); +z_result_t _z_decl_queryable_decode(_z_decl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_undecl_queryable_encode(_z_wbuf_t *wbf, const _z_undecl_queryable_t *decl); +z_result_t _z_undecl_queryable_decode(_z_undecl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_decl_token_encode(_z_wbuf_t *wbf, const _z_decl_token_t *decl); +z_result_t _z_decl_token_decode(_z_decl_token_t *decl, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_undecl_token_encode(_z_wbuf_t *wbf, const _z_undecl_token_t *decl); +z_result_t _z_undecl_token_decode(_z_undecl_token_t *decl, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_declaration_encode(_z_wbuf_t *wbf, const _z_declaration_t *decl); -int8_t _z_declaration_decode(_z_declaration_t *decl, _z_zbuf_t *zbf); +z_result_t _z_declaration_encode(_z_wbuf_t *wbf, const _z_declaration_t *decl); +z_result_t _z_declaration_decode(_z_declaration_t *decl, _z_zbuf_t *zbf); #endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_DECLARATIONS_H */ diff --git a/include/zenoh-pico/protocol/codec/ext.h b/include/zenoh-pico/protocol/codec/ext.h index 544d79bdd..7efd7063e 100644 --- a/include/zenoh-pico/protocol/codec/ext.h +++ b/include/zenoh-pico/protocol/codec/ext.h @@ -22,11 +22,11 @@ #include "zenoh-pico/protocol/iobuf.h" /*------------------ Message Extension ------------------*/ -int8_t _z_msg_ext_encode(_z_wbuf_t *wbf, const _z_msg_ext_t *ext, bool has_next); -int8_t _z_msg_ext_decode(_z_msg_ext_t *ext, _z_zbuf_t *zbf, bool *has_next); -int8_t _z_msg_ext_decode_na(_z_msg_ext_t *ext, _z_zbuf_t *zbf, bool *has_next); -int8_t _z_msg_ext_vec_encode(_z_wbuf_t *wbf, const _z_msg_ext_vec_t *extensions); -int8_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf); +z_result_t _z_msg_ext_encode(_z_wbuf_t *wbf, const _z_msg_ext_t *ext, bool has_next); +z_result_t _z_msg_ext_decode(_z_msg_ext_t *ext, _z_zbuf_t *zbf, bool *has_next); +z_result_t _z_msg_ext_decode_na(_z_msg_ext_t *ext, _z_zbuf_t *zbf, bool *has_next); +z_result_t _z_msg_ext_vec_encode(_z_wbuf_t *wbf, const _z_msg_ext_vec_t *extensions); +z_result_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf); /** * Iterates through the extensions in `zbf`, assuming at least one is present at its beginning * (calling this function otherwise is UB). Short-circuits if `callback` returns a non-zero value. @@ -34,36 +34,36 @@ int8_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf); * `callback` will receive `context` as its second argument, and may "steal" its first argument by * copying its value and setting it to `_z_msg_ext_make_unit(0)`. */ -int8_t _z_msg_ext_decode_iter(_z_zbuf_t *zbf, int8_t (*callback)(_z_msg_ext_t *, void *), void *context); +z_result_t _z_msg_ext_decode_iter(_z_zbuf_t *zbf, z_result_t (*callback)(_z_msg_ext_t *, void *), void *context); /** * Iterates through the extensions in `zbf`, assuming at least one is present at its beginning. * Returns `_Z_ERR_MESSAGE_EXTENSION_MANDATORY_AND_UNKNOWN` if a mandatory extension is found, * `_Z_RES_OK` otherwise. */ -int8_t _z_msg_ext_skip_non_mandatories(_z_zbuf_t *zbf, uint8_t trace_id); +z_result_t _z_msg_ext_skip_non_mandatories(_z_zbuf_t *zbf, uint8_t trace_id); /** * Logs an error to debug the unknown extension, returning `_Z_ERR_MESSAGE_EXTENSION_MANDATORY_AND_UNKNOWN`. * * `trace_id` may be any arbitrary value, but is advised to be unique to its call-site, * to help debugging should it be necessary. */ -int8_t _z_msg_ext_unknown_error(_z_msg_ext_t *extension, uint8_t trace_id); +z_result_t _z_msg_ext_unknown_error(_z_msg_ext_t *extension, uint8_t trace_id); #endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_EXTCODEC_H */ // NOTE: the following headers are for unit testing only #ifdef ZENOH_PICO_TEST_H // ------------------ Message Fields ------------------ -int8_t _z_msg_ext_encode_unit(_z_wbuf_t *wbf, const _z_msg_ext_unit_t *pld); -int8_t _z_msg_ext_decode_unit(_z_msg_ext_unit_t *pld, _z_zbuf_t *zbf); -int8_t _z_msg_ext_decode_unit_na(_z_msg_ext_unit_t *pld, _z_zbuf_t *zbf); +z_result_t _z_msg_ext_encode_unit(_z_wbuf_t *wbf, const _z_msg_ext_unit_t *pld); +z_result_t _z_msg_ext_decode_unit(_z_msg_ext_unit_t *pld, _z_zbuf_t *zbf); +z_result_t _z_msg_ext_decode_unit_na(_z_msg_ext_unit_t *pld, _z_zbuf_t *zbf); -int8_t _z_msg_ext_encode_zint(_z_wbuf_t *wbf, const _z_msg_ext_zint_t *pld); -int8_t _z_msg_ext_decode_zint(_z_msg_ext_zint_t *pld, _z_zbuf_t *zbf); -int8_t _z_msg_ext_decode_zint_na(_z_msg_ext_zint_t *pld, _z_zbuf_t *zbf); +z_result_t _z_msg_ext_encode_zint(_z_wbuf_t *wbf, const _z_msg_ext_zint_t *pld); +z_result_t _z_msg_ext_decode_zint(_z_msg_ext_zint_t *pld, _z_zbuf_t *zbf); +z_result_t _z_msg_ext_decode_zint_na(_z_msg_ext_zint_t *pld, _z_zbuf_t *zbf); -int8_t _z_msg_ext_encode_zbuf(_z_wbuf_t *wbf, const _z_msg_ext_zbuf_t *pld); -int8_t _z_msg_ext_decode_zbuf(_z_msg_ext_zbuf_t *pld, _z_zbuf_t *zbf); -int8_t _z_msg_ext_decode_zbuf_na(_z_msg_ext_zbuf_t *pld, _z_zbuf_t *zbf); +z_result_t _z_msg_ext_encode_zbuf(_z_wbuf_t *wbf, const _z_msg_ext_zbuf_t *pld); +z_result_t _z_msg_ext_decode_zbuf(_z_msg_ext_zbuf_t *pld, _z_zbuf_t *zbf); +z_result_t _z_msg_ext_decode_zbuf_na(_z_msg_ext_zbuf_t *pld, _z_zbuf_t *zbf); #endif /* ZENOH_PICO_TEST_H */ diff --git a/include/zenoh-pico/protocol/codec/interest.h b/include/zenoh-pico/protocol/codec/interest.h index f86d08987..4e8aa4921 100644 --- a/include/zenoh-pico/protocol/codec/interest.h +++ b/include/zenoh-pico/protocol/codec/interest.h @@ -18,7 +18,7 @@ #include "zenoh-pico/protocol/definitions/interest.h" #include "zenoh-pico/protocol/iobuf.h" -int8_t _z_interest_encode(_z_wbuf_t *wbf, const _z_interest_t *interest, bool is_final); -int8_t _z_interest_decode(_z_interest_t *decl, _z_zbuf_t *zbf, bool is_final, bool has_ext); +z_result_t _z_interest_encode(_z_wbuf_t *wbf, const _z_interest_t *interest, bool is_final); +z_result_t _z_interest_decode(_z_interest_t *decl, _z_zbuf_t *zbf, bool is_final, bool has_ext); #endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_DECLARATIONS_H */ diff --git a/include/zenoh-pico/protocol/codec/message.h b/include/zenoh-pico/protocol/codec/message.h index 1ad2de4ba..c9bd9c039 100644 --- a/include/zenoh-pico/protocol/codec/message.h +++ b/include/zenoh-pico/protocol/codec/message.h @@ -18,22 +18,22 @@ #include "zenoh-pico/protocol/definitions/network.h" #include "zenoh-pico/protocol/iobuf.h" -int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb); -int8_t _z_push_body_decode(_z_push_body_t *body, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb); +z_result_t _z_push_body_decode(_z_push_body_t *body, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_query_encode(_z_wbuf_t *wbf, const _z_msg_query_t *query); -int8_t _z_query_decode(_z_msg_query_t *query, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_query_encode(_z_wbuf_t *wbf, const _z_msg_query_t *query); +z_result_t _z_query_decode(_z_msg_query_t *query, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_reply_encode(_z_wbuf_t *wbf, const _z_msg_reply_t *reply); -int8_t _z_reply_decode(_z_msg_reply_t *reply, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_reply_encode(_z_wbuf_t *wbf, const _z_msg_reply_t *reply); +z_result_t _z_reply_decode(_z_msg_reply_t *reply, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_err_encode(_z_wbuf_t *wbf, const _z_msg_err_t *err); -int8_t _z_err_decode(_z_msg_err_t *err, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_err_encode(_z_wbuf_t *wbf, const _z_msg_err_t *err); +z_result_t _z_err_decode(_z_msg_err_t *err, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_put_encode(_z_wbuf_t *wbf, const _z_msg_put_t *put); -int8_t _z_put_decode(_z_msg_put_t *put, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_put_encode(_z_wbuf_t *wbf, const _z_msg_put_t *put); +z_result_t _z_put_decode(_z_msg_put_t *put, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_del_encode(_z_wbuf_t *wbf, const _z_msg_del_t *del); -int8_t _z_del_decode(_z_msg_del_t *del, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_del_encode(_z_wbuf_t *wbf, const _z_msg_del_t *del); +z_result_t _z_del_decode(_z_msg_del_t *del, _z_zbuf_t *zbf, uint8_t header); #endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_MESSAGE_H */ diff --git a/include/zenoh-pico/protocol/codec/network.h b/include/zenoh-pico/protocol/codec/network.h index 100bb2bd9..64a5229c8 100644 --- a/include/zenoh-pico/protocol/codec/network.h +++ b/include/zenoh-pico/protocol/codec/network.h @@ -19,20 +19,20 @@ #include "zenoh-pico/protocol/definitions/network.h" #include "zenoh-pico/protocol/iobuf.h" -int8_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg); -int8_t _z_push_decode(_z_n_msg_push_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg); -int8_t _z_request_decode(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg); -int8_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t *msg); -int8_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl); -int8_t _z_declare_decode(_z_n_msg_declare_t *decl, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_n_interest_encode(_z_wbuf_t *wbf, const _z_n_msg_interest_t *interest); -int8_t _z_n_interest_decode(_z_n_msg_interest_t *interest, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg); +z_result_t _z_push_decode(_z_n_msg_push_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg); +z_result_t _z_request_decode(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg); +z_result_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t *msg); +z_result_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl); +z_result_t _z_declare_decode(_z_n_msg_declare_t *decl, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_n_interest_encode(_z_wbuf_t *wbf, const _z_n_msg_interest_t *interest); +z_result_t _z_n_interest_decode(_z_n_msg_interest_t *interest, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_network_message_encode(_z_wbuf_t *wbf, const _z_network_message_t *msg); -int8_t _z_network_message_decode(_z_network_message_t *msg, _z_zbuf_t *zbf); +z_result_t _z_network_message_encode(_z_wbuf_t *wbf, const _z_network_message_t *msg); +z_result_t _z_network_message_decode(_z_network_message_t *msg, _z_zbuf_t *zbf); #endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_NETWORK_H */ diff --git a/include/zenoh-pico/protocol/codec/transport.h b/include/zenoh-pico/protocol/codec/transport.h index 0feaf1784..cd0e4a2c5 100644 --- a/include/zenoh-pico/protocol/codec/transport.h +++ b/include/zenoh-pico/protocol/codec/transport.h @@ -19,33 +19,33 @@ #include "zenoh-pico/protocol/iobuf.h" #define _ZENOH_PICO_FRAME_MESSAGES_VEC_SIZE 32 -int8_t _z_scouting_message_encode(_z_wbuf_t *buf, const _z_scouting_message_t *msg); -int8_t _z_scouting_message_decode(_z_scouting_message_t *msg, _z_zbuf_t *buf); +z_result_t _z_scouting_message_encode(_z_wbuf_t *buf, const _z_scouting_message_t *msg); +z_result_t _z_scouting_message_decode(_z_scouting_message_t *msg, _z_zbuf_t *buf); -int8_t _z_transport_message_encode(_z_wbuf_t *buf, const _z_transport_message_t *msg); -int8_t _z_transport_message_decode(_z_transport_message_t *msg, _z_zbuf_t *buf); +z_result_t _z_transport_message_encode(_z_wbuf_t *buf, const _z_transport_message_t *msg); +z_result_t _z_transport_message_decode(_z_transport_message_t *msg, _z_zbuf_t *buf); -int8_t _z_join_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_join_t *msg); -int8_t _z_join_decode(_z_t_msg_join_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_join_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_join_t *msg); +z_result_t _z_join_decode(_z_t_msg_join_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_init_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_init_t *msg); -int8_t _z_init_decode(_z_t_msg_init_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_init_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_init_t *msg); +z_result_t _z_init_decode(_z_t_msg_init_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_open_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_open_t *msg); -int8_t _z_open_decode(_z_t_msg_open_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_open_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_open_t *msg); +z_result_t _z_open_decode(_z_t_msg_open_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_close_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_close_t *msg); -int8_t _z_close_decode(_z_t_msg_close_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_close_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_close_t *msg); +z_result_t _z_close_decode(_z_t_msg_close_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_keep_alive_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_keep_alive_t *msg); -int8_t _z_keep_alive_decode(_z_t_msg_keep_alive_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_keep_alive_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_keep_alive_t *msg); +z_result_t _z_keep_alive_decode(_z_t_msg_keep_alive_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_t *msg); -int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_t *msg); +z_result_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fragment_t *msg); -int8_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t header); +z_result_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fragment_t *msg); +z_result_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t header); -int8_t _z_transport_message_encode(_z_wbuf_t *wbf, const _z_transport_message_t *msg); -int8_t _z_transport_message_decode(_z_transport_message_t *msg, _z_zbuf_t *zbf); +z_result_t _z_transport_message_encode(_z_wbuf_t *wbf, const _z_transport_message_t *msg); +z_result_t _z_transport_message_decode(_z_transport_message_t *msg, _z_zbuf_t *zbf); #endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_TRANSPORT_H */ diff --git a/include/zenoh-pico/protocol/core.h b/include/zenoh-pico/protocol/core.h index be010dd6b..7dcf49508 100644 --- a/include/zenoh-pico/protocol/core.h +++ b/include/zenoh-pico/protocol/core.h @@ -165,7 +165,7 @@ typedef struct { } _z_value_t; _z_value_t _z_value_null(void); _z_value_t _z_value_steal(_z_value_t *value); -int8_t _z_value_copy(_z_value_t *dst, const _z_value_t *src); +z_result_t _z_value_copy(_z_value_t *dst, const _z_value_t *src); void _z_value_move(_z_value_t *dst, _z_value_t *src); void _z_value_clear(_z_value_t *src); void _z_value_free(_z_value_t **hello); @@ -186,7 +186,7 @@ typedef struct { } _z_hello_t; void _z_hello_clear(_z_hello_t *src); void _z_hello_free(_z_hello_t **hello); -int8_t _z_hello_copy(_z_hello_t *dst, const _z_hello_t *src); +z_result_t _z_hello_copy(_z_hello_t *dst, const _z_hello_t *src); _z_hello_t _z_hello_null(void); bool _z_hello_check(const _z_hello_t *hello); diff --git a/include/zenoh-pico/protocol/iobuf.h b/include/zenoh-pico/protocol/iobuf.h index 7a60a5f4a..888b69d46 100644 --- a/include/zenoh-pico/protocol/iobuf.h +++ b/include/zenoh-pico/protocol/iobuf.h @@ -107,9 +107,9 @@ size_t _z_wbuf_capacity(const _z_wbuf_t *wbf); size_t _z_wbuf_len(const _z_wbuf_t *wbf); size_t _z_wbuf_space_left(const _z_wbuf_t *wbf); -int8_t _z_wbuf_write(_z_wbuf_t *wbf, uint8_t b); -int8_t _z_wbuf_write_bytes(_z_wbuf_t *wbf, const uint8_t *bs, size_t offset, size_t length); -int8_t _z_wbuf_wrap_bytes(_z_wbuf_t *wbf, const uint8_t *bs, size_t offset, size_t length); +z_result_t _z_wbuf_write(_z_wbuf_t *wbf, uint8_t b); +z_result_t _z_wbuf_write_bytes(_z_wbuf_t *wbf, const uint8_t *bs, size_t offset, size_t length); +z_result_t _z_wbuf_wrap_bytes(_z_wbuf_t *wbf, const uint8_t *bs, size_t offset, size_t length); void _z_wbuf_put(_z_wbuf_t *wbf, uint8_t b, size_t pos); size_t _z_wbuf_get_rpos(const _z_wbuf_t *wbf); @@ -122,7 +122,7 @@ _z_iosli_t *_z_wbuf_get_iosli(const _z_wbuf_t *wbf, size_t idx); size_t _z_wbuf_len_iosli(const _z_wbuf_t *wbf); _z_zbuf_t _z_wbuf_to_zbuf(const _z_wbuf_t *wbf); -int8_t _z_wbuf_siphon(_z_wbuf_t *dst, _z_wbuf_t *src, size_t length); +z_result_t _z_wbuf_siphon(_z_wbuf_t *dst, _z_wbuf_t *src, size_t length); void _z_wbuf_copy(_z_wbuf_t *dst, const _z_wbuf_t *src); void _z_wbuf_reset(_z_wbuf_t *wbf); diff --git a/include/zenoh-pico/protocol/keyexpr.h b/include/zenoh-pico/protocol/keyexpr.h index 047cd6d4c..f171ee32f 100644 --- a/include/zenoh-pico/protocol/keyexpr.h +++ b/include/zenoh-pico/protocol/keyexpr.h @@ -28,7 +28,7 @@ bool _z_keyexpr_suffix_equals(const _z_keyexpr_t *left, const _z_keyexpr_t *righ /*------------------ clone/Copy/Free helpers ------------------*/ _z_keyexpr_t _z_keyexpr_from_string(uint16_t rid, _z_string_t *str); _z_keyexpr_t _z_keyexpr_from_substr(uint16_t rid, const char *str, size_t len); -int8_t _z_keyexpr_copy(_z_keyexpr_t *dst, const _z_keyexpr_t *src); +z_result_t _z_keyexpr_copy(_z_keyexpr_t *dst, const _z_keyexpr_t *src); _z_keyexpr_t _z_keyexpr_duplicate(_z_keyexpr_t src); _z_keyexpr_t _z_keyexpr_alias(_z_keyexpr_t src); /// Returns either keyexpr defined by id + mapping with null suffix if try_declared is true and id is non-zero, diff --git a/include/zenoh-pico/session/interest.h b/include/zenoh-pico/session/interest.h index 7114fea1b..3e1f6d4da 100644 --- a/include/zenoh-pico/session/interest.h +++ b/include/zenoh-pico/session/interest.h @@ -26,10 +26,10 @@ void _z_unregister_interest(_z_session_t *zn, _z_session_interest_rc_t *intr); #endif // Z_FEATURE_INTEREST == 1 void _z_flush_interest(_z_session_t *zn); -int8_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *decl); -int8_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl); -int8_t _z_interest_process_declare_final(_z_session_t *zn, uint32_t id); -int8_t _z_interest_process_interest_final(_z_session_t *zn, uint32_t id); -int8_t _z_interest_process_interest(_z_session_t *zn, _z_keyexpr_t key, uint32_t id, uint8_t flags); +z_result_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *decl); +z_result_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl); +z_result_t _z_interest_process_declare_final(_z_session_t *zn, uint32_t id); +z_result_t _z_interest_process_interest_final(_z_session_t *zn, uint32_t id); +z_result_t _z_interest_process_interest(_z_session_t *zn, _z_keyexpr_t key, uint32_t id, uint8_t flags); #endif /* ZENOH_PICO_SESSION_INTEREST_H */ diff --git a/include/zenoh-pico/session/push.h b/include/zenoh-pico/session/push.h index 7c44f49fa..5c774b704 100644 --- a/include/zenoh-pico/session/push.h +++ b/include/zenoh-pico/session/push.h @@ -21,6 +21,6 @@ #ifndef ZENOH_PICO_SESSION_PUSH_H #define ZENOH_PICO_SESSION_PUSH_H -int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push, z_reliability_t reliability); +z_result_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push, z_reliability_t reliability); #endif /* ZENOH_PICO_SESSION_PUSH_H */ diff --git a/include/zenoh-pico/session/query.h b/include/zenoh-pico/session/query.h index acdc3a6b3..1bf03b74d 100644 --- a/include/zenoh-pico/session/query.h +++ b/include/zenoh-pico/session/query.h @@ -24,11 +24,11 @@ _z_zint_t _z_get_query_id(_z_session_t *zn); _z_pending_query_t *_z_get_pending_query_by_id(_z_session_t *zn, const _z_zint_t id); -int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pq); -int8_t _z_trigger_query_reply_partial(_z_session_t *zn, _z_zint_t reply_context, const _z_keyexpr_t keyexpr, - _z_msg_put_t *msg, z_sample_kind_t kind); -int8_t _z_trigger_query_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t *msg); -int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id); +z_result_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pq); +z_result_t _z_trigger_query_reply_partial(_z_session_t *zn, _z_zint_t reply_context, const _z_keyexpr_t keyexpr, + _z_msg_put_t *msg, z_sample_kind_t kind); +z_result_t _z_trigger_query_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t *msg); +z_result_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id); void _z_unregister_pending_query(_z_session_t *zn, _z_pending_query_t *pq); void _z_flush_pending_queries(_z_session_t *zn); #endif diff --git a/include/zenoh-pico/session/queryable.h b/include/zenoh-pico/session/queryable.h index 400af55f8..4498a5bed 100644 --- a/include/zenoh-pico/session/queryable.h +++ b/include/zenoh-pico/session/queryable.h @@ -28,8 +28,8 @@ _z_session_queryable_rc_t *_z_get_session_queryable_by_id(_z_session_t *zn, cons _z_session_queryable_rc_list_t *_z_get_session_queryable_by_key(_z_session_t *zn, const _z_keyexpr_t key); _z_session_queryable_rc_t *_z_register_session_queryable(_z_session_t *zn, _z_session_queryable_t *q); -int8_t _z_trigger_queryables(_z_session_rc_t *zn, _z_msg_query_t *query, const _z_keyexpr_t q_key, uint32_t qid, - const _z_bytes_t attachment); +z_result_t _z_trigger_queryables(_z_session_rc_t *zn, _z_msg_query_t *query, const _z_keyexpr_t q_key, uint32_t qid, + const _z_bytes_t attachment); void _z_unregister_session_queryable(_z_session_t *zn, _z_session_queryable_rc_t *q); void _z_flush_session_queryable(_z_session_t *zn); #endif diff --git a/include/zenoh-pico/session/reply.h b/include/zenoh-pico/session/reply.h index 719b2fee1..c10aa0b28 100644 --- a/include/zenoh-pico/session/reply.h +++ b/include/zenoh-pico/session/reply.h @@ -22,10 +22,10 @@ #ifndef ZENOH_PICO_SESSION_REPLY_H #define ZENOH_PICO_SESSION_REPLY_H -int8_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key, _z_msg_reply_t *reply); +z_result_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key, _z_msg_reply_t *reply); -int8_t _z_trigger_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t *error); +z_result_t _z_trigger_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t *error); -int8_t _z_trigger_reply_final(_z_session_t *zn, _z_n_msg_response_final_t *final); +z_result_t _z_trigger_reply_final(_z_session_t *zn, _z_n_msg_response_final_t *final); #endif /* ZENOH_PICO_SESSION_REPLY_H */ diff --git a/include/zenoh-pico/session/session.h b/include/zenoh-pico/session/session.h index 80e5609e8..2246c1b85 100644 --- a/include/zenoh-pico/session/session.h +++ b/include/zenoh-pico/session/session.h @@ -148,7 +148,7 @@ struct __z_hello_handler_wrapper_t; // Forward declaration to be used in _z_hel */ typedef void (*_z_hello_handler_t)(_z_hello_t *hello, struct __z_hello_handler_wrapper_t *arg); -int8_t _z_session_generate_zid(_z_id_t *bs, uint8_t size); +z_result_t _z_session_generate_zid(_z_id_t *bs, uint8_t size); typedef enum { _Z_INTEREST_MSG_TYPE_FINAL = 0, diff --git a/include/zenoh-pico/session/subscription.h b/include/zenoh-pico/session/subscription.h index 21897545e..dd48ecb83 100644 --- a/include/zenoh-pico/session/subscription.h +++ b/include/zenoh-pico/session/subscription.h @@ -28,9 +28,9 @@ _z_subscription_rc_t *_z_get_subscription_by_id(_z_session_t *zn, uint8_t is_loc _z_subscription_rc_list_t *_z_get_subscriptions_by_key(_z_session_t *zn, uint8_t is_local, const _z_keyexpr_t *keyexpr); _z_subscription_rc_t *_z_register_subscription(_z_session_t *zn, uint8_t is_local, _z_subscription_t *sub); -int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, const _z_bytes_t payload, - _z_encoding_t *encoding, const _z_zint_t kind, const _z_timestamp_t *timestamp, - const _z_n_qos_t qos, const _z_bytes_t attachment, z_reliability_t reliability); +z_result_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, const _z_bytes_t payload, + _z_encoding_t *encoding, const _z_zint_t kind, const _z_timestamp_t *timestamp, + const _z_n_qos_t qos, const _z_bytes_t attachment, z_reliability_t reliability); void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscription_rc_t *sub); void _z_flush_subscriptions(_z_session_t *zn); #endif diff --git a/include/zenoh-pico/session/utils.h b/include/zenoh-pico/session/utils.h index 7a7a9d504..75eaac2e8 100644 --- a/include/zenoh-pico/session/utils.h +++ b/include/zenoh-pico/session/utils.h @@ -26,13 +26,13 @@ _z_hello_list_t *_z_scout_inner(const z_what_t what, _z_id_t id, _z_string_t *locator, const uint32_t timeout, const bool exit_on_first); -int8_t _z_session_init(_z_session_rc_t *zsrc, _z_id_t *zid); +z_result_t _z_session_init(_z_session_rc_t *zsrc, _z_id_t *zid); void _z_session_clear(_z_session_t *zn); -int8_t _z_session_close(_z_session_t *zn, uint8_t reason); +z_result_t _z_session_close(_z_session_t *zn, uint8_t reason); -int8_t _z_handle_network_message(_z_session_rc_t *zsrc, _z_zenoh_message_t *z_msg, uint16_t local_peer_id); -int8_t _z_send_n_msg(_z_session_t *zn, _z_network_message_t *n_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl); +z_result_t _z_handle_network_message(_z_session_rc_t *zsrc, _z_zenoh_message_t *z_msg, uint16_t local_peer_id); +z_result_t _z_send_n_msg(_z_session_t *zn, _z_network_message_t *n_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl); void _zp_session_lock_mutex(_z_session_t *zn); void _zp_session_unlock_mutex(_z_session_t *zn); diff --git a/include/zenoh-pico/system/link/bt.h b/include/zenoh-pico/system/link/bt.h index b155e34b3..03ffda584 100644 --- a/include/zenoh-pico/system/link/bt.h +++ b/include/zenoh-pico/system/link/bt.h @@ -36,8 +36,8 @@ typedef struct { char *_gname; } _z_bt_socket_t; -int8_t _z_open_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout); -int8_t _z_listen_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout); +z_result_t _z_open_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout); +z_result_t _z_listen_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout); void _z_close_bt(_z_sys_net_socket_t *sock); size_t _z_read_exact_bt(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); size_t _z_read_bt(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); diff --git a/include/zenoh-pico/system/link/raweth.h b/include/zenoh-pico/system/link/raweth.h index 0bbdc5f0a..d48bf1fa4 100644 --- a/include/zenoh-pico/system/link/raweth.h +++ b/include/zenoh-pico/system/link/raweth.h @@ -82,11 +82,11 @@ typedef struct { bool _has_vlan; } _z_raweth_socket_t; -int8_t _z_open_raweth(_z_sys_net_socket_t *sock, const char *interface); +z_result_t _z_open_raweth(_z_sys_net_socket_t *sock, const char *interface); size_t _z_send_raweth(const _z_sys_net_socket_t *sock, const void *buff, size_t buff_len); size_t _z_receive_raweth(const _z_sys_net_socket_t *sock, void *buff, size_t buff_len, _z_slice_t *addr, const _zp_raweth_whitelist_array_t *whitelist); -int8_t _z_close_raweth(_z_sys_net_socket_t *sock); +z_result_t _z_close_raweth(_z_sys_net_socket_t *sock); uint16_t _z_raweth_ntohs(uint16_t val); uint16_t _z_raweth_htons(uint16_t val); diff --git a/include/zenoh-pico/system/link/serial.h b/include/zenoh-pico/system/link/serial.h index 954fd2911..21d832c65 100644 --- a/include/zenoh-pico/system/link/serial.h +++ b/include/zenoh-pico/system/link/serial.h @@ -32,10 +32,10 @@ typedef struct { _z_sys_net_socket_t _sock; } _z_serial_socket_t; -int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate); -int8_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate); -int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate); -int8_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate); +z_result_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate); +z_result_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate); +z_result_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate); +z_result_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate); void _z_close_serial(_z_sys_net_socket_t *sock); size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); diff --git a/include/zenoh-pico/system/link/tcp.h b/include/zenoh-pico/system/link/tcp.h index e90b688eb..22bdc3efc 100644 --- a/include/zenoh-pico/system/link/tcp.h +++ b/include/zenoh-pico/system/link/tcp.h @@ -27,11 +27,11 @@ typedef struct { _z_sys_net_endpoint_t _rep; } _z_tcp_socket_t; -int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port); +z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port); void _z_free_endpoint_tcp(_z_sys_net_endpoint_t *ep); -int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout); -int8_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep); +z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout); +z_result_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep); void _z_close_tcp(_z_sys_net_socket_t *sock); size_t _z_read_exact_tcp(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); size_t _z_read_tcp(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); diff --git a/include/zenoh-pico/system/link/udp.h b/include/zenoh-pico/system/link/udp.h index e9f17acb9..47899c04a 100644 --- a/include/zenoh-pico/system/link/udp.h +++ b/include/zenoh-pico/system/link/udp.h @@ -29,12 +29,12 @@ typedef struct { _z_sys_net_endpoint_t _lep; } _z_udp_socket_t; -int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port); +z_result_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port); void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep); // Unicast -int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout); -int8_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout); +z_result_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout); +z_result_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout); void _z_close_udp_unicast(_z_sys_net_socket_t *sock); size_t _z_read_exact_udp_unicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); size_t _z_read_udp_unicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); @@ -42,10 +42,10 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s const _z_sys_net_endpoint_t rep); // Multicast -int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, - uint32_t tout, const char *iface); -int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, - const char *iface, const char *join); +z_result_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, + uint32_t tout, const char *iface); +z_result_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, + const char *iface, const char *join); void _z_close_udp_multicast(_z_sys_net_socket_t *sockrecv, _z_sys_net_socket_t *socksend, const _z_sys_net_endpoint_t rep, const _z_sys_net_endpoint_t lep); size_t _z_read_exact_udp_multicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len, diff --git a/include/zenoh-pico/system/link/ws.h b/include/zenoh-pico/system/link/ws.h index 52edd2f11..aa57fcbf8 100644 --- a/include/zenoh-pico/system/link/ws.h +++ b/include/zenoh-pico/system/link/ws.h @@ -27,11 +27,11 @@ typedef struct { _z_sys_net_endpoint_t _rep; } _z_ws_socket_t; -int8_t _z_create_endpoint_ws(_z_sys_net_endpoint_t *ep, const char *s_addr, const char *s_port); +z_result_t _z_create_endpoint_ws(_z_sys_net_endpoint_t *ep, const char *s_addr, const char *s_port); void _z_free_endpoint_ws(_z_sys_net_endpoint_t *ep); -int8_t _z_open_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout); -int8_t _z_listen_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep); +z_result_t _z_open_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout); +z_result_t _z_listen_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep); void _z_close_ws(_z_sys_net_socket_t *sock); size_t _z_read_exact_ws(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); size_t _z_read_ws(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len); diff --git a/include/zenoh-pico/system/platform-common.h b/include/zenoh-pico/system/platform-common.h index de614c5da..5c9f0c00b 100644 --- a/include/zenoh-pico/system/platform-common.h +++ b/include/zenoh-pico/system/platform-common.h @@ -85,51 +85,51 @@ typedef void *z_task_attr_t; #endif /*------------------ Thread ------------------*/ -int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg); -int8_t _z_task_join(_z_task_t *task); -int8_t _z_task_cancel(_z_task_t *task); +z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg); +z_result_t _z_task_join(_z_task_t *task); +z_result_t _z_task_cancel(_z_task_t *task); void _z_task_free(_z_task_t **task); _Z_OWNED_TYPE_VALUE(_z_task_t, task) _Z_OWNED_FUNCTIONS_SYSTEM_DEF(task) -int8_t z_task_init(z_owned_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg); -int8_t z_task_join(z_owned_task_t *task); +z_result_t z_task_init(z_owned_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg); +z_result_t z_task_join(z_owned_task_t *task); /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m); -int8_t _z_mutex_drop(_z_mutex_t *m); +z_result_t _z_mutex_init(_z_mutex_t *m); +z_result_t _z_mutex_drop(_z_mutex_t *m); -int8_t _z_mutex_lock(_z_mutex_t *m); -int8_t _z_mutex_try_lock(_z_mutex_t *m); -int8_t _z_mutex_unlock(_z_mutex_t *m); +z_result_t _z_mutex_lock(_z_mutex_t *m); +z_result_t _z_mutex_try_lock(_z_mutex_t *m); +z_result_t _z_mutex_unlock(_z_mutex_t *m); _Z_OWNED_TYPE_VALUE(_z_mutex_t, mutex) _Z_OWNED_FUNCTIONS_SYSTEM_DEF(mutex) -int8_t z_mutex_init(z_owned_mutex_t *m); -int8_t z_mutex_drop(z_moved_mutex_t *m); +z_result_t z_mutex_init(z_owned_mutex_t *m); +z_result_t z_mutex_drop(z_moved_mutex_t *m); -int8_t z_mutex_lock(z_loaned_mutex_t *m); -int8_t z_mutex_try_lock(z_loaned_mutex_t *m); -int8_t z_mutex_unlock(z_loaned_mutex_t *m); +z_result_t z_mutex_lock(z_loaned_mutex_t *m); +z_result_t z_mutex_try_lock(z_loaned_mutex_t *m); +z_result_t z_mutex_unlock(z_loaned_mutex_t *m); /*------------------ CondVar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t *cv); -int8_t _z_condvar_drop(_z_condvar_t *cv); +z_result_t _z_condvar_init(_z_condvar_t *cv); +z_result_t _z_condvar_drop(_z_condvar_t *cv); -int8_t _z_condvar_signal(_z_condvar_t *cv); -int8_t _z_condvar_signal_all(_z_condvar_t *cv); -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m); +z_result_t _z_condvar_signal(_z_condvar_t *cv); +z_result_t _z_condvar_signal_all(_z_condvar_t *cv); +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m); _Z_OWNED_TYPE_VALUE(_z_condvar_t, condvar) _Z_OWNED_FUNCTIONS_SYSTEM_DEF(condvar) -int8_t z_condvar_init(z_owned_condvar_t *cv); -int8_t z_condvar_drop(z_moved_condvar_t *cv); +z_result_t z_condvar_init(z_owned_condvar_t *cv); +z_result_t z_condvar_drop(z_moved_condvar_t *cv); -int8_t z_condvar_signal(z_loaned_condvar_t *cv); -int8_t z_condvar_wait(z_loaned_condvar_t *cv, z_loaned_mutex_t *m); +z_result_t z_condvar_signal(z_loaned_condvar_t *cv); +z_result_t z_condvar_wait(z_loaned_condvar_t *cv, z_loaned_mutex_t *m); /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time); @@ -154,7 +154,7 @@ typedef struct { uint32_t nanos; } zp_time_since_epoch; -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t); +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t); #ifdef __cplusplus } #endif diff --git a/include/zenoh-pico/transport/common/lease.h b/include/zenoh-pico/transport/common/lease.h index 8d85e7c17..900a2f887 100644 --- a/include/zenoh-pico/transport/common/lease.h +++ b/include/zenoh-pico/transport/common/lease.h @@ -17,7 +17,7 @@ #include "zenoh-pico/transport/transport.h" -int8_t _z_send_join(_z_transport_t *zt); -int8_t _z_send_keep_alive(_z_transport_t *zt); +z_result_t _z_send_join(_z_transport_t *zt); +z_result_t _z_send_keep_alive(_z_transport_t *zt); #endif /* ZENOH_PICO_TRANSPORT_LEASE_H */ diff --git a/include/zenoh-pico/transport/common/read.h b/include/zenoh-pico/transport/common/read.h index fe87896ab..f298d1878 100644 --- a/include/zenoh-pico/transport/common/read.h +++ b/include/zenoh-pico/transport/common/read.h @@ -17,7 +17,7 @@ #include "zenoh-pico/transport/transport.h" -int8_t _z_read(_z_transport_t *zt); +z_result_t _z_read(_z_transport_t *zt); void *_zp_read_task(void *zt_arg); // The argument is void* to avoid incompatible pointer types in tasks #endif /* ZENOH_PICO_TRANSPORT_READ_H */ diff --git a/include/zenoh-pico/transport/common/rx.h b/include/zenoh-pico/transport/common/rx.h index 11e6cc1fe..147273816 100644 --- a/include/zenoh-pico/transport/common/rx.h +++ b/include/zenoh-pico/transport/common/rx.h @@ -20,6 +20,6 @@ /*------------------ Transmission and Reception helpers ------------------*/ size_t _z_read_stream_size(_z_zbuf_t *zbuf); -int8_t _z_link_recv_t_msg(_z_transport_message_t *t_msg, const _z_link_t *zl); +z_result_t _z_link_recv_t_msg(_z_transport_message_t *t_msg, const _z_link_t *zl); #endif /* ZENOH_PICO_TRANSPORT_RX_H */ diff --git a/include/zenoh-pico/transport/common/tx.h b/include/zenoh-pico/transport/common/tx.h index d7870c54a..1eb4abac1 100644 --- a/include/zenoh-pico/transport/common/tx.h +++ b/include/zenoh-pico/transport/common/tx.h @@ -23,10 +23,10 @@ void __unsafe_z_prepare_wbuf(_z_wbuf_t *buf, uint8_t link_flow_capability); void __unsafe_z_finalize_wbuf(_z_wbuf_t *buf, uint8_t link_flow_capability); /*This function is unsafe because it operates in potentially concurrent data.*Make sure that the following mutexes are locked before calling this function : *-ztu->mutex_tx */ -int8_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z_reliability_t reliability, size_t sn); +z_result_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z_reliability_t reliability, size_t sn); /*------------------ Transmission and Reception helpers ------------------*/ -int8_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg); -int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg); +z_result_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg); +z_result_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg); #endif /* ZENOH_PICO_TRANSPORT_TX_H */ diff --git a/include/zenoh-pico/transport/manager.h b/include/zenoh-pico/transport/manager.h index 6a6a7ad48..8ac95dd7c 100644 --- a/include/zenoh-pico/transport/manager.h +++ b/include/zenoh-pico/transport/manager.h @@ -19,7 +19,7 @@ #include "zenoh-pico/link/manager.h" #include "zenoh-pico/transport/transport.h" -int8_t _z_new_transport(_z_transport_t *zt, _z_id_t *bs, _z_string_t *locator, z_whatami_t mode); +z_result_t _z_new_transport(_z_transport_t *zt, _z_id_t *bs, _z_string_t *locator, z_whatami_t mode); void _z_free_transport(_z_transport_t **zt); #endif /* INCLUDE_ZENOH_PICO_TRANSPORT_MANAGER_H */ diff --git a/include/zenoh-pico/transport/multicast/lease.h b/include/zenoh-pico/transport/multicast/lease.h index e9202aa11..09a0b4135 100644 --- a/include/zenoh-pico/transport/multicast/lease.h +++ b/include/zenoh-pico/transport/multicast/lease.h @@ -17,15 +17,15 @@ #include "zenoh-pico/transport/transport.h" -int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm); -int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm); -int8_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm); +z_result_t _zp_multicast_send_join(_z_transport_multicast_t *ztm); +z_result_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm); +z_result_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm); void *_zp_multicast_lease_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1) -int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, z_task_attr_t *attr, _z_task_t *task); +z_result_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, z_task_attr_t *attr, _z_task_t *task); #else -int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, void *attr, void *task); +z_result_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, void *attr, void *task); #endif /* Z_FEATURE_MULTI_THREAD == 1 && (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1) */ #endif /* ZENOH_PICO_MULTICAST_LEASE_H */ diff --git a/include/zenoh-pico/transport/multicast/read.h b/include/zenoh-pico/transport/multicast/read.h index 5a0fda213..acaa82308 100644 --- a/include/zenoh-pico/transport/multicast/read.h +++ b/include/zenoh-pico/transport/multicast/read.h @@ -17,14 +17,14 @@ #include "zenoh-pico/transport/transport.h" -int8_t _zp_multicast_read(_z_transport_multicast_t *ztm); -int8_t _zp_multicast_stop_read_task(_z_transport_t *zt); +z_result_t _zp_multicast_read(_z_transport_multicast_t *ztm); +z_result_t _zp_multicast_stop_read_task(_z_transport_t *zt); void *_zp_multicast_read_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_MULTICAST_TRANSPORT == 1 -int8_t _zp_multicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task); +z_result_t _zp_multicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task); #else -int8_t _zp_multicast_start_read_task(_z_transport_t *zt, void *attr, void *task); +z_result_t _zp_multicast_start_read_task(_z_transport_t *zt, void *attr, void *task); #endif /* #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_MULTICAST_TRANSPORT == 1 */ #endif /* ZENOH_PICO_MULTICAST_READ_H */ diff --git a/include/zenoh-pico/transport/multicast/rx.h b/include/zenoh-pico/transport/multicast/rx.h index 8357e8291..31a10e64a 100644 --- a/include/zenoh-pico/transport/multicast/rx.h +++ b/include/zenoh-pico/transport/multicast/rx.h @@ -17,8 +17,8 @@ #include "zenoh-pico/transport/transport.h" -int8_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr); -int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, - _z_slice_t *addr); +z_result_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr); +z_result_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, + _z_slice_t *addr); #endif /* ZENOH_PICO_TRANSPORT_LINK_RX_H */ diff --git a/include/zenoh-pico/transport/multicast/transport.h b/include/zenoh-pico/transport/multicast/transport.h index b4795f959..fa9cd085c 100644 --- a/include/zenoh-pico/transport/multicast/transport.h +++ b/include/zenoh-pico/transport/multicast/transport.h @@ -17,13 +17,13 @@ #include "zenoh-pico/api/types.h" -int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, - _z_transport_multicast_establish_param_t *param); -int8_t _z_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid); -int8_t _z_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid); -int8_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, bool link_only); -int8_t _z_multicast_transport_close(_z_transport_multicast_t *ztm, uint8_t reason); +z_result_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, + _z_transport_multicast_establish_param_t *param); +z_result_t _z_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid); +z_result_t _z_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid); +z_result_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, bool link_only); +z_result_t _z_multicast_transport_close(_z_transport_multicast_t *ztm, uint8_t reason); void _z_multicast_transport_clear(_z_transport_t *zt); #endif /* ZENOH_PICO_MULTICAST_TRANSPORT_H */ diff --git a/include/zenoh-pico/transport/multicast/tx.h b/include/zenoh-pico/transport/multicast/tx.h index 6b48266db..c9721523a 100644 --- a/include/zenoh-pico/transport/multicast/tx.h +++ b/include/zenoh-pico/transport/multicast/tx.h @@ -18,8 +18,8 @@ #include "zenoh-pico/net/session.h" #include "zenoh-pico/transport/transport.h" -int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl); -int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg); +z_result_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl); +z_result_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg); #endif /* ZENOH_PICO_MULTICAST_TX_H */ diff --git a/include/zenoh-pico/transport/raweth/read.h b/include/zenoh-pico/transport/raweth/read.h index 7c98e1c87..6ead7be9b 100644 --- a/include/zenoh-pico/transport/raweth/read.h +++ b/include/zenoh-pico/transport/raweth/read.h @@ -17,14 +17,14 @@ #include "zenoh-pico/transport/transport.h" -int8_t _zp_raweth_read(_z_transport_multicast_t *ztm); -int8_t _zp_raweth_stop_read_task(_z_transport_t *zt); +z_result_t _zp_raweth_read(_z_transport_multicast_t *ztm); +z_result_t _zp_raweth_stop_read_task(_z_transport_t *zt); void *_zp_raweth_read_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_RAWETH_TRANSPORT == 1 -int8_t _zp_raweth_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task); +z_result_t _zp_raweth_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task); #else -int8_t _zp_raweth_start_read_task(_z_transport_t *zt, void *attr, void *task); +z_result_t _zp_raweth_start_read_task(_z_transport_t *zt, void *attr, void *task); #endif /* Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_RAWETH_TRANSPORT == 1 */ #endif /* ZENOH_PICO_RAWETH_READ_H */ diff --git a/include/zenoh-pico/transport/raweth/rx.h b/include/zenoh-pico/transport/raweth/rx.h index 4484a2e43..81874d633 100644 --- a/include/zenoh-pico/transport/raweth/rx.h +++ b/include/zenoh-pico/transport/raweth/rx.h @@ -17,7 +17,7 @@ #include "zenoh-pico/transport/transport.h" -int8_t _z_raweth_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr); -int8_t _z_raweth_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr); +z_result_t _z_raweth_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr); +z_result_t _z_raweth_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr); #endif /* ZENOH_PICO_RAWETH_RX_H */ diff --git a/include/zenoh-pico/transport/raweth/tx.h b/include/zenoh-pico/transport/raweth/tx.h index 8146e38e4..83abdd9fb 100644 --- a/include/zenoh-pico/transport/raweth/tx.h +++ b/include/zenoh-pico/transport/raweth/tx.h @@ -18,9 +18,9 @@ #include "zenoh-pico/net/session.h" #include "zenoh-pico/transport/transport.h" -int8_t _z_raweth_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg); -int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl); -int8_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg); +z_result_t _z_raweth_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg); +z_result_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl); +z_result_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg); #endif /* ZENOH_PICO_RAWETH_TX_H */ diff --git a/include/zenoh-pico/transport/transport.h b/include/zenoh-pico/transport/transport.h index 0ae300833..5f99c3aa8 100644 --- a/include/zenoh-pico/transport/transport.h +++ b/include/zenoh-pico/transport/transport.h @@ -61,7 +61,7 @@ typedef struct _z_session_rc_t _z_session_rc_ref_t; // Forward declaration to be used in _zp_f_send_tmsg* typedef struct _z_transport_multicast_t _z_transport_multicast_t; // Send function prototype -typedef int8_t (*_zp_f_send_tmsg)(_z_transport_multicast_t *self, const _z_transport_message_t *t_msg); +typedef z_result_t (*_zp_f_send_tmsg)(_z_transport_multicast_t *self, const _z_transport_message_t *t_msg); typedef struct { // Session associated to the transport @@ -182,7 +182,7 @@ typedef struct { uint8_t _seq_num_res; } _z_transport_multicast_establish_param_t; -int8_t _z_transport_close(_z_transport_t *zt, uint8_t reason); +z_result_t _z_transport_close(_z_transport_t *zt, uint8_t reason); void _z_transport_clear(_z_transport_t *zt); void _z_transport_free(_z_transport_t **zt); diff --git a/include/zenoh-pico/transport/unicast/lease.h b/include/zenoh-pico/transport/unicast/lease.h index 17361c32e..469fd1333 100644 --- a/include/zenoh-pico/transport/unicast/lease.h +++ b/include/zenoh-pico/transport/unicast/lease.h @@ -17,14 +17,14 @@ #include "zenoh-pico/transport/transport.h" -int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu); -int8_t _zp_unicast_stop_lease_task(_z_transport_t *zt); +z_result_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu); +z_result_t _zp_unicast_stop_lease_task(_z_transport_t *zt); void *_zp_unicast_lease_task(void *ztu_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 -int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task); +z_result_t _zp_unicast_start_lease_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task); #else -int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, void *attr, void *task); +z_result_t _zp_unicast_start_lease_task(_z_transport_t *zt, void *attr, void *task); #endif /* Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 */ #endif /* ZENOH_PICO_TRANSPORT_LINK_TASK_LEASE_H */ diff --git a/include/zenoh-pico/transport/unicast/read.h b/include/zenoh-pico/transport/unicast/read.h index 91c7b9356..63a8976bb 100644 --- a/include/zenoh-pico/transport/unicast/read.h +++ b/include/zenoh-pico/transport/unicast/read.h @@ -17,14 +17,14 @@ #include "zenoh-pico/transport/transport.h" -int8_t _zp_unicast_read(_z_transport_unicast_t *ztu); -int8_t _zp_unicast_stop_read_task(_z_transport_t *zt); +z_result_t _zp_unicast_read(_z_transport_unicast_t *ztu); +z_result_t _zp_unicast_stop_read_task(_z_transport_t *zt); void *_zp_unicast_read_task(void *ztu_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 -int8_t _zp_unicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task); +z_result_t _zp_unicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task); #else -int8_t _zp_unicast_start_read_task(_z_transport_t *zt, void *attr, void *task); +z_result_t _zp_unicast_start_read_task(_z_transport_t *zt, void *attr, void *task); #endif /* Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 */ #endif /* ZENOH_PICO_UNICAST_READ_H */ diff --git a/include/zenoh-pico/transport/unicast/rx.h b/include/zenoh-pico/transport/unicast/rx.h index 61dd89507..f36cb592c 100644 --- a/include/zenoh-pico/transport/unicast/rx.h +++ b/include/zenoh-pico/transport/unicast/rx.h @@ -17,8 +17,8 @@ #include "zenoh-pico/transport/transport.h" -int8_t _z_unicast_recv_t_msg(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg); -int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg); -int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg); +z_result_t _z_unicast_recv_t_msg(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg); +z_result_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg); +z_result_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg); #endif /* ZENOH_PICO_UNICAST_RX_H */ diff --git a/include/zenoh-pico/transport/unicast/transport.h b/include/zenoh-pico/transport/unicast/transport.h index 5f344b072..4b60b7c70 100644 --- a/include/zenoh-pico/transport/unicast/transport.h +++ b/include/zenoh-pico/transport/unicast/transport.h @@ -17,12 +17,13 @@ #include "zenoh-pico/api/types.h" -int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transport_unicast_establish_param_t *param); -int8_t _z_unicast_open_client(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid); -int8_t _z_unicast_open_peer(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid); -int8_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, bool link_only); -int8_t _z_unicast_transport_close(_z_transport_unicast_t *ztu, uint8_t reason); +z_result_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, + _z_transport_unicast_establish_param_t *param); +z_result_t _z_unicast_open_client(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid); +z_result_t _z_unicast_open_peer(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid); +z_result_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, bool link_only); +z_result_t _z_unicast_transport_close(_z_transport_unicast_t *ztu, uint8_t reason); void _z_unicast_transport_clear(_z_transport_t *zt); #endif /* ZENOH_PICO_UNICAST_TRANSPORT_H */ diff --git a/include/zenoh-pico/transport/unicast/tx.h b/include/zenoh-pico/transport/unicast/tx.h index d087dd696..56a33bfdd 100644 --- a/include/zenoh-pico/transport/unicast/tx.h +++ b/include/zenoh-pico/transport/unicast/tx.h @@ -18,8 +18,8 @@ #include "zenoh-pico/net/session.h" #include "zenoh-pico/transport/transport.h" -int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl); -int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_message_t *t_msg); +z_result_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl); +z_result_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_message_t *t_msg); #endif /* ZENOH_PICO_TRANSPORT_LINK_TX_H */ diff --git a/include/zenoh-pico/utils/config.h b/include/zenoh-pico/utils/config.h index 0a538e7d0..de17a1239 100644 --- a/include/zenoh-pico/utils/config.h +++ b/include/zenoh-pico/utils/config.h @@ -34,7 +34,7 @@ typedef _z_str_intmap_t _z_config_t; /** * Initialize a new empty map of properties. */ -int8_t _z_config_init(_z_config_t *ps); +z_result_t _z_config_init(_z_config_t *ps); /** * Insert a property with a given key to a properties map. @@ -45,7 +45,7 @@ int8_t _z_config_init(_z_config_t *ps); * key: The key of the property to add. * value: The value of the property to add. */ -int8_t _zp_config_insert(_z_config_t *ps, uint8_t key, const char *value); +z_result_t _zp_config_insert(_z_config_t *ps, uint8_t key, const char *value); /** * Get the property with the given key from a properties map. diff --git a/include/zenoh-pico/utils/result.h b/include/zenoh-pico/utils/result.h index ad313830a..8a6143ea5 100644 --- a/include/zenoh-pico/utils/result.h +++ b/include/zenoh-pico/utils/result.h @@ -85,7 +85,7 @@ typedef enum { #define _Z_RETURN_IF_ERR(expr) \ { \ - int8_t __res = expr; \ + z_result_t __res = expr; \ if (__res != _Z_RES_OK) { \ return __res; \ } \ @@ -93,7 +93,7 @@ typedef enum { #define _Z_CLEAN_RETURN_IF_ERR(base_expr, clean_expr) \ { \ - int8_t __res = base_expr; \ + z_result_t __res = base_expr; \ if (__res != _Z_RES_OK) { \ clean_expr; \ return __res; \ diff --git a/src/api/api.c b/src/api/api.c index ea74e6f80..d20ac38b2 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -49,12 +49,12 @@ /********* Data Types Handlers *********/ -int8_t z_view_string_from_str(z_view_string_t *str, const char *value) { +z_result_t z_view_string_from_str(z_view_string_t *str, const char *value) { str->_val = _z_string_alias_str((char *)value); return _Z_RES_OK; } -int8_t z_view_string_from_substr(z_view_string_t *str, const char *value, size_t len) { +z_result_t z_view_string_from_substr(z_view_string_t *str, const char *value, size_t len) { str->_val = _z_string_alias_substr((char *)value, len); return _Z_RES_OK; } @@ -86,13 +86,13 @@ size_t z_string_array_len(const z_loaned_string_array_t *a) { return _z_string_s bool z_string_array_is_empty(const z_loaned_string_array_t *a) { return _z_string_svec_is_empty(a); } -int8_t z_keyexpr_is_canon(const char *start, size_t len) { return _z_keyexpr_is_canon(start, len); } +z_result_t z_keyexpr_is_canon(const char *start, size_t len) { return _z_keyexpr_is_canon(start, len); } -int8_t z_keyexpr_canonize(char *start, size_t *len) { return _z_keyexpr_canonize(start, len); } +z_result_t z_keyexpr_canonize(char *start, size_t *len) { return _z_keyexpr_canonize(start, len); } -int8_t z_keyexpr_canonize_null_terminated(char *start) { +z_result_t z_keyexpr_canonize_null_terminated(char *start) { size_t len = (start != NULL) ? strlen(start) : 0; - int8_t res = _z_keyexpr_canonize(start, &len); + z_result_t res = _z_keyexpr_canonize(start, &len); if (res == _Z_RES_OK) { start[len] = '\0'; } @@ -109,7 +109,7 @@ z_result_t z_view_keyexpr_from_substr(z_view_keyexpr_t *keyexpr, const char *nam return _Z_RES_OK; } -int8_t z_view_keyexpr_from_str(z_view_keyexpr_t *keyexpr, const char *name) { +z_result_t z_view_keyexpr_from_str(z_view_keyexpr_t *keyexpr, const char *name) { size_t name_len = strlen(name); return z_view_keyexpr_from_substr(keyexpr, name, name_len); } @@ -120,7 +120,7 @@ z_result_t z_view_keyexpr_from_substr_autocanonize(z_view_keyexpr_t *keyexpr, ch return _Z_RES_OK; } -int8_t z_view_keyexpr_from_str_autocanonize(z_view_keyexpr_t *keyexpr, char *name) { +z_result_t z_view_keyexpr_from_str_autocanonize(z_view_keyexpr_t *keyexpr, char *name) { size_t name_len = strlen(name); return z_view_keyexpr_from_substr_autocanonize(keyexpr, name, &name_len); } @@ -129,12 +129,12 @@ void z_view_keyexpr_from_substr_unchecked(z_view_keyexpr_t *keyexpr, const char keyexpr->_val = _z_keyexpr_from_substr(0, name, len); } -int8_t z_keyexpr_as_view_string(const z_loaned_keyexpr_t *keyexpr, z_view_string_t *s) { +z_result_t z_keyexpr_as_view_string(const z_loaned_keyexpr_t *keyexpr, z_view_string_t *s) { s->_val = _z_string_alias(&keyexpr->_suffix); return _Z_RES_OK; } -int8_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const char *right, size_t len) { +z_result_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const char *right, size_t len) { z_internal_keyexpr_null(key); if (len == 0) { return _z_keyexpr_copy(&key->_val, left); @@ -162,7 +162,7 @@ int8_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, return _Z_RES_OK; } -int8_t z_keyexpr_join(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const z_loaned_keyexpr_t *right) { +z_result_t z_keyexpr_join(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const z_loaned_keyexpr_t *right) { z_internal_keyexpr_null(key); size_t left_len = _z_string_len(&left->_suffix); @@ -206,11 +206,11 @@ bool z_keyexpr_equals(const z_loaned_keyexpr_t *l, const z_loaned_keyexpr_t *r) void z_config_new(z_owned_config_t *config) { config->_val = _z_config_empty(); } -int8_t z_config_default(z_owned_config_t *config) { return _z_config_default(&config->_val); } +z_result_t z_config_default(z_owned_config_t *config) { return _z_config_default(&config->_val); } const char *zp_config_get(const z_loaned_config_t *config, uint8_t key) { return _z_config_get(config, key); } -int8_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char *value) { +z_result_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char *value) { return _zp_config_insert(config, key, value); } @@ -295,7 +295,7 @@ static uint16_t _z_encoding_values_str_to_int(const char *schema, size_t len) { return UINT16_MAX; } -static int8_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { +static z_result_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { size_t pos = 0; for (; pos < len; ++pos) { if (s[pos] == ENCODING_SCHEMA_SEPARATOR) break; @@ -314,7 +314,7 @@ static int8_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, cons return _z_encoding_make(&encoding->_val, _Z_ENCODING_ID_DEFAULT, s, len); } -static int8_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { +static z_result_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { const char *prefix = NULL; size_t prefix_len = 0; // Convert id @@ -349,11 +349,11 @@ static int8_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encodin } #else -static int8_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { +static z_result_t _z_encoding_convert_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { return _z_encoding_make(encoding->_val, _Z_ENCODING_ID_DEFAULT, s, len); } -static int8_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { +static z_result_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { _z_string_copy(s->_val, &encoding->schema); return _Z_RES_OK; } @@ -363,7 +363,7 @@ static int8_t _z_encoding_convert_into_string(const z_loaned_encoding_t *encodin _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_encoding_t, encoding, _z_encoding_check, _z_encoding_null, _z_encoding_copy, _z_encoding_clear) -int8_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) { +z_result_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) { // Init owned encoding z_internal_encoding_null(encoding); // Convert string to encoding @@ -373,7 +373,7 @@ int8_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) { return _Z_RES_OK; } -int8_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { +z_result_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { // Init owned encoding z_internal_encoding_null(encoding); // Convert string to encoding @@ -382,11 +382,11 @@ int8_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_ } return _Z_RES_OK; } -int8_t z_encoding_set_schema_from_str(z_loaned_encoding_t *encoding, const char *schema) { +z_result_t z_encoding_set_schema_from_str(z_loaned_encoding_t *encoding, const char *schema) { return z_encoding_set_schema_from_substr(encoding, schema, strlen(schema)); } -int8_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const char *schema, size_t len) { +z_result_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const char *schema, size_t len) { _z_string_clear(&encoding->schema); if (schema == NULL && len > 0) { return _Z_ERR_INVALID; @@ -398,7 +398,7 @@ int8_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const ch return _Z_RES_OK; } -int8_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { +z_result_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { // Init owned string z_internal_string_null(s); // Convert encoding to string @@ -406,7 +406,7 @@ int8_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_ return _Z_RES_OK; } -int8_t z_slice_copy_from_buf(z_owned_slice_t *slice, const uint8_t *data, size_t len) { +z_result_t z_slice_copy_from_buf(z_owned_slice_t *slice, const uint8_t *data, size_t len) { slice->_val = _z_slice_copy_from_buf(data, len); if (slice->_val.start == NULL) { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -415,8 +415,8 @@ int8_t z_slice_copy_from_buf(z_owned_slice_t *slice, const uint8_t *data, size_t } } -int8_t z_slice_from_buf(z_owned_slice_t *slice, uint8_t *data, size_t len, void (*deleter)(void *data, void *context), - void *context) { +z_result_t z_slice_from_buf(z_owned_slice_t *slice, uint8_t *data, size_t len, + void (*deleter)(void *data, void *context), void *context) { slice->_val = _z_slice_from_buf_custom_deleter(data, len, _z_delete_context_create(deleter, context)); return _Z_RES_OK; } @@ -429,52 +429,52 @@ void z_slice_empty(z_owned_slice_t *slice) { slice->_val = _z_slice_empty(); } bool z_slice_is_empty(const z_loaned_slice_t *slice) { return _z_slice_is_empty(slice); } -int8_t z_bytes_deserialize_into_int8(const z_loaned_bytes_t *bytes, int8_t *dst) { +z_result_t z_bytes_deserialize_into_int8(const z_loaned_bytes_t *bytes, int8_t *dst) { return _z_bytes_to_uint8(bytes, (uint8_t *)dst); } -int8_t z_bytes_deserialize_into_int16(const z_loaned_bytes_t *bytes, int16_t *dst) { +z_result_t z_bytes_deserialize_into_int16(const z_loaned_bytes_t *bytes, int16_t *dst) { return _z_bytes_to_uint16(bytes, (uint16_t *)dst); } -int8_t z_bytes_deserialize_into_int32(const z_loaned_bytes_t *bytes, int32_t *dst) { +z_result_t z_bytes_deserialize_into_int32(const z_loaned_bytes_t *bytes, int32_t *dst) { return _z_bytes_to_uint32(bytes, (uint32_t *)dst); } -int8_t z_bytes_deserialize_into_int64(const z_loaned_bytes_t *bytes, int64_t *dst) { +z_result_t z_bytes_deserialize_into_int64(const z_loaned_bytes_t *bytes, int64_t *dst) { return _z_bytes_to_uint64(bytes, (uint64_t *)dst); } -int8_t z_bytes_deserialize_into_uint8(const z_loaned_bytes_t *bytes, uint8_t *dst) { +z_result_t z_bytes_deserialize_into_uint8(const z_loaned_bytes_t *bytes, uint8_t *dst) { return _z_bytes_to_uint8(bytes, dst); } -int8_t z_bytes_deserialize_into_uint16(const z_loaned_bytes_t *bytes, uint16_t *dst) { +z_result_t z_bytes_deserialize_into_uint16(const z_loaned_bytes_t *bytes, uint16_t *dst) { return _z_bytes_to_uint16(bytes, dst); } -int8_t z_bytes_deserialize_into_uint32(const z_loaned_bytes_t *bytes, uint32_t *dst) { +z_result_t z_bytes_deserialize_into_uint32(const z_loaned_bytes_t *bytes, uint32_t *dst) { return _z_bytes_to_uint32(bytes, dst); } -int8_t z_bytes_deserialize_into_uint64(const z_loaned_bytes_t *bytes, uint64_t *dst) { +z_result_t z_bytes_deserialize_into_uint64(const z_loaned_bytes_t *bytes, uint64_t *dst) { return _z_bytes_to_uint64(bytes, dst); } -int8_t z_bytes_deserialize_into_float(const z_loaned_bytes_t *bytes, float *dst) { +z_result_t z_bytes_deserialize_into_float(const z_loaned_bytes_t *bytes, float *dst) { return _z_bytes_to_float(bytes, dst); } -int8_t z_bytes_deserialize_into_double(const z_loaned_bytes_t *bytes, double *dst) { +z_result_t z_bytes_deserialize_into_double(const z_loaned_bytes_t *bytes, double *dst) { return _z_bytes_to_double(bytes, dst); } -int8_t z_bytes_deserialize_into_slice(const z_loaned_bytes_t *bytes, z_owned_slice_t *dst) { +z_result_t z_bytes_deserialize_into_slice(const z_loaned_bytes_t *bytes, z_owned_slice_t *dst) { dst->_val = _z_slice_empty(); return _z_bytes_to_slice(bytes, &dst->_val); } -int8_t z_bytes_deserialize_into_string(const z_loaned_bytes_t *bytes, z_owned_string_t *s) { +z_result_t z_bytes_deserialize_into_string(const z_loaned_bytes_t *bytes, z_owned_string_t *s) { // Init owned string z_internal_string_null(s); // Convert bytes to string @@ -485,92 +485,93 @@ int8_t z_bytes_deserialize_into_string(const z_loaned_bytes_t *bytes, z_owned_st return _Z_RES_OK; } -int8_t z_bytes_deserialize_into_pair(const z_loaned_bytes_t *bytes, z_owned_bytes_t *first, z_owned_bytes_t *second) { +z_result_t z_bytes_deserialize_into_pair(const z_loaned_bytes_t *bytes, z_owned_bytes_t *first, + z_owned_bytes_t *second) { // Init pair of owned bytes z_bytes_empty(first); z_bytes_empty(second); return _z_bytes_deserialize_into_pair(bytes, &first->_val, &second->_val); } -int8_t z_bytes_serialize_from_int8(z_owned_bytes_t *bytes, int8_t val) { +z_result_t z_bytes_serialize_from_int8(z_owned_bytes_t *bytes, int8_t val) { return z_bytes_serialize_from_uint8(bytes, (uint8_t)val); } -int8_t z_bytes_serialize_from_int16(z_owned_bytes_t *bytes, int16_t val) { +z_result_t z_bytes_serialize_from_int16(z_owned_bytes_t *bytes, int16_t val) { return z_bytes_serialize_from_uint16(bytes, (uint16_t)val); } -int8_t z_bytes_serialize_from_int32(z_owned_bytes_t *bytes, int32_t val) { +z_result_t z_bytes_serialize_from_int32(z_owned_bytes_t *bytes, int32_t val) { return z_bytes_serialize_from_uint32(bytes, (uint32_t)val); } -int8_t z_bytes_serialize_from_int64(z_owned_bytes_t *bytes, int64_t val) { +z_result_t z_bytes_serialize_from_int64(z_owned_bytes_t *bytes, int64_t val) { return z_bytes_serialize_from_uint64(bytes, (uint64_t)val); } -int8_t z_bytes_serialize_from_uint8(z_owned_bytes_t *bytes, uint8_t val) { +z_result_t z_bytes_serialize_from_uint8(z_owned_bytes_t *bytes, uint8_t val) { z_bytes_empty(bytes); return _z_bytes_from_uint8(&bytes->_val, val); } -int8_t z_bytes_serialize_from_uint16(z_owned_bytes_t *bytes, uint16_t val) { +z_result_t z_bytes_serialize_from_uint16(z_owned_bytes_t *bytes, uint16_t val) { z_bytes_empty(bytes); return _z_bytes_from_uint16(&bytes->_val, val); } -int8_t z_bytes_serialize_from_uint32(z_owned_bytes_t *bytes, uint32_t val) { +z_result_t z_bytes_serialize_from_uint32(z_owned_bytes_t *bytes, uint32_t val) { z_bytes_empty(bytes); return _z_bytes_from_uint32(&bytes->_val, val); } -int8_t z_bytes_serialize_from_uint64(z_owned_bytes_t *bytes, uint64_t val) { +z_result_t z_bytes_serialize_from_uint64(z_owned_bytes_t *bytes, uint64_t val) { z_bytes_empty(bytes); return _z_bytes_from_uint64(&bytes->_val, val); } -int8_t z_bytes_serialize_from_float(z_owned_bytes_t *bytes, float val) { +z_result_t z_bytes_serialize_from_float(z_owned_bytes_t *bytes, float val) { z_bytes_empty(bytes); return _z_bytes_from_float(&bytes->_val, val); } -int8_t z_bytes_serialize_from_double(z_owned_bytes_t *bytes, double val) { +z_result_t z_bytes_serialize_from_double(z_owned_bytes_t *bytes, double val) { z_bytes_empty(bytes); return _z_bytes_from_double(&bytes->_val, val); } -int8_t z_bytes_from_slice(z_owned_bytes_t *bytes, z_moved_slice_t *slice) { +z_result_t z_bytes_from_slice(z_owned_bytes_t *bytes, z_moved_slice_t *slice) { z_bytes_empty(bytes); _z_slice_t s = _z_slice_steal(&slice->_this._val); _Z_CLEAN_RETURN_IF_ERR(_z_bytes_from_slice(&bytes->_val, s), _z_slice_clear(&s)); return _Z_RES_OK; } -int8_t z_bytes_serialize_from_slice(z_owned_bytes_t *bytes, const z_loaned_slice_t *slice) { +z_result_t z_bytes_serialize_from_slice(z_owned_bytes_t *bytes, const z_loaned_slice_t *slice) { z_owned_slice_t s; _Z_RETURN_IF_ERR(z_slice_clone(&s, slice)); return z_bytes_from_slice(bytes, z_slice_move(&s)); } -int8_t z_bytes_from_buf(z_owned_bytes_t *bytes, uint8_t *data, size_t len, void (*deleter)(void *data, void *context), - void *context) { +z_result_t z_bytes_from_buf(z_owned_bytes_t *bytes, uint8_t *data, size_t len, + void (*deleter)(void *data, void *context), void *context) { z_owned_slice_t s; s._val = _z_slice_from_buf_custom_deleter(data, len, _z_delete_context_create(deleter, context)); return z_bytes_from_slice(bytes, z_slice_move(&s)); } -int8_t z_bytes_from_static_buf(z_owned_bytes_t *bytes, const uint8_t *data, size_t len) { +z_result_t z_bytes_from_static_buf(z_owned_bytes_t *bytes, const uint8_t *data, size_t len) { z_owned_slice_t s; s._val = _z_slice_alias_buf(data, len); return z_bytes_from_slice(bytes, z_slice_move(&s)); } -int8_t z_bytes_serialize_from_buf(z_owned_bytes_t *bytes, const uint8_t *data, size_t len) { +z_result_t z_bytes_serialize_from_buf(z_owned_bytes_t *bytes, const uint8_t *data, size_t len) { z_owned_slice_t s; _Z_RETURN_IF_ERR(z_slice_copy_from_buf(&s, data, len)); return z_bytes_from_slice(bytes, z_slice_move(&s)); } -int8_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t *s) { +z_result_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t *s) { // TODO, verify that string is a valid UTF-8 ? z_owned_slice_t slice; size_t str_len = _z_string_len(&s->_this._val); @@ -579,33 +580,33 @@ int8_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t *s) { return z_bytes_from_slice(bytes, z_slice_move(&slice)); } -int8_t z_bytes_serialize_from_string(z_owned_bytes_t *bytes, const z_loaned_string_t *s) { +z_result_t z_bytes_serialize_from_string(z_owned_bytes_t *bytes, const z_loaned_string_t *s) { z_owned_string_t s_copy; _Z_RETURN_IF_ERR(z_string_clone(&s_copy, s)); return z_bytes_from_string(bytes, z_string_move(&s_copy)); } -int8_t z_bytes_from_str(z_owned_bytes_t *bytes, char *value, void (*deleter)(void *value, void *context), - void *context) { +z_result_t z_bytes_from_str(z_owned_bytes_t *bytes, char *value, void (*deleter)(void *value, void *context), + void *context) { z_owned_string_t s; s._val = _z_string_from_str_custom_deleter(value, _z_delete_context_create(deleter, context)); return z_bytes_from_string(bytes, z_string_move(&s)); } -int8_t z_bytes_from_static_str(z_owned_bytes_t *bytes, const char *value) { +z_result_t z_bytes_from_static_str(z_owned_bytes_t *bytes, const char *value) { z_owned_string_t s; s._val = _z_string_alias_str(value); return z_bytes_from_string(bytes, z_string_move(&s)); } -int8_t z_bytes_serialize_from_str(z_owned_bytes_t *bytes, const char *value) { +z_result_t z_bytes_serialize_from_str(z_owned_bytes_t *bytes, const char *value) { z_owned_string_t s; _Z_RETURN_IF_ERR(z_string_copy_from_str(&s, value)); return z_bytes_from_string(bytes, z_string_move(&s)); } -int8_t z_bytes_from_iter(z_owned_bytes_t *bytes, bool (*iterator_body)(z_owned_bytes_t *data, void *context), - void *context) { +z_result_t z_bytes_from_iter(z_owned_bytes_t *bytes, bool (*iterator_body)(z_owned_bytes_t *data, void *context), + void *context) { z_bytes_empty(bytes); z_owned_bytes_t data; _z_bytes_iterator_writer_t iter_writer = _z_bytes_get_iterator_writer(&bytes->_val, 0); @@ -616,7 +617,7 @@ int8_t z_bytes_from_iter(z_owned_bytes_t *bytes, bool (*iterator_body)(z_owned_b return _Z_RES_OK; } -int8_t z_bytes_from_pair(z_owned_bytes_t *bytes, z_moved_bytes_t *first, z_moved_bytes_t *second) { +z_result_t z_bytes_from_pair(z_owned_bytes_t *bytes, z_moved_bytes_t *first, z_moved_bytes_t *second) { z_bytes_empty(bytes); return _z_bytes_from_pair(&bytes->_val, &first->_this._val, &second->_this._val); } @@ -633,11 +634,11 @@ size_t z_bytes_reader_read(z_bytes_reader_t *reader, uint8_t *dst, size_t len) { return _z_bytes_reader_read(&reader->_reader, dst, len); } -int8_t z_bytes_reader_read_bounded(z_bytes_reader_t *reader, z_owned_bytes_t *dst) { +z_result_t z_bytes_reader_read_bounded(z_bytes_reader_t *reader, z_owned_bytes_t *dst) { return _z_bytes_iterator_next(reader, &dst->_val); } -int8_t z_bytes_reader_seek(z_bytes_reader_t *reader, int64_t offset, int origin) { +z_result_t z_bytes_reader_seek(z_bytes_reader_t *reader, int64_t offset, int origin) { return _z_bytes_reader_seek(&reader->_reader, offset, origin); } @@ -672,19 +673,19 @@ z_bytes_writer_t z_bytes_get_writer(z_loaned_bytes_t *bytes) { return _z_bytes_get_iterator_writer(bytes, Z_IOSLICE_SIZE); } -int8_t z_bytes_writer_write_all(z_bytes_writer_t *writer, const uint8_t *src, size_t len) { +z_result_t z_bytes_writer_write_all(z_bytes_writer_t *writer, const uint8_t *src, size_t len) { return _z_bytes_writer_write_all(&writer->writer, src, len); } -int8_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t *bytes) { +z_result_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t *bytes) { return _z_bytes_writer_append(&writer->writer, &bytes->_this._val); } -int8_t z_bytes_writer_append_bounded(z_bytes_writer_t *writer, z_moved_bytes_t *bytes) { +z_result_t z_bytes_writer_append_bounded(z_bytes_writer_t *writer, z_moved_bytes_t *bytes) { return _z_bytes_iterator_writer_write(writer, &bytes->_this._val); } -int8_t z_timestamp_new(z_timestamp_t *ts, const z_loaned_session_t *zs) { +z_result_t z_timestamp_new(z_timestamp_t *ts, const z_loaned_session_t *zs) { *ts = _z_timestamp_null(); zp_time_since_epoch t; _Z_RETURN_IF_ERR(zp_get_time_since_epoch(&t)); @@ -764,7 +765,7 @@ void z_closure_zid_call(const z_loaned_closure_zid_t *closure, const z_id_t *id) bool _z_config_check(const _z_config_t *config) { return !_z_str_intmap_is_empty(config); } _z_config_t _z_config_null(void) { return _z_str_intmap_make(); } -int8_t _z_config_copy(_z_config_t *dst, const _z_config_t *src) { +z_result_t _z_config_copy(_z_config_t *dst, const _z_config_t *src) { *dst = _z_str_intmap_clone(src); return _Z_RES_OK; } @@ -807,7 +808,7 @@ static const char *WHAT_AM_I_TO_STRING_MAP[8] = { "Router|Peer|Client" // 0b111 }; -int8_t z_whatami_to_view_string(z_whatami_t whatami, z_view_string_t *str_out) { +z_result_t z_whatami_to_view_string(z_whatami_t whatami, z_view_string_t *str_out) { uint8_t idx = (uint8_t)whatami; if (idx >= _ZP_ARRAY_SIZE(WHAT_AM_I_TO_STRING_MAP) || idx == 0) { z_view_string_from_str(str_out, WHAT_AM_I_TO_STRING_MAP[0]); @@ -819,7 +820,7 @@ int8_t z_whatami_to_view_string(z_whatami_t whatami, z_view_string_t *str_out) { } bool _z_string_array_check(const _z_string_svec_t *val) { return !_z_string_svec_is_empty(val); } -int8_t _z_string_array_copy(_z_string_svec_t *dst, const _z_string_svec_t *src) { +z_result_t _z_string_array_copy(_z_string_svec_t *dst, const _z_string_svec_t *src) { _z_string_svec_copy(dst, src); return dst->_len == src->_len ? _Z_RES_OK : _Z_ERR_SYSTEM_OUT_OF_MEMORY; } @@ -868,8 +869,8 @@ void __z_hello_handler(_z_hello_t *hello, __z_hello_handler_wrapper_t *wrapped_c wrapped_ctx->user_call(hello, wrapped_ctx->ctx); } -int8_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, const z_scout_options_t *options) { - int8_t ret = _Z_RES_OK; +z_result_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, const z_scout_options_t *options) { + z_result_t ret = _Z_RES_OK; void *ctx = callback->_this._val.context; callback->_this._val.context = NULL; @@ -930,7 +931,7 @@ int8_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, cons void z_open_options_default(z_open_options_t *options) { options->__dummy = 0; } -int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config, const z_open_options_t *options) { +z_result_t z_open(z_owned_session_t *zs, z_moved_config_t *config, const z_open_options_t *options) { _ZP_UNUSED(options); z_internal_session_null(zs); _z_session_t *s = z_malloc(sizeof(_z_session_t)); @@ -948,7 +949,7 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config, const z_open_opti } zs->_rc = zsrc; // Open session - int8_t ret = _z_open(&zs->_rc, &config->_this._val); + z_result_t ret = _z_open(&zs->_rc, &config->_this._val); if (ret != _Z_RES_OK) { _z_session_rc_decr(&zs->_rc); z_internal_session_null(zs); @@ -963,7 +964,7 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config, const z_open_opti void z_close_options_default(z_close_options_t *options) { options->__dummy = 0; } -int8_t z_close(z_moved_session_t *zs, const z_close_options_t *options) { +z_result_t z_close(z_moved_session_t *zs, const z_close_options_t *options) { _ZP_UNUSED(options); if (zs == NULL || !z_internal_session_check(&zs->_this)) { return _Z_RES_OK; @@ -972,7 +973,7 @@ int8_t z_close(z_moved_session_t *zs, const z_close_options_t *options) { return _Z_RES_OK; } -int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback) { +z_result_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback) { // Call transport function switch (_Z_RC_IN_VAL(zs)->_tp._type) { case _Z_TRANSPORT_MULTICAST_TYPE: @@ -993,7 +994,7 @@ int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *cal return 0; } -int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback) { +z_result_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback) { // Call transport function switch (_Z_RC_IN_VAL(zs)->_tp._type) { case _Z_TRANSPORT_UNICAST_TYPE: @@ -1051,7 +1052,7 @@ const z_loaned_encoding_t *z_reply_err_encoding(const z_loaned_reply_err_t *repl const char *z_string_data(const z_loaned_string_t *str) { return _z_string_data(str); } size_t z_string_len(const z_loaned_string_t *str) { return _z_string_len(str); } -int8_t z_string_copy_from_str(z_owned_string_t *str, const char *value) { +z_result_t z_string_copy_from_str(z_owned_string_t *str, const char *value) { str->_val = _z_string_copy_from_str(value); if (str->_val._slice.start == NULL && value != NULL) { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -1059,15 +1060,15 @@ int8_t z_string_copy_from_str(z_owned_string_t *str, const char *value) { return _Z_RES_OK; } -int8_t z_string_from_str(z_owned_string_t *str, char *value, void (*deleter)(void *value, void *context), - void *context) { +z_result_t z_string_from_str(z_owned_string_t *str, char *value, void (*deleter)(void *value, void *context), + void *context) { str->_val = _z_string_from_str_custom_deleter(value, _z_delete_context_create(deleter, context)); return _Z_RES_OK; } void z_string_empty(z_owned_string_t *str) { str->_val = _z_string_null(); } -int8_t z_string_copy_from_substr(z_owned_string_t *str, const char *value, size_t len) { +z_result_t z_string_copy_from_substr(z_owned_string_t *str, const char *value, size_t len) { str->_val = _z_string_copy_from_substr(value, len); return _Z_RES_OK; } @@ -1106,9 +1107,9 @@ void z_delete_options_default(z_delete_options_t *options) { #endif } -int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, - const z_put_options_t *options) { - int8_t ret = 0; +z_result_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, + const z_put_options_t *options) { + z_result_t ret = 0; z_put_options_t opt; z_put_options_default(&opt); @@ -1139,8 +1140,9 @@ int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_ return ret; } -int8_t z_delete(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const z_delete_options_t *options) { - int8_t ret = 0; +z_result_t z_delete(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, + const z_delete_options_t *options) { + z_result_t ret = 0; z_delete_options_t opt; z_delete_options_default(&opt); @@ -1168,8 +1170,8 @@ void z_publisher_options_default(z_publisher_options_t *options) { #endif } -int8_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, - const z_publisher_options_t *options) { +z_result_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *zs, + const z_loaned_keyexpr_t *keyexpr, const z_publisher_options_t *options) { _z_keyexpr_t keyexpr_aliased = _z_keyexpr_alias_from_user_defined(*keyexpr, true); _z_keyexpr_t key = keyexpr_aliased; @@ -1199,7 +1201,7 @@ int8_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *z _z_publisher_t int_pub = _z_declare_publisher(zs, key, opt.encoding == NULL ? NULL : &opt.encoding->_this._val, opt.congestion_control, opt.priority, opt.is_express, reliability); // Create write filter - int8_t res = _z_write_filter_create(&int_pub); + z_result_t res = _z_write_filter_create(&int_pub); if (res != _Z_RES_OK) { if (key._id != Z_RESOURCE_ID_NONE) { _z_undeclare_resource(_Z_RC_IN_VAL(zs), key._id); @@ -1210,8 +1212,8 @@ int8_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *z return _Z_RES_OK; } -int8_t z_undeclare_publisher(z_moved_publisher_t *pub) { - int8_t ret = _z_undeclare_publisher(&pub->_this._val); +z_result_t z_undeclare_publisher(z_moved_publisher_t *pub) { + z_result_t ret = _z_undeclare_publisher(&pub->_this._val); _z_publisher_clear(&pub->_this._val); return ret; } @@ -1224,9 +1226,9 @@ void z_publisher_put_options_default(z_publisher_put_options_t *options) { void z_publisher_delete_options_default(z_publisher_delete_options_t *options) { options->timestamp = NULL; } -int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t *payload, - const z_publisher_put_options_t *options) { - int8_t ret = 0; +z_result_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t *payload, + const z_publisher_put_options_t *options) { + z_result_t ret = 0; // Build options z_publisher_put_options_t opt; z_publisher_put_options_default(&opt); @@ -1275,7 +1277,7 @@ int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t *payload return ret; } -int8_t z_publisher_delete(const z_loaned_publisher_t *pub, const z_publisher_delete_options_t *options) { +z_result_t z_publisher_delete(const z_loaned_publisher_t *pub, const z_publisher_delete_options_t *options) { // Build options z_publisher_delete_options_t opt; z_publisher_delete_options_default(&opt); @@ -1294,9 +1296,9 @@ int8_t z_publisher_delete(const z_loaned_publisher_t *pub, const z_publisher_del if (_Z_RC_IS_NULL(&sess_rc)) { return _Z_ERR_SESSION_CLOSED; } - int8_t ret = _z_write(_Z_RC_IN_VAL(&sess_rc), pub_keyexpr, _z_bytes_null(), NULL, Z_SAMPLE_KIND_DELETE, - pub->_congestion_control, pub->_priority, pub->_is_express, opt.timestamp, _z_bytes_null(), - reliability); + z_result_t ret = _z_write(_Z_RC_IN_VAL(&sess_rc), pub_keyexpr, _z_bytes_null(), NULL, Z_SAMPLE_KIND_DELETE, + pub->_congestion_control, pub->_priority, pub->_is_express, opt.timestamp, + _z_bytes_null(), reliability); // Clean up _z_session_rc_drop(&sess_rc); return ret; @@ -1330,9 +1332,9 @@ void z_get_options_default(z_get_options_t *options) { options->timeout_ms = Z_GET_TIMEOUT_DEFAULT; } -int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const char *parameters, - z_moved_closure_reply_t *callback, z_get_options_t *options) { - int8_t ret = _Z_RES_OK; +z_result_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const char *parameters, + z_moved_closure_reply_t *callback, z_get_options_t *options) { + z_result_t ret = _Z_RES_OK; void *ctx = callback->_this._val.context; callback->_this._val.context = NULL; @@ -1402,9 +1404,9 @@ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_queryable_t, queryable, _z_queryable_ch void z_queryable_options_default(z_queryable_options_t *options) { options->complete = _Z_QUERYABLE_COMPLETE_DEFAULT; } -int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_session_t *zs, - const z_loaned_keyexpr_t *keyexpr, z_moved_closure_query_t *callback, - const z_queryable_options_t *options) { +z_result_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_session_t *zs, + const z_loaned_keyexpr_t *keyexpr, z_moved_closure_query_t *callback, + const z_queryable_options_t *options) { void *ctx = callback->_this._val.context; callback->_this._val.context = NULL; @@ -1435,8 +1437,8 @@ int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_sessio return _Z_RES_OK; } -int8_t z_undeclare_queryable(z_moved_queryable_t *queryable) { - int8_t ret = _z_undeclare_queryable(&queryable->_this._val); +z_result_t z_undeclare_queryable(z_moved_queryable_t *queryable) { + z_result_t ret = _z_undeclare_queryable(&queryable->_this._val); _z_queryable_clear(&queryable->_this._val); return ret; } @@ -1450,8 +1452,8 @@ void z_query_reply_options_default(z_query_reply_options_t *options) { options->attachment = NULL; } -int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, - const z_query_reply_options_t *options) { +z_result_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, + const z_query_reply_options_t *options) { // Try upgrading session weak to rc _z_session_rc_t sess_rc = _z_session_weak_upgrade(&_Z_RC_IN_VAL(query)->_zn); if (_Z_RC_IS_NULL(&sess_rc)) { @@ -1469,9 +1471,9 @@ int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *ke _z_value_t value = {.payload = _z_bytes_from_owned_bytes(&payload->_this), .encoding = _z_encoding_from_owned(&opts.encoding->_this)}; - int8_t ret = _z_send_reply(_Z_RC_IN_VAL(query), &sess_rc, keyexpr_aliased, value, Z_SAMPLE_KIND_PUT, - opts.congestion_control, opts.priority, opts.is_express, opts.timestamp, - _z_bytes_from_owned_bytes(&opts.attachment->_this)); + z_result_t ret = _z_send_reply(_Z_RC_IN_VAL(query), &sess_rc, keyexpr_aliased, value, Z_SAMPLE_KIND_PUT, + opts.congestion_control, opts.priority, opts.is_express, opts.timestamp, + _z_bytes_from_owned_bytes(&opts.attachment->_this)); z_bytes_drop(payload); // Clean-up _z_session_rc_drop(&sess_rc); @@ -1488,8 +1490,8 @@ void z_query_reply_del_options_default(z_query_reply_del_options_t *options) { options->attachment = NULL; } -int8_t z_query_reply_del(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, - const z_query_reply_del_options_t *options) { +z_result_t z_query_reply_del(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, + const z_query_reply_del_options_t *options) { // Try upgrading session weak to rc _z_session_rc_t sess_rc = _z_session_weak_upgrade(&_Z_RC_IN_VAL(query)->_zn); if (_Z_RC_IS_NULL(&sess_rc)) { @@ -1505,9 +1507,9 @@ int8_t z_query_reply_del(const z_loaned_query_t *query, const z_loaned_keyexpr_t _z_value_t value = {.payload = _z_bytes_null(), .encoding = _z_encoding_null()}; - int8_t ret = _z_send_reply(_Z_RC_IN_VAL(query), &sess_rc, keyexpr_aliased, value, Z_SAMPLE_KIND_DELETE, - opts.congestion_control, opts.priority, opts.is_express, opts.timestamp, - _z_bytes_from_owned_bytes(&opts.attachment->_this)); + z_result_t ret = _z_send_reply(_Z_RC_IN_VAL(query), &sess_rc, keyexpr_aliased, value, Z_SAMPLE_KIND_DELETE, + opts.congestion_control, opts.priority, opts.is_express, opts.timestamp, + _z_bytes_from_owned_bytes(&opts.attachment->_this)); // Clean-up _z_session_rc_drop(&sess_rc); z_bytes_drop(opts.attachment); @@ -1516,8 +1518,8 @@ int8_t z_query_reply_del(const z_loaned_query_t *query, const z_loaned_keyexpr_t void z_query_reply_err_options_default(z_query_reply_err_options_t *options) { options->encoding = NULL; } -int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t *payload, - const z_query_reply_err_options_t *options) { +z_result_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t *payload, + const z_query_reply_err_options_t *options) { // Try upgrading session weak to rc _z_session_rc_t sess_rc = _z_session_weak_upgrade(&_Z_RC_IN_VAL(query)->_zn); if (_Z_RC_IS_NULL(&sess_rc)) { @@ -1533,7 +1535,7 @@ int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t *payload _z_value_t value = {.payload = _z_bytes_from_owned_bytes(&payload->_this), .encoding = _z_encoding_from_owned(&opts.encoding->_this)}; - int8_t ret = _z_send_reply_err(_Z_RC_IN_VAL(query), &sess_rc, value); + z_result_t ret = _z_send_reply_err(_Z_RC_IN_VAL(query), &sess_rc, value); _z_session_rc_drop(&sess_rc); z_bytes_drop(payload); // Clean-up @@ -1542,12 +1544,12 @@ int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t *payload } #endif -int8_t z_keyexpr_from_str_autocanonize(z_owned_keyexpr_t *key, const char *name) { +z_result_t z_keyexpr_from_str_autocanonize(z_owned_keyexpr_t *key, const char *name) { size_t len = strlen(name); return z_keyexpr_from_substr_autocanonize(key, name, &len); } -int8_t z_keyexpr_from_substr_autocanonize(z_owned_keyexpr_t *key, const char *name, size_t *len) { +z_result_t z_keyexpr_from_substr_autocanonize(z_owned_keyexpr_t *key, const char *name, size_t *len) { z_internal_keyexpr_null(key); // Copy the suffix @@ -1564,11 +1566,11 @@ int8_t z_keyexpr_from_substr_autocanonize(z_owned_keyexpr_t *key, const char *na return _Z_RES_OK; } -int8_t z_keyexpr_from_str(z_owned_keyexpr_t *key, const char *name) { +z_result_t z_keyexpr_from_str(z_owned_keyexpr_t *key, const char *name) { return z_keyexpr_from_substr(key, name, strlen(name)); } -int8_t z_keyexpr_from_substr(z_owned_keyexpr_t *key, const char *name, size_t len) { +z_result_t z_keyexpr_from_substr(z_owned_keyexpr_t *key, const char *name, size_t len) { z_internal_keyexpr_null(key); key->_val._suffix = _z_string_preallocate(len); if (!_z_keyexpr_has_suffix(&key->_val)) { @@ -1578,7 +1580,7 @@ int8_t z_keyexpr_from_substr(z_owned_keyexpr_t *key, const char *name, size_t le return _Z_RES_OK; } -int8_t z_declare_keyexpr(z_owned_keyexpr_t *key, const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr) { +z_result_t z_declare_keyexpr(z_owned_keyexpr_t *key, const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr) { _z_keyexpr_t k = _z_keyexpr_alias_from_user_defined(*keyexpr, false); uint16_t id = _z_declare_resource(_Z_RC_IN_VAL(zs), k); key->_val = _z_rid_with_suffix(id, NULL); @@ -1593,8 +1595,8 @@ int8_t z_declare_keyexpr(z_owned_keyexpr_t *key, const z_loaned_session_t *zs, c return _Z_RES_OK; } -int8_t z_undeclare_keyexpr(z_moved_keyexpr_t *keyexpr, const z_loaned_session_t *zs) { - int8_t ret = _Z_RES_OK; +z_result_t z_undeclare_keyexpr(z_moved_keyexpr_t *keyexpr, const z_loaned_session_t *zs) { + z_result_t ret = _Z_RES_OK; ret = _z_undeclare_resource(_Z_RC_IN_VAL(zs), keyexpr->_this._val._id); z_keyexpr_drop(keyexpr); @@ -1610,8 +1612,9 @@ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_subscriber_t, subscriber, _z_subscriber void z_subscriber_options_default(z_subscriber_options_t *options) { options->__dummy = 0; } -int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, - z_moved_closure_sample_t *callback, const z_subscriber_options_t *options) { +z_result_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t *zs, + const z_loaned_keyexpr_t *keyexpr, z_moved_closure_sample_t *callback, + const z_subscriber_options_t *options) { _ZP_UNUSED(options); void *ctx = callback->_this._val.context; callback->_this._val.context = NULL; @@ -1660,8 +1663,8 @@ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t } } -int8_t z_undeclare_subscriber(z_moved_subscriber_t *sub) { - int8_t ret = _z_undeclare_subscriber(&sub->_this._val); +z_result_t z_undeclare_subscriber(z_moved_subscriber_t *sub) { + z_result_t ret = _z_undeclare_subscriber(&sub->_this._val); _z_subscriber_clear(&sub->_this._val); return ret; } @@ -1690,7 +1693,7 @@ void zp_task_read_options_default(zp_task_read_options_t *options) { #endif } -int8_t zp_start_read_task(z_loaned_session_t *zs, const zp_task_read_options_t *options) { +z_result_t zp_start_read_task(z_loaned_session_t *zs, const zp_task_read_options_t *options) { (void)(options); #if Z_FEATURE_MULTI_THREAD == 1 zp_task_read_options_t opt; @@ -1705,7 +1708,7 @@ int8_t zp_start_read_task(z_loaned_session_t *zs, const zp_task_read_options_t * #endif } -int8_t zp_stop_read_task(z_loaned_session_t *zs) { +z_result_t zp_stop_read_task(z_loaned_session_t *zs) { #if Z_FEATURE_MULTI_THREAD == 1 return _zp_stop_read_task(_Z_RC_IN_VAL(zs)); #else @@ -1722,7 +1725,7 @@ void zp_task_lease_options_default(zp_task_lease_options_t *options) { #endif } -int8_t zp_start_lease_task(z_loaned_session_t *zs, const zp_task_lease_options_t *options) { +z_result_t zp_start_lease_task(z_loaned_session_t *zs, const zp_task_lease_options_t *options) { (void)(options); #if Z_FEATURE_MULTI_THREAD == 1 zp_task_lease_options_t opt; @@ -1737,7 +1740,7 @@ int8_t zp_start_lease_task(z_loaned_session_t *zs, const zp_task_lease_options_t #endif } -int8_t zp_stop_lease_task(z_loaned_session_t *zs) { +z_result_t zp_stop_lease_task(z_loaned_session_t *zs) { #if Z_FEATURE_MULTI_THREAD == 1 return _zp_stop_lease_task(_Z_RC_IN_VAL(zs)); #else @@ -1748,21 +1751,21 @@ int8_t zp_stop_lease_task(z_loaned_session_t *zs) { void zp_read_options_default(zp_read_options_t *options) { options->__dummy = 0; } -int8_t zp_read(const z_loaned_session_t *zs, const zp_read_options_t *options) { +z_result_t zp_read(const z_loaned_session_t *zs, const zp_read_options_t *options) { (void)(options); return _zp_read(_Z_RC_IN_VAL(zs)); } void zp_send_keep_alive_options_default(zp_send_keep_alive_options_t *options) { options->__dummy = 0; } -int8_t zp_send_keep_alive(const z_loaned_session_t *zs, const zp_send_keep_alive_options_t *options) { +z_result_t zp_send_keep_alive(const z_loaned_session_t *zs, const zp_send_keep_alive_options_t *options) { (void)(options); return _zp_send_keep_alive(_Z_RC_IN_VAL(zs)); } void zp_send_join_options_default(zp_send_join_options_t *options) { options->__dummy = 0; } -int8_t zp_send_join(const z_loaned_session_t *zs, const zp_send_join_options_t *options) { +z_result_t zp_send_join(const z_loaned_session_t *zs, const zp_send_join_options_t *options) { (void)(options); return _zp_send_join(_Z_RC_IN_VAL(zs)); } diff --git a/src/collections/arc_slice.c b/src/collections/arc_slice.c index cb89e3c15..01f7d8038 100644 --- a/src/collections/arc_slice.c +++ b/src/collections/arc_slice.c @@ -60,14 +60,14 @@ bool _z_arc_slice_is_empty(const _z_arc_slice_t* s) { return _z_arc_slice_len(s) const uint8_t* _z_arc_slice_data(const _z_arc_slice_t* s) { return _Z_RC_IN_VAL(&s->slice)->start + s->start; } -int8_t _z_arc_slice_copy(_z_arc_slice_t* dst, const _z_arc_slice_t* src) { +z_result_t _z_arc_slice_copy(_z_arc_slice_t* dst, const _z_arc_slice_t* src) { _z_slice_rc_copy(&dst->slice, &src->slice); dst->len = src->len; dst->start = src->start; return _Z_RES_OK; } -int8_t _z_arc_slice_move(_z_arc_slice_t* dst, _z_arc_slice_t* src) { +z_result_t _z_arc_slice_move(_z_arc_slice_t* dst, _z_arc_slice_t* src) { dst->slice = src->slice; dst->len = src->len; dst->start = src->start; @@ -77,7 +77,7 @@ int8_t _z_arc_slice_move(_z_arc_slice_t* dst, _z_arc_slice_t* src) { return _Z_RES_OK; } -int8_t _z_arc_slice_drop(_z_arc_slice_t* s) { +z_result_t _z_arc_slice_drop(_z_arc_slice_t* s) { _z_slice_rc_drop(&s->slice); *s = _z_arc_slice_empty(); return _Z_RES_OK; diff --git a/src/collections/bytes.c b/src/collections/bytes.c index 9b9b0d355..418c8f873 100644 --- a/src/collections/bytes.c +++ b/src/collections/bytes.c @@ -33,7 +33,7 @@ _z_bytes_t _z_bytes_null(void) { return b; } -int8_t _z_bytes_copy(_z_bytes_t *dst, const _z_bytes_t *src) { +z_result_t _z_bytes_copy(_z_bytes_t *dst, const _z_bytes_t *src) { _z_arc_slice_svec_copy(&dst->_slices, &src->_slices); if (_z_arc_slice_svec_len(&dst->_slices) == _z_arc_slice_svec_len(&src->_slices)) { return _Z_RES_OK; @@ -100,21 +100,21 @@ size_t _z_bytes_to_buf(const _z_bytes_t *bytes, uint8_t *dst, size_t len) { return len - remaining; } -int8_t _z_bytes_from_slice(_z_bytes_t *b, _z_slice_t s) { +z_result_t _z_bytes_from_slice(_z_bytes_t *b, _z_slice_t s) { *b = _z_bytes_null(); _z_arc_slice_t arc_s = _z_arc_slice_wrap(s, 0, s.len); if (_z_arc_slice_len(&arc_s) != s.len) return _Z_ERR_SYSTEM_OUT_OF_MEMORY; return _z_arc_slice_svec_append(&b->_slices, &arc_s) ? _Z_RES_OK : _Z_ERR_SYSTEM_OUT_OF_MEMORY; } -int8_t _z_bytes_from_buf(_z_bytes_t *b, const uint8_t *src, size_t len) { +z_result_t _z_bytes_from_buf(_z_bytes_t *b, const uint8_t *src, size_t len) { *b = _z_bytes_null(); _z_slice_t s = _z_slice_copy_from_buf(src, len); if (s.len != len) return _Z_ERR_SYSTEM_OUT_OF_MEMORY; return _z_bytes_from_slice(b, s); } -int8_t _z_bytes_to_slice(const _z_bytes_t *bytes, _z_slice_t *s) { +z_result_t _z_bytes_to_slice(const _z_bytes_t *bytes, _z_slice_t *s) { // Allocate slice size_t len = _z_bytes_len(bytes); *s = _z_slice_make(len); @@ -133,14 +133,14 @@ int8_t _z_bytes_to_slice(const _z_bytes_t *bytes, _z_slice_t *s) { return _Z_RES_OK; } -int8_t _z_bytes_append_slice(_z_bytes_t *dst, _z_arc_slice_t *s) { +z_result_t _z_bytes_append_slice(_z_bytes_t *dst, _z_arc_slice_t *s) { _Z_CLEAN_RETURN_IF_ERR(_z_arc_slice_svec_append(&dst->_slices, s) ? _Z_RES_OK : _Z_ERR_SYSTEM_OUT_OF_MEMORY, _z_arc_slice_drop(s)); return _Z_RES_OK; } -int8_t _z_bytes_append_bytes(_z_bytes_t *dst, _z_bytes_t *src) { - int8_t res = _Z_RES_OK; +z_result_t _z_bytes_append_bytes(_z_bytes_t *dst, _z_bytes_t *src) { + z_result_t res = _Z_RES_OK; for (size_t i = 0; i < _z_bytes_num_slices(src); ++i) { _z_arc_slice_t s; _z_arc_slice_move(&s, _z_bytes_get_slice(src, i)); @@ -154,7 +154,7 @@ int8_t _z_bytes_append_bytes(_z_bytes_t *dst, _z_bytes_t *src) { return res; } -int8_t _z_bytes_from_pair(_z_bytes_t *out, _z_bytes_t *first, _z_bytes_t *second) { +z_result_t _z_bytes_from_pair(_z_bytes_t *out, _z_bytes_t *first, _z_bytes_t *second) { *out = _z_bytes_null(); _z_bytes_iterator_writer_t writer = _z_bytes_get_iterator_writer(out, 0); _Z_CLEAN_RETURN_IF_ERR(_z_bytes_iterator_writer_write(&writer, first), _z_bytes_drop(second)); @@ -163,9 +163,9 @@ int8_t _z_bytes_from_pair(_z_bytes_t *out, _z_bytes_t *first, _z_bytes_t *second return _Z_RES_OK; } -int8_t _z_bytes_deserialize_into_pair(const _z_bytes_t *bs, _z_bytes_t *first_out, _z_bytes_t *second_out) { +z_result_t _z_bytes_deserialize_into_pair(const _z_bytes_t *bs, _z_bytes_t *first_out, _z_bytes_t *second_out) { _z_bytes_iterator_t iter = _z_bytes_get_iterator(bs); - int8_t res = _z_bytes_iterator_next(&iter, first_out); + z_result_t res = _z_bytes_iterator_next(&iter, first_out); if (res != _Z_RES_OK) return res; res = _z_bytes_iterator_next(&iter, second_out); if (res != _Z_RES_OK) { @@ -174,12 +174,12 @@ int8_t _z_bytes_deserialize_into_pair(const _z_bytes_t *bs, _z_bytes_t *first_ou return res; } -int8_t _z_bytes_to_uint8(const _z_bytes_t *bs, uint8_t *val) { +z_result_t _z_bytes_to_uint8(const _z_bytes_t *bs, uint8_t *val) { *val = 0; return _z_bytes_to_buf(bs, val, sizeof(uint8_t)) == sizeof(uint8_t) ? _Z_RES_OK : _Z_ERR_DID_NOT_READ; } -int8_t _z_bytes_to_uint16(const _z_bytes_t *bs, uint16_t *val) { +z_result_t _z_bytes_to_uint16(const _z_bytes_t *bs, uint16_t *val) { *val = 0; uint8_t buf[sizeof(uint16_t)] = {0}; if (_z_bytes_to_buf(bs, buf, sizeof(uint16_t)) == 0) { @@ -189,7 +189,7 @@ int8_t _z_bytes_to_uint16(const _z_bytes_t *bs, uint16_t *val) { return _Z_RES_OK; } -int8_t _z_bytes_to_uint32(const _z_bytes_t *bs, uint32_t *val) { +z_result_t _z_bytes_to_uint32(const _z_bytes_t *bs, uint32_t *val) { *val = 0; uint8_t buf[sizeof(uint32_t)] = {0}; if (_z_bytes_to_buf(bs, buf, sizeof(uint32_t)) == 0) { @@ -199,7 +199,7 @@ int8_t _z_bytes_to_uint32(const _z_bytes_t *bs, uint32_t *val) { return _Z_RES_OK; } -int8_t _z_bytes_to_uint64(const _z_bytes_t *bs, uint64_t *val) { +z_result_t _z_bytes_to_uint64(const _z_bytes_t *bs, uint64_t *val) { *val = 0; uint8_t buf[sizeof(uint64_t)] = {0}; if (_z_bytes_to_buf(bs, buf, sizeof(uint64_t)) == 0) { @@ -209,39 +209,41 @@ int8_t _z_bytes_to_uint64(const _z_bytes_t *bs, uint64_t *val) { return _Z_RES_OK; } -int8_t _z_bytes_to_float(const _z_bytes_t *bs, float *val) { +z_result_t _z_bytes_to_float(const _z_bytes_t *bs, float *val) { *val = 0; return _z_bytes_to_buf(bs, (uint8_t *)val, sizeof(float)) == sizeof(float) ? _Z_RES_OK : _Z_ERR_DID_NOT_READ; } -int8_t _z_bytes_to_double(const _z_bytes_t *bs, double *val) { +z_result_t _z_bytes_to_double(const _z_bytes_t *bs, double *val) { *val = 0; return _z_bytes_to_buf(bs, (uint8_t *)val, sizeof(double)) == sizeof(double) ? _Z_RES_OK : _Z_ERR_DID_NOT_READ; } -int8_t _z_bytes_from_uint8(_z_bytes_t *b, uint8_t val) { return _z_bytes_from_buf(b, &val, sizeof(val)); } +z_result_t _z_bytes_from_uint8(_z_bytes_t *b, uint8_t val) { return _z_bytes_from_buf(b, &val, sizeof(val)); } -int8_t _z_bytes_from_uint16(_z_bytes_t *b, uint16_t val) { +z_result_t _z_bytes_from_uint16(_z_bytes_t *b, uint16_t val) { uint8_t buf[sizeof(uint16_t)]; size_t len = _z_host_le_store16(val, buf); return _z_bytes_from_buf(b, buf, len); } -int8_t _z_bytes_from_uint32(_z_bytes_t *b, uint32_t val) { +z_result_t _z_bytes_from_uint32(_z_bytes_t *b, uint32_t val) { uint8_t buf[sizeof(uint32_t)]; size_t len = _z_host_le_store32(val, buf); return _z_bytes_from_buf(b, buf, len); } -int8_t _z_bytes_from_uint64(_z_bytes_t *b, uint64_t val) { +z_result_t _z_bytes_from_uint64(_z_bytes_t *b, uint64_t val) { uint8_t buf[sizeof(uint64_t)]; size_t len = _z_host_le_store64(val, buf); return _z_bytes_from_buf(b, buf, len); } -int8_t _z_bytes_from_float(_z_bytes_t *b, float val) { return _z_bytes_from_buf(b, (uint8_t *)&val, sizeof(val)); } +z_result_t _z_bytes_from_float(_z_bytes_t *b, float val) { return _z_bytes_from_buf(b, (uint8_t *)&val, sizeof(val)); } -int8_t _z_bytes_from_double(_z_bytes_t *b, double val) { return _z_bytes_from_buf(b, (uint8_t *)&val, sizeof(val)); } +z_result_t _z_bytes_from_double(_z_bytes_t *b, double val) { + return _z_bytes_from_buf(b, (uint8_t *)&val, sizeof(val)); +} _z_slice_t _z_bytes_try_get_contiguous(const _z_bytes_t *bs) { if (_z_bytes_num_slices(bs) == 1) { @@ -265,7 +267,7 @@ _z_bytes_reader_t _z_bytes_get_reader(const _z_bytes_t *bytes) { return r; } -int8_t _z_bytes_reader_seek_forward(_z_bytes_reader_t *reader, size_t offset) { +z_result_t _z_bytes_reader_seek_forward(_z_bytes_reader_t *reader, size_t offset) { size_t start_slice = reader->slice_idx; for (size_t i = start_slice; i < _z_bytes_num_slices(reader->bytes); ++i) { _z_arc_slice_t *s = _z_bytes_get_slice(reader->bytes, i); @@ -287,7 +289,7 @@ int8_t _z_bytes_reader_seek_forward(_z_bytes_reader_t *reader, size_t offset) { return _Z_RES_OK; } -int8_t _z_bytes_reader_seek_backward(_z_bytes_reader_t *reader, size_t offset) { +z_result_t _z_bytes_reader_seek_backward(_z_bytes_reader_t *reader, size_t offset) { while (offset != 0) { if (reader->in_slice_idx == 0) { if (reader->slice_idx == 0) return _Z_ERR_DID_NOT_READ; @@ -309,7 +311,7 @@ int8_t _z_bytes_reader_seek_backward(_z_bytes_reader_t *reader, size_t offset) { return _Z_RES_OK; } -int8_t _z_bytes_reader_seek(_z_bytes_reader_t *reader, int64_t offset, int origin) { +z_result_t _z_bytes_reader_seek(_z_bytes_reader_t *reader, int64_t offset, int origin) { switch (origin) { case SEEK_SET: { reader->byte_idx = 0; @@ -365,18 +367,18 @@ size_t _z_bytes_reader_read(_z_bytes_reader_t *reader, uint8_t *buf, size_t len) return to_read - len; } -int8_t __read_single_byte(uint8_t *b, void *context) { +z_result_t __read_single_byte(uint8_t *b, void *context) { _z_bytes_reader_t *reader = (_z_bytes_reader_t *)context; return _z_bytes_reader_read(reader, b, 1) == 1 ? _Z_RES_OK : _Z_ERR_DID_NOT_READ; } -int8_t _z_bytes_reader_read_zint(_z_bytes_reader_t *reader, _z_zint_t *zint) { +z_result_t _z_bytes_reader_read_zint(_z_bytes_reader_t *reader, _z_zint_t *zint) { return _z_zsize_decode_with_reader(zint, __read_single_byte, reader); } -int8_t _z_bytes_reader_read_slices(_z_bytes_reader_t *reader, size_t len, _z_bytes_t *out) { +z_result_t _z_bytes_reader_read_slices(_z_bytes_reader_t *reader, size_t len, _z_bytes_t *out) { *out = _z_bytes_null(); - int8_t res = _Z_RES_OK; + z_result_t res = _Z_RES_OK; for (size_t i = reader->slice_idx; i < _z_bytes_num_slices(reader->bytes) && len > 0; ++i) { _z_arc_slice_t *s = _z_bytes_get_slice(reader->bytes, i); @@ -415,7 +417,7 @@ _z_bytes_iterator_t _z_bytes_get_iterator(const _z_bytes_t *bytes) { return (_z_bytes_iterator_t){._reader = _z_bytes_get_reader(bytes)}; } -int8_t _z_bytes_iterator_next(_z_bytes_iterator_t *iter, _z_bytes_t *b) { +z_result_t _z_bytes_iterator_next(_z_bytes_iterator_t *iter, _z_bytes_t *b) { *b = _z_bytes_null(); _z_zint_t len; if (_z_bytes_reader_read_zint(&iter->_reader, &len) != _Z_RES_OK) { @@ -428,7 +430,7 @@ _z_bytes_writer_t _z_bytes_get_writer(_z_bytes_t *bytes, size_t cache_size) { return (_z_bytes_writer_t){.cache = NULL, .cache_size = cache_size, .bytes = bytes}; } -int8_t _z_bytes_writer_ensure_cache(_z_bytes_writer_t *writer) { +z_result_t _z_bytes_writer_ensure_cache(_z_bytes_writer_t *writer) { // first we check if cache stayed untouched since previous write operation if (writer->cache != NULL) { _z_arc_slice_t *arc_s = _z_bytes_get_slice(writer->bytes, _z_bytes_num_slices(writer->bytes) - 1); @@ -451,7 +453,7 @@ int8_t _z_bytes_writer_ensure_cache(_z_bytes_writer_t *writer) { return _Z_RES_OK; } -int8_t _z_bytes_writer_write_all(_z_bytes_writer_t *writer, const uint8_t *src, size_t len) { +z_result_t _z_bytes_writer_write_all(_z_bytes_writer_t *writer, const uint8_t *src, size_t len) { if (writer->cache_size == 0) { // no cache - append data as a single slice _z_slice_t s = _z_slice_copy_from_buf(src, len); if (s.len != len) return _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -477,7 +479,7 @@ int8_t _z_bytes_writer_write_all(_z_bytes_writer_t *writer, const uint8_t *src, return _Z_RES_OK; } -int8_t _z_bytes_writer_append(_z_bytes_writer_t *writer, _z_bytes_t *src) { +z_result_t _z_bytes_writer_append(_z_bytes_writer_t *writer, _z_bytes_t *src) { _Z_CLEAN_RETURN_IF_ERR(_z_bytes_append_bytes(writer->bytes, src), _z_bytes_drop(src)); writer->cache = NULL; return _Z_RES_OK; @@ -487,7 +489,7 @@ _z_bytes_iterator_writer_t _z_bytes_get_iterator_writer(_z_bytes_t *bytes, size_ return (_z_bytes_iterator_writer_t){.writer = _z_bytes_get_writer(bytes, cache_size)}; } -int8_t _z_bytes_iterator_writer_write(_z_bytes_iterator_writer_t *writer, _z_bytes_t *src) { +z_result_t _z_bytes_iterator_writer_write(_z_bytes_iterator_writer_t *writer, _z_bytes_t *src) { uint8_t l_buf[16]; size_t l_len = _z_zsize_encode_buf(l_buf, _z_bytes_len(src)); _Z_CLEAN_RETURN_IF_ERR(_z_bytes_writer_write_all(&writer->writer, l_buf, l_len), _z_bytes_drop(src)); diff --git a/src/collections/fifo.c b/src/collections/fifo.c index 914cf2752..54e27fd3c 100644 --- a/src/collections/fifo.c +++ b/src/collections/fifo.c @@ -18,7 +18,7 @@ #include /*-------- fifo --------*/ -int8_t _z_fifo_init(_z_fifo_t *r, size_t capacity) { +z_result_t _z_fifo_init(_z_fifo_t *r, size_t capacity) { _z_ring_init(&r->_ring, capacity); return 0; } diff --git a/src/collections/fifo_mt.c b/src/collections/fifo_mt.c index a7377d91c..e8d735f94 100644 --- a/src/collections/fifo_mt.c +++ b/src/collections/fifo_mt.c @@ -19,7 +19,7 @@ #include "zenoh-pico/utils/logging.h" /*-------- Fifo Buffer Multithreaded --------*/ -int8_t _z_fifo_mt_init(_z_fifo_mt_t *fifo, size_t capacity) { +z_result_t _z_fifo_mt_init(_z_fifo_mt_t *fifo, size_t capacity) { _Z_RETURN_IF_ERR(_z_fifo_init(&fifo->_fifo, capacity)) fifo->is_closed = false; @@ -39,7 +39,7 @@ _z_fifo_mt_t *_z_fifo_mt_new(size_t capacity) { return NULL; } - int8_t ret = _z_fifo_mt_init(fifo, capacity); + z_result_t ret = _z_fifo_mt_init(fifo, capacity); if (ret != _Z_RES_OK) { _Z_ERROR("_z_fifo_mt_init failed: %i", ret); z_free(fifo); @@ -64,7 +64,7 @@ void _z_fifo_mt_free(_z_fifo_mt_t *fifo, z_element_free_f free_f) { z_free(fifo); } -int8_t _z_fifo_mt_push(const void *elem, void *context, z_element_free_f element_free) { +z_result_t _z_fifo_mt_push(const void *elem, void *context, z_element_free_f element_free) { _ZP_UNUSED(element_free); if (elem == NULL || context == NULL) { return _Z_ERR_GENERIC; @@ -90,7 +90,7 @@ int8_t _z_fifo_mt_push(const void *elem, void *context, z_element_free_f element return _Z_RES_OK; } -int8_t _z_fifo_mt_close(_z_fifo_mt_t *fifo) { +z_result_t _z_fifo_mt_close(_z_fifo_mt_t *fifo) { #if Z_FEATURE_MULTI_THREAD == 1 _Z_RETURN_IF_ERR(_z_mutex_lock(&fifo->_mutex)) fifo->is_closed = true; @@ -102,7 +102,7 @@ int8_t _z_fifo_mt_close(_z_fifo_mt_t *fifo) { return _Z_RES_OK; } -int8_t _z_fifo_mt_pull(void *dst, void *context, z_element_move_f element_move) { +z_result_t _z_fifo_mt_pull(void *dst, void *context, z_element_move_f element_move) { _z_fifo_mt_t *f = (_z_fifo_mt_t *)context; #if Z_FEATURE_MULTI_THREAD == 1 @@ -132,7 +132,7 @@ int8_t _z_fifo_mt_pull(void *dst, void *context, z_element_move_f element_move) return _Z_RES_OK; } -int8_t _z_fifo_mt_try_pull(void *dst, void *context, z_element_move_f element_move) { +z_result_t _z_fifo_mt_try_pull(void *dst, void *context, z_element_move_f element_move) { _z_fifo_mt_t *f = (_z_fifo_mt_t *)context; #if Z_FEATURE_MULTI_THREAD == 1 diff --git a/src/collections/intmap.c b/src/collections/intmap.c index ff903fb69..004e61bdd 100644 --- a/src/collections/intmap.c +++ b/src/collections/intmap.c @@ -50,7 +50,7 @@ size_t _z_int_void_map_len(const _z_int_void_map_t *map) { return len; } -int8_t _z_int_void_map_copy(_z_int_void_map_t *dst, const _z_int_void_map_t *src, z_element_clone_f f_c) { +z_result_t _z_int_void_map_copy(_z_int_void_map_t *dst, const _z_int_void_map_t *src, z_element_clone_f f_c) { assert((dst != NULL) && (src != NULL) && (dst->_capacity == src->_capacity)); for (size_t idx = 0; idx < src->_capacity; idx++) { const _z_list_t *src_list = src->_vals[idx]; diff --git a/src/collections/lifo.c b/src/collections/lifo.c index 8b43a2f68..a4e6a1bb6 100644 --- a/src/collections/lifo.c +++ b/src/collections/lifo.c @@ -18,7 +18,7 @@ #include /*-------- lifo --------*/ -int8_t _z_lifo_init(_z_lifo_t *r, size_t capacity) { +z_result_t _z_lifo_init(_z_lifo_t *r, size_t capacity) { memset(r, 0, sizeof(_z_lifo_t)); if (capacity != (size_t)0) { r->_val = (void **)z_malloc(sizeof(void *) * capacity); diff --git a/src/collections/refcount.c b/src/collections/refcount.c index 2d5c5c741..608548fae 100644 --- a/src/collections/refcount.c +++ b/src/collections/refcount.c @@ -63,7 +63,7 @@ #define _ZP_RC_OP_CHECK_STRONG_CNT(p, x) _z_atomic_compare_exchange_strong(&(p)->_strong_cnt, &x, x) #define _ZP_RC_OP_SYNC atomic_thread_fence(_z_memory_order_acquire); #define _ZP_RC_OP_UPGRADE_CAS_LOOP \ - int8_t _upgrade(_z_inner_rc_t* cnt) { \ + z_result_t _upgrade(_z_inner_rc_t* cnt) { \ unsigned int prev = _z_atomic_load_explicit(&cnt->_strong_cnt, _z_memory_order_relaxed); \ while ((prev != 0) && (prev < _Z_RC_MAX_COUNT)) { \ if (_z_atomic_compare_exchange_weak_explicit(&cnt->_strong_cnt, &prev, prev + 1, _z_memory_order_acquire, \ @@ -95,7 +95,7 @@ #define _ZP_RC_OP_CHECK_STRONG_CNT(p, x) __sync_bool_compare_and_swap(&(p)->_strong_cnt, x, x) #define _ZP_RC_OP_SYNC __sync_synchronize(); #define _ZP_RC_OP_UPGRADE_CAS_LOOP \ - int8_t _upgrade(_z_inner_rc_t* cnt) { \ + z_result_t _upgrade(_z_inner_rc_t* cnt) { \ unsigned int prev = __sync_fetch_and_add(&cnt->_strong_cnt, (unsigned int)0); \ while ((prev != 0) && (prev < _Z_RC_MAX_COUNT)) { \ if (__sync_bool_compare_and_swap(&cnt->_strong_cnt, prev, prev + 1)) { \ @@ -124,10 +124,10 @@ #define _ZP_RC_OP_DECR_AND_CMP_WEAK(p, x) (x == 0) #define _ZP_RC_OP_CHECK_STRONG_CNT(p, x) (x == 0) && (p != NULL) #define _ZP_RC_OP_SYNC -#define _ZP_RC_OP_UPGRADE_CAS_LOOP \ - int8_t _upgrade(_z_inner_rc_t* cnt) { \ - (void)cnt; \ - return _Z_ERR_INVALID; \ +#define _ZP_RC_OP_UPGRADE_CAS_LOOP \ + z_result_t _upgrade(_z_inner_rc_t* cnt) { \ + (void)cnt; \ + return _Z_ERR_INVALID; \ } #endif // ZENOH_COMPILER_GCC @@ -146,7 +146,7 @@ #define _ZP_RC_OP_CHECK_STRONG_CNT(p, x) (p->_strong_cnt == x) #define _ZP_RC_OP_SYNC #define _ZP_RC_OP_UPGRADE_CAS_LOOP \ - int8_t _upgrade(_z_inner_rc_t* cnt) { \ + z_result_t _upgrade(_z_inner_rc_t* cnt) { \ if ((cnt->_strong_cnt != 0) && (cnt->_strong_cnt < _Z_RC_MAX_COUNT)) { \ if (_ZP_RC_OP_INCR_AND_CMP_WEAK(cnt, _Z_RC_MAX_COUNT)) { \ _Z_ERROR("Rc weak count overflow"); \ @@ -165,7 +165,7 @@ typedef struct { _ZP_RC_CNT_TYPE _weak_cnt; } _z_inner_rc_t; -int8_t _z_rc_init(void** cnt) { +z_result_t _z_rc_init(void** cnt) { *cnt = z_malloc(sizeof(_z_inner_rc_t)); if ((*cnt) == NULL) { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -174,7 +174,7 @@ int8_t _z_rc_init(void** cnt) { return _Z_RES_OK; } -int8_t _z_rc_increase_strong(void* cnt) { +z_result_t _z_rc_increase_strong(void* cnt) { _z_inner_rc_t* c = (_z_inner_rc_t*)cnt; if (_ZP_RC_OP_INCR_AND_CMP_WEAK(c, _Z_RC_MAX_COUNT)) { _Z_ERROR("Rc weak count overflow"); @@ -184,7 +184,7 @@ int8_t _z_rc_increase_strong(void* cnt) { return _Z_RES_OK; } -int8_t _z_rc_increase_weak(void* cnt) { +z_result_t _z_rc_increase_weak(void* cnt) { _z_inner_rc_t* c = (_z_inner_rc_t*)cnt; if (_ZP_RC_OP_INCR_AND_CMP_WEAK(c, _Z_RC_MAX_COUNT)) { _Z_ERROR("Rc weak count overflow"); @@ -214,7 +214,7 @@ bool _z_rc_decrease_weak(void** cnt) { _ZP_RC_OP_UPGRADE_CAS_LOOP -int8_t _z_rc_weak_upgrade(void* cnt) { return _upgrade((_z_inner_rc_t*)cnt); } +z_result_t _z_rc_weak_upgrade(void* cnt) { return _upgrade((_z_inner_rc_t*)cnt); } size_t _z_rc_weak_count(void* cnt) { return ((_z_inner_rc_t*)cnt)->_weak_cnt; } diff --git a/src/collections/ring.c b/src/collections/ring.c index 66adb6c89..bd3061fcd 100644 --- a/src/collections/ring.c +++ b/src/collections/ring.c @@ -19,7 +19,7 @@ #include /*-------- ring --------*/ -int8_t _z_ring_init(_z_ring_t *r, size_t capacity) { +z_result_t _z_ring_init(_z_ring_t *r, size_t capacity) { // We need one more element to differentiate wether the ring is empty or full capacity++; diff --git a/src/collections/ring_mt.c b/src/collections/ring_mt.c index fdc9d7193..3749e8c3a 100644 --- a/src/collections/ring_mt.c +++ b/src/collections/ring_mt.c @@ -19,7 +19,7 @@ #include "zenoh-pico/utils/logging.h" /*-------- Ring Buffer Multithreaded --------*/ -int8_t _z_ring_mt_init(_z_ring_mt_t *ring, size_t capacity) { +z_result_t _z_ring_mt_init(_z_ring_mt_t *ring, size_t capacity) { _Z_RETURN_IF_ERR(_z_ring_init(&ring->_ring, capacity)) #if Z_FEATURE_MULTI_THREAD == 1 @@ -37,7 +37,7 @@ _z_ring_mt_t *_z_ring_mt_new(size_t capacity) { return NULL; } - int8_t ret = _z_ring_mt_init(ring, capacity); + z_result_t ret = _z_ring_mt_init(ring, capacity); if (ret != _Z_RES_OK) { _Z_ERROR("_z_ring_mt_init failed: %i", ret); return NULL; @@ -61,7 +61,7 @@ void _z_ring_mt_free(_z_ring_mt_t *ring, z_element_free_f free_f) { z_free(ring); } -int8_t _z_ring_mt_push(const void *elem, void *context, z_element_free_f element_free) { +z_result_t _z_ring_mt_push(const void *elem, void *context, z_element_free_f element_free) { if (elem == NULL || context == NULL) { return _Z_ERR_GENERIC; } @@ -81,7 +81,7 @@ int8_t _z_ring_mt_push(const void *elem, void *context, z_element_free_f element return _Z_RES_OK; } -int8_t _z_ring_mt_close(_z_ring_mt_t *ring) { +z_result_t _z_ring_mt_close(_z_ring_mt_t *ring) { #if Z_FEATURE_MULTI_THREAD == 1 _Z_RETURN_IF_ERR(_z_mutex_lock(&ring->_mutex)) ring->is_closed = true; @@ -93,7 +93,7 @@ int8_t _z_ring_mt_close(_z_ring_mt_t *ring) { return _Z_RES_OK; } -int8_t _z_ring_mt_pull(void *dst, void *context, z_element_move_f element_move) { +z_result_t _z_ring_mt_pull(void *dst, void *context, z_element_move_f element_move) { _z_ring_mt_t *r = (_z_ring_mt_t *)context; #if Z_FEATURE_MULTI_THREAD == 1 @@ -119,7 +119,7 @@ int8_t _z_ring_mt_pull(void *dst, void *context, z_element_move_f element_move) return _Z_RES_OK; } -int8_t _z_ring_mt_try_pull(void *dst, void *context, z_element_move_f element_move) { +z_result_t _z_ring_mt_try_pull(void *dst, void *context, z_element_move_f element_move) { _z_ring_mt_t *r = (_z_ring_mt_t *)context; #if Z_FEATURE_MULTI_THREAD == 1 diff --git a/src/collections/slice.c b/src/collections/slice.c index 0a72f9e97..c6fe1171a 100644 --- a/src/collections/slice.c +++ b/src/collections/slice.c @@ -49,8 +49,8 @@ _z_slice_t _z_slice_empty(void) { return (_z_slice_t){.start = NULL, .len = 0, ._delete_context = _z_delete_context_null()}; } -int8_t _z_slice_init(_z_slice_t *bs, size_t capacity) { - int8_t ret = _Z_RES_OK; +z_result_t _z_slice_init(_z_slice_t *bs, size_t capacity) { + z_result_t ret = _Z_RES_OK; bs->start = capacity == 0 ? NULL : (uint8_t *)z_malloc(capacity); if (bs->start != NULL) { @@ -120,19 +120,19 @@ void _z_slice_free(_z_slice_t **bs) { } } -int8_t _z_slice_copy(_z_slice_t *dst, const _z_slice_t *src) { +z_result_t _z_slice_copy(_z_slice_t *dst, const _z_slice_t *src) { // Make sure dst slice is not init beforehand, or suffer memory leak - int8_t ret = _z_slice_init(dst, src->len); + z_result_t ret = _z_slice_init(dst, src->len); if (ret == _Z_RES_OK) { (void)memcpy((uint8_t *)dst->start, src->start, src->len); } return ret; } -int8_t _z_slice_n_copy(_z_slice_t *dst, const _z_slice_t *src, size_t offset, size_t len) { +z_result_t _z_slice_n_copy(_z_slice_t *dst, const _z_slice_t *src, size_t offset, size_t len) { assert(offset + len <= src->len); // Make sure dst slice is not init beforehand, or suffer memory leak - int8_t ret = _z_slice_init(dst, len); + z_result_t ret = _z_slice_init(dst, len); if (ret == _Z_RES_OK) { const uint8_t *start = _z_cptr_u8_offset(src->start, (ptrdiff_t)offset); (void)memcpy((uint8_t *)dst->start, start, len); diff --git a/src/collections/string.c b/src/collections/string.c index c46200965..753c7cad5 100644 --- a/src/collections/string.c +++ b/src/collections/string.c @@ -69,9 +69,11 @@ _z_string_t *_z_string_copy_from_str_as_ptr(const char *value) { size_t _z_string_len(const _z_string_t *s) { return s->_slice.len; } -int8_t _z_string_copy(_z_string_t *dst, const _z_string_t *src) { return _z_slice_copy(&dst->_slice, &src->_slice); } +z_result_t _z_string_copy(_z_string_t *dst, const _z_string_t *src) { + return _z_slice_copy(&dst->_slice, &src->_slice); +} -int8_t _z_string_copy_substring(_z_string_t *dst, const _z_string_t *src, size_t offset, size_t len) { +z_result_t _z_string_copy_substring(_z_string_t *dst, const _z_string_t *src, size_t offset, size_t len) { return _z_slice_n_copy(&dst->_slice, &src->_slice, offset, len); } diff --git a/src/link/config/bt.c b/src/link/config/bt.c index 0c633b7cc..93858c450 100644 --- a/src/link/config/bt.c +++ b/src/link/config/bt.c @@ -35,13 +35,13 @@ char *_z_bt_config_to_str(const _z_str_intmap_t *s) { return _z_str_intmap_to_str(s, BT_CONFIG_ARGC, args); } -int8_t _z_bt_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { +z_result_t _z_bt_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { BT_CONFIG_MAPPING_BUILD return _z_str_intmap_from_strn(strint, s, BT_CONFIG_ARGC, args, n); } -int8_t _z_bt_config_from_str(_z_str_intmap_t *strint, const char *s) { +z_result_t _z_bt_config_from_str(_z_str_intmap_t *strint, const char *s) { BT_CONFIG_MAPPING_BUILD return _z_str_intmap_from_str(strint, s, BT_CONFIG_ARGC, args); diff --git a/src/link/config/serial.c b/src/link/config/serial.c index 876174f79..0a5ba8ebb 100644 --- a/src/link/config/serial.c +++ b/src/link/config/serial.c @@ -36,13 +36,13 @@ char *_z_serial_config_to_str(const _z_str_intmap_t *s) { return _z_str_intmap_to_str(s, SERIAL_CONFIG_ARGC, args); } -int8_t _z_serial_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { +z_result_t _z_serial_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { SERIAL_CONFIG_MAPPING_BUILD return _z_str_intmap_from_strn(strint, s, SERIAL_CONFIG_ARGC, args, n); } -int8_t _z_serial_config_from_str(_z_str_intmap_t *strint, const char *s) { +z_result_t _z_serial_config_from_str(_z_str_intmap_t *strint, const char *s) { SERIAL_CONFIG_MAPPING_BUILD return _z_str_intmap_from_str(strint, s, SERIAL_CONFIG_ARGC, args); diff --git a/src/link/config/tcp.c b/src/link/config/tcp.c index 0da276204..31663123c 100644 --- a/src/link/config/tcp.c +++ b/src/link/config/tcp.c @@ -38,13 +38,13 @@ char *_z_tcp_config_to_str(const _z_str_intmap_t *s) { return _z_str_intmap_to_str(s, TCP_CONFIG_ARGC, args); } -int8_t _z_tcp_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { +z_result_t _z_tcp_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { TCP_CONFIG_MAPPING_BUILD return _z_str_intmap_from_strn(strint, s, TCP_CONFIG_ARGC, args, n); } -int8_t _z_tcp_config_from_str(_z_str_intmap_t *strint, const char *s) { +z_result_t _z_tcp_config_from_str(_z_str_intmap_t *strint, const char *s) { return _z_tcp_config_from_strn(strint, s, strlen(s)); } #endif diff --git a/src/link/config/udp.c b/src/link/config/udp.c index 3dc5f06c6..595db85ce 100644 --- a/src/link/config/udp.c +++ b/src/link/config/udp.c @@ -38,12 +38,12 @@ char *_z_udp_config_to_str(const _z_str_intmap_t *s) { return _z_str_intmap_to_str(s, UDP_CONFIG_ARGC, args); } -int8_t _z_udp_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { +z_result_t _z_udp_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { UDP_CONFIG_MAPPING_BUILD return _z_str_intmap_from_strn(strint, s, UDP_CONFIG_ARGC, args, n); } -int8_t _z_udp_config_from_str(_z_str_intmap_t *strint, const char *s) { +z_result_t _z_udp_config_from_str(_z_str_intmap_t *strint, const char *s) { return _z_udp_config_from_strn(strint, s, strlen(s)); } diff --git a/src/link/config/ws.c b/src/link/config/ws.c index dd4378e6a..438b12fba 100644 --- a/src/link/config/ws.c +++ b/src/link/config/ws.c @@ -37,13 +37,13 @@ char *_z_ws_config_to_str(const _z_str_intmap_t *s) { return _z_str_intmap_to_str(s, argc, args); } -int8_t _z_ws_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { +z_result_t _z_ws_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) { WS_CONFIG_MAPPING_BUILD return _z_str_intmap_from_strn(strint, s, argc, args, n); } -int8_t _z_ws_config_from_str(_z_str_intmap_t *strint, const char *s) { +z_result_t _z_ws_config_from_str(_z_str_intmap_t *strint, const char *s) { return _z_ws_config_from_strn(strint, s, strlen(s)); } #endif diff --git a/src/link/endpoint.c b/src/link/endpoint.c index 5c9f23f92..50d47444b 100644 --- a/src/link/endpoint.c +++ b/src/link/endpoint.c @@ -62,7 +62,7 @@ void _z_locator_free(_z_locator_t **lc) { } } -int8_t _z_locator_copy(_z_locator_t *dst, const _z_locator_t *src) { +z_result_t _z_locator_copy(_z_locator_t *dst, const _z_locator_t *src) { _Z_RETURN_IF_ERR(_z_string_copy(&dst->_protocol, &src->_protocol)); _Z_RETURN_IF_ERR(_z_string_copy(&dst->_address, &src->_address)); @@ -85,7 +85,7 @@ bool _z_locator_eq(const _z_locator_t *left, const _z_locator_t *right) { return res; } -static int8_t _z_locator_protocol_from_string(_z_string_t *protocol, _z_string_t *str) { +static z_result_t _z_locator_protocol_from_string(_z_string_t *protocol, _z_string_t *str) { *protocol = _z_string_null(); const char *p_start = _z_string_data(str); @@ -97,7 +97,7 @@ static int8_t _z_locator_protocol_from_string(_z_string_t *protocol, _z_string_t return _z_string_copy_substring(protocol, str, 0, p_len); } -static int8_t _z_locator_address_from_string(_z_string_t *address, _z_string_t *str) { +static z_result_t _z_locator_address_from_string(_z_string_t *address, _z_string_t *str) { *address = _z_string_null(); // Find protocol separator @@ -130,7 +130,7 @@ static int8_t _z_locator_address_from_string(_z_string_t *address, _z_string_t * return _z_string_copy_substring(address, str, start_offset, addr_len); } -int8_t _z_locator_metadata_from_string(_z_str_intmap_t *strint, _z_string_t *str) { +z_result_t _z_locator_metadata_from_string(_z_str_intmap_t *strint, _z_string_t *str) { *strint = _z_str_intmap_make(); // Find metadata separator @@ -169,7 +169,7 @@ void _z_locator_metadata_onto_str(char *dst, size_t dst_len, const _z_str_intmap _z_str_intmap_onto_str(dst, dst_len, s, 0, NULL); } -int8_t _z_locator_from_string(_z_locator_t *lc, _z_string_t *str) { +z_result_t _z_locator_from_string(_z_locator_t *lc, _z_string_t *str) { if (str == NULL || !_z_string_check(str)) { return _Z_ERR_CONFIG_LOCATOR_INVALID; } @@ -284,7 +284,7 @@ void _z_endpoint_free(_z_endpoint_t **ep) { } } -int8_t _z_endpoint_config_from_string(_z_str_intmap_t *strint, _z_string_t *str, _z_string_t *proto) { +z_result_t _z_endpoint_config_from_string(_z_str_intmap_t *strint, _z_string_t *str, _z_string_t *proto) { char *p_start = (char *)memchr(_z_string_data(str), ENDPOINT_CONFIG_SEPARATOR, _z_string_len(str)); if (p_start != NULL) { p_start = _z_ptr_char_offset(p_start, 1); @@ -410,7 +410,7 @@ char *_z_endpoint_config_to_string(const _z_str_intmap_t *s, const _z_string_t * return NULL; } -int8_t _z_endpoint_from_string(_z_endpoint_t *ep, _z_string_t *str) { +z_result_t _z_endpoint_from_string(_z_endpoint_t *ep, _z_string_t *str) { _z_endpoint_init(ep); _Z_CLEAN_RETURN_IF_ERR(_z_locator_from_string(&ep->_locator, str), _z_endpoint_clear(ep)); _Z_CLEAN_RETURN_IF_ERR(_z_endpoint_config_from_string(&ep->_config, str, &ep->_locator._protocol), diff --git a/src/link/link.c b/src/link/link.c index f15b5b69b..197d68212 100644 --- a/src/link/link.c +++ b/src/link/link.c @@ -21,8 +21,8 @@ #include "zenoh-pico/link/manager.h" #include "zenoh-pico/utils/logging.h" -int8_t _z_open_link(_z_link_t *zl, _z_string_t *locator) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_link(_z_link_t *zl, _z_string_t *locator) { + z_result_t ret = _Z_RES_OK; _z_endpoint_t ep; ret = _z_endpoint_from_string(&ep, locator); @@ -74,8 +74,8 @@ int8_t _z_open_link(_z_link_t *zl, _z_string_t *locator) { return ret; } -int8_t _z_listen_link(_z_link_t *zl, _z_string_t *locator) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_link(_z_link_t *zl, _z_string_t *locator) { + z_result_t ret = _Z_RES_OK; _z_endpoint_t ep; ret = _z_endpoint_from_string(&ep, locator); @@ -151,8 +151,8 @@ size_t _z_link_recv_exact_zbuf(const _z_link_t *link, _z_zbuf_t *zbf, size_t len return rb; } -int8_t _z_link_send_wbuf(const _z_link_t *link, const _z_wbuf_t *wbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_link_send_wbuf(const _z_link_t *link, const _z_wbuf_t *wbf) { + z_result_t ret = _Z_RES_OK; bool link_is_streamed = false; switch (link->_cap._flow) { diff --git a/src/link/multicast/bt.c b/src/link/multicast/bt.c index 8f6285eef..0b26d3643 100644 --- a/src/link/multicast/bt.c +++ b/src/link/multicast/bt.c @@ -25,8 +25,8 @@ #define SPP_MAXIMUM_PAYLOAD 128 -int8_t _z_endpoint_bt_valid(_z_endpoint_t *ep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_endpoint_bt_valid(_z_endpoint_t *ep) { + z_result_t ret = _Z_RES_OK; _z_string_t bt_str = _z_string_alias_str(BT_SCHEMA); if (!_z_string_equals(&ep->_locator._protocol, &bt_str)) { @@ -51,8 +51,8 @@ static char *__z_convert_address_bt(_z_string_t *address) { return ret; } -int8_t _z_f_link_open_bt(_z_link_t *self) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_open_bt(_z_link_t *self) { + z_result_t ret = _Z_RES_OK; const char *mode_str = _z_str_intmap_get(&self->_endpoint._config, BT_CONFIG_MODE_KEY); uint8_t mode = (strcmp(mode_str, "master") == 0) ? _Z_BT_MODE_MASTER : _Z_BT_MODE_SLAVE; @@ -70,8 +70,8 @@ int8_t _z_f_link_open_bt(_z_link_t *self) { return ret; } -int8_t _z_f_link_listen_bt(_z_link_t *self) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_listen_bt(_z_link_t *self) { + z_result_t ret = _Z_RES_OK; const char *mode_str = _z_str_intmap_get(&self->_endpoint._config, BT_CONFIG_MODE_KEY); uint8_t mode = (strcmp(mode_str, "master") == 0) ? _Z_BT_MODE_MASTER : _Z_BT_MODE_SLAVE; @@ -123,8 +123,8 @@ size_t _z_f_link_read_exact_bt(const _z_link_t *self, uint8_t *ptr, size_t len, uint16_t _z_get_link_mtu_bt(void) { return SPP_MAXIMUM_PAYLOAD; } -int8_t _z_new_link_bt(_z_link_t *zl, _z_endpoint_t endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_new_link_bt(_z_link_t *zl, _z_endpoint_t endpoint) { + z_result_t ret = _Z_RES_OK; zl->_cap._transport = Z_LINK_CAP_TRANSPORT_MULTICAST; zl->_cap._flow = Z_LINK_CAP_FLOW_STREAM; diff --git a/src/link/multicast/udp.c b/src/link/multicast/udp.c index 7169d0ac3..5968d34d0 100644 --- a/src/link/multicast/udp.c +++ b/src/link/multicast/udp.c @@ -80,8 +80,8 @@ static char *__z_parse_address_segment_udp_multicast(_z_string_t *address) { return ret; } -int8_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *endpoint) { + z_result_t ret = _Z_RES_OK; _z_string_t udp_str = _z_string_alias_str(UDP_SCHEMA); if (!_z_string_equals(&endpoint->_locator._protocol, &udp_str)) { @@ -118,8 +118,8 @@ int8_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *endpoint) { return ret; } -int8_t _z_f_link_open_udp_multicast(_z_link_t *self) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_open_udp_multicast(_z_link_t *self) { + z_result_t ret = _Z_RES_OK; uint32_t tout = Z_CONFIG_SOCKET_TIMEOUT; char *tout_as_str = _z_str_intmap_get(&self->_endpoint._config, UDP_CONFIG_TOUT_KEY); @@ -134,8 +134,8 @@ int8_t _z_f_link_open_udp_multicast(_z_link_t *self) { return ret; } -int8_t _z_f_link_listen_udp_multicast(_z_link_t *self) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_listen_udp_multicast(_z_link_t *self) { + z_result_t ret = _Z_RES_OK; const char *iface = _z_str_intmap_get(&self->_endpoint._config, UDP_CONFIG_IFACE_KEY); const char *join = _z_str_intmap_get(&self->_endpoint._config, UDP_CONFIG_JOIN_KEY); @@ -178,8 +178,8 @@ uint16_t _z_get_link_mtu_udp_multicast(void) { return 1450; } -int8_t _z_new_link_udp_multicast(_z_link_t *zl, _z_endpoint_t endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_new_link_udp_multicast(_z_link_t *zl, _z_endpoint_t endpoint) { + z_result_t ret = _Z_RES_OK; zl->_cap._transport = Z_LINK_CAP_TRANSPORT_MULTICAST; zl->_cap._flow = Z_LINK_CAP_FLOW_DATAGRAM; diff --git a/src/link/unicast/serial.c b/src/link/unicast/serial.c index 9f8f1d741..7cc16be15 100644 --- a/src/link/unicast/serial.c +++ b/src/link/unicast/serial.c @@ -27,8 +27,8 @@ #define SPP_MAXIMUM_PAYLOAD 128 -int8_t _z_endpoint_serial_valid(_z_endpoint_t *endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_endpoint_serial_valid(_z_endpoint_t *endpoint) { + z_result_t ret = _Z_RES_OK; _z_string_t ser_str = _z_string_alias_str(SERIAL_SCHEMA); if (!_z_string_equals(&endpoint->_locator._protocol, &ser_str)) { @@ -63,8 +63,8 @@ static char *__z_convert_address_serial(_z_string_t *address) { return ret; } -int8_t _z_f_link_open_serial(_z_link_t *self) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_open_serial(_z_link_t *self) { + z_result_t ret = _Z_RES_OK; const char *baudrate_str = _z_str_intmap_get(&self->_endpoint._config, SERIAL_CONFIG_BAUDRATE_KEY); uint32_t baudrate = (uint32_t)strtoul(baudrate_str, NULL, 10); @@ -83,8 +83,8 @@ int8_t _z_f_link_open_serial(_z_link_t *self) { return ret; } -int8_t _z_f_link_listen_serial(_z_link_t *self) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_listen_serial(_z_link_t *self) { + z_result_t ret = _Z_RES_OK; const char *baudrate_str = _z_str_intmap_get(&self->_endpoint._config, SERIAL_CONFIG_BAUDRATE_KEY); uint32_t baudrate = (uint32_t)strtoul(baudrate_str, NULL, 10); @@ -127,8 +127,8 @@ size_t _z_f_link_read_exact_serial(const _z_link_t *self, uint8_t *ptr, size_t l uint16_t _z_get_link_mtu_serial(void) { return _Z_SERIAL_MTU_SIZE; } -int8_t _z_new_link_serial(_z_link_t *zl, _z_endpoint_t endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_new_link_serial(_z_link_t *zl, _z_endpoint_t endpoint) { + z_result_t ret = _Z_RES_OK; zl->_cap._transport = Z_LINK_CAP_TRANSPORT_UNICAST; zl->_cap._flow = Z_LINK_CAP_FLOW_DATAGRAM; diff --git a/src/link/unicast/tcp.c b/src/link/unicast/tcp.c index 1d1038711..d55cf7c31 100644 --- a/src/link/unicast/tcp.c +++ b/src/link/unicast/tcp.c @@ -78,8 +78,8 @@ static char *__z_parse_address_segment_tcp(_z_string_t *address) { return ret; } -int8_t _z_endpoint_tcp_valid(_z_endpoint_t *endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_endpoint_tcp_valid(_z_endpoint_t *endpoint) { + z_result_t ret = _Z_RES_OK; _z_string_t tcp_str = _z_string_alias_str(TCP_SCHEMA); if (!_z_string_equals(&endpoint->_locator._protocol, &tcp_str)) { @@ -111,8 +111,8 @@ int8_t _z_endpoint_tcp_valid(_z_endpoint_t *endpoint) { return ret; } -int8_t _z_f_link_open_tcp(_z_link_t *zl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_open_tcp(_z_link_t *zl) { + z_result_t ret = _Z_RES_OK; uint32_t tout = Z_CONFIG_SOCKET_TIMEOUT; char *tout_as_str = _z_str_intmap_get(&zl->_endpoint._config, TCP_CONFIG_TOUT_KEY); @@ -125,8 +125,8 @@ int8_t _z_f_link_open_tcp(_z_link_t *zl) { return ret; } -int8_t _z_f_link_listen_tcp(_z_link_t *zl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_listen_tcp(_z_link_t *zl) { + z_result_t ret = _Z_RES_OK; ret = _z_listen_tcp(&zl->_socket._tcp._sock, zl->_socket._tcp._rep); @@ -160,8 +160,8 @@ uint16_t _z_get_link_mtu_tcp(void) { return 65535; } -int8_t _z_new_link_tcp(_z_link_t *zl, _z_endpoint_t *endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_new_link_tcp(_z_link_t *zl, _z_endpoint_t *endpoint) { + z_result_t ret = _Z_RES_OK; zl->_cap._transport = Z_LINK_CAP_TRANSPORT_UNICAST; zl->_cap._flow = Z_LINK_CAP_FLOW_STREAM; diff --git a/src/link/unicast/udp.c b/src/link/unicast/udp.c index 8f38830bd..4b6192f38 100644 --- a/src/link/unicast/udp.c +++ b/src/link/unicast/udp.c @@ -79,8 +79,8 @@ static char *__z_parse_address_segment_udp_unicast(_z_string_t *address) { return ret; } -int8_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *endpoint) { + z_result_t ret = _Z_RES_OK; _z_string_t udp_str = _z_string_alias_str(UDP_SCHEMA); if (!_z_string_equals(&endpoint->_locator._protocol, &udp_str)) { @@ -112,8 +112,8 @@ int8_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *endpoint) { return ret; } -int8_t _z_f_link_open_udp_unicast(_z_link_t *self) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_open_udp_unicast(_z_link_t *self) { + z_result_t ret = _Z_RES_OK; uint32_t tout = Z_CONFIG_SOCKET_TIMEOUT; char *tout_as_str = _z_str_intmap_get(&self->_endpoint._config, UDP_CONFIG_TOUT_KEY); @@ -126,8 +126,8 @@ int8_t _z_f_link_open_udp_unicast(_z_link_t *self) { return ret; } -int8_t _z_f_link_listen_udp_unicast(_z_link_t *self) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_listen_udp_unicast(_z_link_t *self) { + z_result_t ret = _Z_RES_OK; uint32_t tout = Z_CONFIG_SOCKET_TIMEOUT; char *tout_as_str = _z_str_intmap_get(&self->_endpoint._config, UDP_CONFIG_TOUT_KEY); @@ -167,8 +167,8 @@ uint16_t _z_get_link_mtu_udp_unicast(void) { return 1450; } -int8_t _z_new_link_udp_unicast(_z_link_t *zl, _z_endpoint_t endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_new_link_udp_unicast(_z_link_t *zl, _z_endpoint_t endpoint) { + z_result_t ret = _Z_RES_OK; zl->_cap._transport = Z_LINK_CAP_TRANSPORT_UNICAST; zl->_cap._flow = Z_LINK_CAP_FLOW_DATAGRAM; diff --git a/src/link/unicast/ws.c b/src/link/unicast/ws.c index 970744051..71355e4f2 100644 --- a/src/link/unicast/ws.c +++ b/src/link/unicast/ws.c @@ -73,8 +73,8 @@ char *__z_parse_address_segment_ws(_z_string_t *address) { return ret; } -int8_t _z_endpoint_ws_valid(_z_endpoint_t *endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_endpoint_ws_valid(_z_endpoint_t *endpoint) { + z_result_t ret = _Z_RES_OK; _z_string_t str = _z_string_alias_str(WS_SCHEMA); if (_z_string_equals(&endpoint->_locator._protocol, &str)) { @@ -106,8 +106,8 @@ int8_t _z_endpoint_ws_valid(_z_endpoint_t *endpoint) { return ret; } -int8_t _z_f_link_open_ws(_z_link_t *zl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_open_ws(_z_link_t *zl) { + z_result_t ret = _Z_RES_OK; uint32_t tout = Z_CONFIG_SOCKET_TIMEOUT; char *tout_as_str = _z_str_intmap_get(&zl->_endpoint._config, WS_CONFIG_TOUT_KEY); @@ -120,8 +120,8 @@ int8_t _z_f_link_open_ws(_z_link_t *zl) { return ret; } -int8_t _z_f_link_listen_ws(_z_link_t *zl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_f_link_listen_ws(_z_link_t *zl) { + z_result_t ret = _Z_RES_OK; ret = _z_listen_ws(&zl->_socket._ws._sock, zl->_socket._ws._rep); @@ -155,8 +155,8 @@ uint16_t _z_get_link_mtu_ws(void) { return 65535; } -int8_t _z_new_link_ws(_z_link_t *zl, _z_endpoint_t *endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_new_link_ws(_z_link_t *zl, _z_endpoint_t *endpoint) { + z_result_t ret = _Z_RES_OK; zl->_cap._transport = Z_LINK_CAP_TRANSPORT_UNICAST; zl->_cap._flow = Z_LINK_CAP_FLOW_DATAGRAM; diff --git a/src/net/config.c b/src/net/config.c index def05b16e..92dc984b4 100644 --- a/src/net/config.c +++ b/src/net/config.c @@ -23,9 +23,9 @@ _z_config_t _z_config_empty(void) { return config; } -int8_t _z_config_default(_z_config_t *config) { return _z_config_client(config, NULL); } +z_result_t _z_config_default(_z_config_t *config) { return _z_config_client(config, NULL); } -int8_t _z_config_client(_z_config_t *ps, const char *locator) { +z_result_t _z_config_client(_z_config_t *ps, const char *locator) { *ps = _z_config_empty(); _Z_RETURN_IF_ERR(_zp_config_insert(ps, Z_CONFIG_MODE_KEY, Z_CONFIG_MODE_CLIENT)); if (locator != NULL) { diff --git a/src/net/encoding.c b/src/net/encoding.c index 98d3d51bb..5926f4657 100644 --- a/src/net/encoding.c +++ b/src/net/encoding.c @@ -19,7 +19,7 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/result.h" -int8_t _z_encoding_make(_z_encoding_t *encoding, uint16_t id, const char *schema, size_t len) { +z_result_t _z_encoding_make(_z_encoding_t *encoding, uint16_t id, const char *schema, size_t len) { encoding->id = id; // Clone schema if (schema != NULL) { @@ -46,7 +46,7 @@ bool _z_encoding_check(const _z_encoding_t *encoding) { return ((encoding->id != _Z_ENCODING_ID_DEFAULT) || _z_string_check(&encoding->schema)); } -int8_t _z_encoding_copy(_z_encoding_t *dst, const _z_encoding_t *src) { +z_result_t _z_encoding_copy(_z_encoding_t *dst, const _z_encoding_t *src) { *dst = _z_encoding_null(); _Z_RETURN_IF_ERR(_z_string_copy(&dst->schema, &src->schema)); dst->id = src->id; diff --git a/src/net/filtering.c b/src/net/filtering.c index eb2400752..706633db7 100644 --- a/src/net/filtering.c +++ b/src/net/filtering.c @@ -72,7 +72,7 @@ static void _z_write_filter_callback(const _z_interest_msg_t *msg, void *arg) { } } -int8_t _z_write_filter_create(_z_publisher_t *pub) { +z_result_t _z_write_filter_create(_z_publisher_t *pub) { uint8_t flags = _Z_INTEREST_FLAG_KEYEXPRS | _Z_INTEREST_FLAG_SUBSCRIBERS | _Z_INTEREST_FLAG_RESTRICTED | _Z_INTEREST_FLAG_CURRENT | _Z_INTEREST_FLAG_FUTURE | _Z_INTEREST_FLAG_AGGREGATE; _z_writer_filter_ctx_t *ctx = (_z_writer_filter_ctx_t *)z_malloc(sizeof(_z_writer_filter_ctx_t)); @@ -94,7 +94,7 @@ int8_t _z_write_filter_create(_z_publisher_t *pub) { return _Z_RES_OK; } -int8_t _z_write_filter_destroy(const _z_publisher_t *pub) { +z_result_t _z_write_filter_destroy(const _z_publisher_t *pub) { _Z_RETURN_IF_ERR(_z_remove_interest(_Z_RC_IN_VAL(&pub->_zn), pub->_filter._interest_id)); z_free(pub->_filter.ctx); return _Z_RES_OK; @@ -103,12 +103,12 @@ int8_t _z_write_filter_destroy(const _z_publisher_t *pub) { bool _z_write_filter_active(const _z_publisher_t *pub) { return (pub->_filter.ctx->state == WRITE_FILTER_ACTIVE); } #else -int8_t _z_write_filter_create(_z_publisher_t *pub) { +z_result_t _z_write_filter_create(_z_publisher_t *pub) { _ZP_UNUSED(pub); return _Z_RES_OK; } -int8_t _z_write_filter_destroy(const _z_publisher_t *pub) { +z_result_t _z_write_filter_destroy(const _z_publisher_t *pub) { _ZP_UNUSED(pub); return _Z_RES_OK; } diff --git a/src/net/primitives.c b/src/net/primitives.c index 019f9dbdd..2e480e440 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -78,8 +78,8 @@ uint16_t _z_declare_resource(_z_session_t *zn, _z_keyexpr_t keyexpr) { return ret; } -int8_t _z_undeclare_resource(_z_session_t *zn, uint16_t rid) { - int8_t ret = _Z_RES_OK; +z_result_t _z_undeclare_resource(_z_session_t *zn, uint16_t rid) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Undeclaring local keyexpr %d", rid); _z_resource_t *r = _z_get_resource_by_id(zn, _Z_KEYEXPR_MAPPING_LOCAL, rid); if (r != NULL) { @@ -119,7 +119,7 @@ _z_publisher_t _z_declare_publisher(const _z_session_rc_t *zn, _z_keyexpr_t keye return ret; } -int8_t _z_undeclare_publisher(_z_publisher_t *pub) { +z_result_t _z_undeclare_publisher(_z_publisher_t *pub) { if (pub == NULL || _Z_RC_IS_NULL(&pub->_zn)) { return _Z_ERR_ENTITY_UNKNOWN; } @@ -130,11 +130,11 @@ int8_t _z_undeclare_publisher(_z_publisher_t *pub) { } /*------------------ Write ------------------*/ -int8_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const _z_bytes_t payload, const _z_encoding_t *encoding, - const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, z_priority_t priority, - bool is_express, const _z_timestamp_t *timestamp, const _z_bytes_t attachment, - z_reliability_t reliability) { - int8_t ret = _Z_RES_OK; +z_result_t _z_write(_z_session_t *zn, const _z_keyexpr_t keyexpr, const _z_bytes_t payload, + const _z_encoding_t *encoding, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, + z_priority_t priority, bool is_express, const _z_timestamp_t *timestamp, + const _z_bytes_t attachment, z_reliability_t reliability) { + z_result_t ret = _Z_RES_OK; _z_network_message_t msg; switch (kind) { case Z_SAMPLE_KIND_PUT: @@ -224,7 +224,7 @@ _z_subscriber_t _z_declare_subscriber(const _z_session_rc_t *zn, _z_keyexpr_t ke return ret; } -int8_t _z_undeclare_subscriber(_z_subscriber_t *sub) { +z_result_t _z_undeclare_subscriber(_z_subscriber_t *sub) { if (sub == NULL || _Z_RC_IS_NULL(&sub->_zn)) { return _Z_ERR_ENTITY_UNKNOWN; } @@ -287,7 +287,7 @@ _z_queryable_t _z_declare_queryable(const _z_session_rc_t *zn, _z_keyexpr_t keye return ret; } -int8_t _z_undeclare_queryable(_z_queryable_t *qle) { +z_result_t _z_undeclare_queryable(_z_queryable_t *qle) { if (qle == NULL || _Z_RC_IS_NULL(&qle->_zn)) { return _Z_ERR_ENTITY_UNKNOWN; } @@ -314,10 +314,11 @@ int8_t _z_undeclare_queryable(_z_queryable_t *qle) { return _Z_RES_OK; } -int8_t _z_send_reply(const _z_query_t *query, const _z_session_rc_t *zsrc, _z_keyexpr_t keyexpr, - const _z_value_t payload, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, - z_priority_t priority, bool is_express, const _z_timestamp_t *timestamp, const _z_bytes_t att) { - int8_t ret = _Z_RES_OK; +z_result_t _z_send_reply(const _z_query_t *query, const _z_session_rc_t *zsrc, _z_keyexpr_t keyexpr, + const _z_value_t payload, const z_sample_kind_t kind, const z_congestion_control_t cong_ctrl, + z_priority_t priority, bool is_express, const _z_timestamp_t *timestamp, + const _z_bytes_t att) { + z_result_t ret = _Z_RES_OK; _z_session_t *zn = _Z_RC_IN_VAL(zsrc); _z_keyexpr_t q_ke; @@ -415,8 +416,8 @@ int8_t _z_send_reply(const _z_query_t *query, const _z_session_rc_t *zsrc, _z_ke return ret; } -int8_t _z_send_reply_err(const _z_query_t *query, const _z_session_rc_t *zsrc, const _z_value_t payload) { - int8_t ret = _Z_RES_OK; +z_result_t _z_send_reply_err(const _z_query_t *query, const _z_session_rc_t *zsrc, const _z_value_t payload) { + z_result_t ret = _Z_RES_OK; _z_session_t *zn = _Z_RC_IN_VAL(zsrc); // Build the reply context decorator. This is NOT the final reply. @@ -450,11 +451,11 @@ int8_t _z_send_reply_err(const _z_query_t *query, const _z_session_rc_t *zsrc, c #if Z_FEATURE_QUERY == 1 /*------------------ Query ------------------*/ -int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target, - const z_consolidation_mode_t consolidation, _z_value_t value, _z_reply_handler_t callback, - _z_drop_handler_t dropper, void *arg, uint64_t timeout_ms, const _z_bytes_t attachment, - z_congestion_control_t cong_ctrl, z_priority_t priority, bool is_express) { - int8_t ret = _Z_RES_OK; +z_result_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target, + const z_consolidation_mode_t consolidation, _z_value_t value, _z_reply_handler_t callback, + _z_drop_handler_t dropper, void *arg, uint64_t timeout_ms, const _z_bytes_t attachment, + z_congestion_control_t cong_ctrl, z_priority_t priority, bool is_express) { + z_result_t ret = _Z_RES_OK; // Create the pending query object _z_pending_query_t *pq = (_z_pending_query_t *)z_malloc(sizeof(_z_pending_query_t)); @@ -515,7 +516,7 @@ uint32_t _z_add_interest(_z_session_t *zn, _z_keyexpr_t keyexpr, _z_interest_han return intr._id; } -int8_t _z_remove_interest(_z_session_t *zn, uint32_t interest_id) { +z_result_t _z_remove_interest(_z_session_t *zn, uint32_t interest_id) { // Find interest entry _z_session_interest_rc_t *sintr = _z_get_interest_by_id(zn, interest_id); if (sintr == NULL) { diff --git a/src/net/query.c b/src/net/query.c index 76cda128e..79e50ee33 100644 --- a/src/net/query.c +++ b/src/net/query.c @@ -53,7 +53,7 @@ void _z_query_clear(_z_query_t *q) { _z_query_clear_inner(q); } -int8_t _z_query_copy(_z_query_t *dst, const _z_query_t *src) { +z_result_t _z_query_copy(_z_query_t *dst, const _z_query_t *src) { *dst = _z_query_null(); _Z_RETURN_IF_ERR(_z_keyexpr_copy(&dst->_key, &src->_key)); _Z_CLEAN_RETURN_IF_ERR(_z_value_copy(&dst->_value, &src->_value), _z_query_clear_inner(dst)); diff --git a/src/net/reply.c b/src/net/reply.c index b84a19eec..b9038af2e 100644 --- a/src/net/reply.c +++ b/src/net/reply.c @@ -47,7 +47,7 @@ void _z_reply_data_free(_z_reply_data_t **reply_data) { } } -int8_t _z_reply_data_copy(_z_reply_data_t *dst, const _z_reply_data_t *src) { +z_result_t _z_reply_data_copy(_z_reply_data_t *dst, const _z_reply_data_t *src) { *dst = _z_reply_data_null(); if (src->_tag == _Z_REPLY_TAG_DATA) { _Z_RETURN_IF_ERR(_z_sample_copy(&dst->_result.sample, &src->_result.sample)); @@ -78,7 +78,7 @@ void _z_reply_free(_z_reply_t **reply) { } } -int8_t _z_reply_copy(_z_reply_t *dst, const _z_reply_t *src) { +z_result_t _z_reply_copy(_z_reply_t *dst, const _z_reply_t *src) { *dst = _z_reply_null(); _Z_RETURN_IF_ERR(_z_reply_data_copy(&dst->data, &src->data)); return _Z_RES_OK; diff --git a/src/net/sample.c b/src/net/sample.c index c6e3e9a37..6248f57e5 100644 --- a/src/net/sample.c +++ b/src/net/sample.c @@ -61,7 +61,7 @@ void _z_sample_free(_z_sample_t **sample) { } } -int8_t _z_sample_copy(_z_sample_t *dst, const _z_sample_t *src) { +z_result_t _z_sample_copy(_z_sample_t *dst, const _z_sample_t *src) { *dst = _z_sample_null(); _Z_RETURN_IF_ERR(_z_keyexpr_copy(&dst->keyexpr, &src->keyexpr)); _Z_CLEAN_RETURN_IF_ERR(_z_bytes_copy(&dst->payload, &src->payload), _z_sample_clear(dst)); diff --git a/src/net/session.c b/src/net/session.c index f2d675720..442844fcb 100644 --- a/src/net/session.c +++ b/src/net/session.c @@ -37,8 +37,8 @@ #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/uuid.h" -int8_t __z_open_inner(_z_session_rc_t *zn, _z_string_t *locator, z_whatami_t mode) { - int8_t ret = _Z_RES_OK; +z_result_t __z_open_inner(_z_session_rc_t *zn, _z_string_t *locator, z_whatami_t mode) { + z_result_t ret = _Z_RES_OK; _z_id_t local_zid = _z_id_empty(); ret = _z_session_generate_zid(&local_zid, Z_ZID_LENGTH); @@ -55,8 +55,8 @@ int8_t __z_open_inner(_z_session_rc_t *zn, _z_string_t *locator, z_whatami_t mod return ret; } -int8_t _z_open(_z_session_rc_t *zn, _z_config_t *config) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open(_z_session_rc_t *zn, _z_config_t *config) { + z_result_t ret = _Z_RES_OK; _z_id_t zid = _z_id_empty(); char *opt_as_str = _z_config_get(config, Z_CONFIG_SESSION_ZID_KEY); @@ -178,15 +178,15 @@ _z_config_t *_z_info(const _z_session_t *zn) { return ps; } -int8_t _zp_read(_z_session_t *zn) { return _z_read(&zn->_tp); } +z_result_t _zp_read(_z_session_t *zn) { return _z_read(&zn->_tp); } -int8_t _zp_send_keep_alive(_z_session_t *zn) { return _z_send_keep_alive(&zn->_tp); } +z_result_t _zp_send_keep_alive(_z_session_t *zn) { return _z_send_keep_alive(&zn->_tp); } -int8_t _zp_send_join(_z_session_t *zn) { return _z_send_join(&zn->_tp); } +z_result_t _zp_send_join(_z_session_t *zn) { return _z_send_join(&zn->_tp); } #if Z_FEATURE_MULTI_THREAD == 1 -int8_t _zp_start_read_task(_z_session_t *zn, z_task_attr_t *attr) { - int8_t ret = _Z_RES_OK; +z_result_t _zp_start_read_task(_z_session_t *zn, z_task_attr_t *attr) { + z_result_t ret = _Z_RES_OK; // Allocate task _z_task_t *task = (_z_task_t *)z_malloc(sizeof(_z_task_t)); if (task == NULL) { @@ -214,8 +214,8 @@ int8_t _zp_start_read_task(_z_session_t *zn, z_task_attr_t *attr) { return ret; } -int8_t _zp_start_lease_task(_z_session_t *zn, z_task_attr_t *attr) { - int8_t ret = _Z_RES_OK; +z_result_t _zp_start_lease_task(_z_session_t *zn, z_task_attr_t *attr) { + z_result_t ret = _Z_RES_OK; // Allocate task _z_task_t *task = (_z_task_t *)z_malloc(sizeof(_z_task_t)); if (task == NULL) { @@ -243,8 +243,8 @@ int8_t _zp_start_lease_task(_z_session_t *zn, z_task_attr_t *attr) { return ret; } -int8_t _zp_stop_read_task(_z_session_t *zn) { - int8_t ret = _Z_RES_OK; +z_result_t _zp_stop_read_task(_z_session_t *zn) { + z_result_t ret = _Z_RES_OK; // Call transport function switch (zn->_tp._type) { case _Z_TRANSPORT_UNICAST_TYPE: @@ -263,8 +263,8 @@ int8_t _zp_stop_read_task(_z_session_t *zn) { return ret; } -int8_t _zp_stop_lease_task(_z_session_t *zn) { - int8_t ret = _Z_RES_OK; +z_result_t _zp_stop_lease_task(_z_session_t *zn) { + z_result_t ret = _Z_RES_OK; // Call transport function switch (zn->_tp._type) { case _Z_TRANSPORT_UNICAST_TYPE: diff --git a/src/protocol/codec.c b/src/protocol/codec.c index 24f2f54e7..7564ef782 100644 --- a/src/protocol/codec.c +++ b/src/protocol/codec.c @@ -22,10 +22,10 @@ #include "zenoh-pico/utils/result.h" /*------------------ uint8 -------------------*/ -int8_t _z_consolidation_mode_encode(_z_wbuf_t *wbf, z_consolidation_mode_t en) { return _z_zsize_encode(wbf, en); } +z_result_t _z_consolidation_mode_encode(_z_wbuf_t *wbf, z_consolidation_mode_t en) { return _z_zsize_encode(wbf, en); } -int8_t _z_consolidation_mode_decode(z_consolidation_mode_t *en, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_consolidation_mode_decode(z_consolidation_mode_t *en, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; _z_zint_t tmp; ret |= _z_zsize_decode(&tmp, zbf); @@ -34,10 +34,10 @@ int8_t _z_consolidation_mode_decode(z_consolidation_mode_t *en, _z_zbuf_t *zbf) return ret; } -int8_t _z_query_target_encode(_z_wbuf_t *wbf, z_query_target_t en) { return _z_zsize_encode(wbf, en); } +z_result_t _z_query_target_encode(_z_wbuf_t *wbf, z_query_target_t en) { return _z_zsize_encode(wbf, en); } -int8_t _z_query_target_decode(z_query_target_t *en, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_query_target_decode(z_query_target_t *en, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; _z_zint_t tmp; ret |= _z_zsize_decode(&tmp, zbf); @@ -46,10 +46,10 @@ int8_t _z_query_target_decode(z_query_target_t *en, _z_zbuf_t *zbf) { return ret; } -int8_t _z_whatami_encode(_z_wbuf_t *wbf, z_whatami_t en) { return _z_zsize_encode(wbf, _z_whatami_to_uint8(en)); } +z_result_t _z_whatami_encode(_z_wbuf_t *wbf, z_whatami_t en) { return _z_zsize_encode(wbf, _z_whatami_to_uint8(en)); } -int8_t _z_whatami_decode(z_whatami_t *en, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_whatami_decode(z_whatami_t *en, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; _z_zint_t tmp; ret |= _z_zsize_decode(&tmp, zbf); @@ -58,10 +58,10 @@ int8_t _z_whatami_decode(z_whatami_t *en, _z_zbuf_t *zbf) { return ret; } -int8_t _z_uint8_encode(_z_wbuf_t *wbf, uint8_t u8) { return _z_wbuf_write(wbf, u8); } +z_result_t _z_uint8_encode(_z_wbuf_t *wbf, uint8_t u8) { return _z_wbuf_write(wbf, u8); } -int8_t _z_uint8_decode(uint8_t *u8, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_uint8_decode(uint8_t *u8, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; *u8 = 0; if (_z_zbuf_can_read(zbf) == true) { @@ -74,8 +74,8 @@ int8_t _z_uint8_decode(uint8_t *u8, _z_zbuf_t *zbf) { return ret; } -int8_t _z_uint16_encode(_z_wbuf_t *wbf, uint16_t u16) { - int8_t ret = _Z_RES_OK; +z_result_t _z_uint16_encode(_z_wbuf_t *wbf, uint16_t u16) { + z_result_t ret = _Z_RES_OK; ret |= _z_wbuf_write(wbf, _z_get_u16_lsb(u16)); ret |= _z_wbuf_write(wbf, _z_get_u16_msb(u16)); @@ -83,8 +83,8 @@ int8_t _z_uint16_encode(_z_wbuf_t *wbf, uint16_t u16) { return ret; } -int8_t _z_uint16_decode(uint16_t *u16, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_uint16_decode(uint16_t *u16, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; uint8_t enc_u16[2]; ret |= _z_uint8_decode(&enc_u16[0], zbf); @@ -147,7 +147,7 @@ uint8_t _z_zint64_encode_buf(uint8_t *buf, uint64_t v) { return (uint8_t)start; } -int8_t _z_zint64_encode(_z_wbuf_t *wbf, uint64_t v) { +z_result_t _z_zint64_encode(_z_wbuf_t *wbf, uint64_t v) { uint8_t buf[VLE_LEN]; size_t len = _z_zint64_encode_buf(buf, v); @@ -157,11 +157,11 @@ int8_t _z_zint64_encode(_z_wbuf_t *wbf, uint64_t v) { return _Z_RES_OK; } -int8_t _z_zint16_encode(_z_wbuf_t *wbf, uint16_t v) { return _z_zint64_encode(wbf, (uint64_t)v); } -int8_t _z_zint32_encode(_z_wbuf_t *wbf, uint32_t v) { return _z_zint64_encode(wbf, (uint64_t)v); } -int8_t _z_zsize_encode(_z_wbuf_t *wbf, _z_zint_t v) { return _z_zint64_encode(wbf, (uint64_t)v); } +z_result_t _z_zint16_encode(_z_wbuf_t *wbf, uint16_t v) { return _z_zint64_encode(wbf, (uint64_t)v); } +z_result_t _z_zint32_encode(_z_wbuf_t *wbf, uint32_t v) { return _z_zint64_encode(wbf, (uint64_t)v); } +z_result_t _z_zsize_encode(_z_wbuf_t *wbf, _z_zint_t v) { return _z_zint64_encode(wbf, (uint64_t)v); } -int8_t _z_zint64_decode_with_reader(uint64_t *zint, __z_single_byte_reader_t reader, void *context) { +z_result_t _z_zint64_decode_with_reader(uint64_t *zint, __z_single_byte_reader_t reader, void *context) { *zint = 0; uint8_t b = 0; @@ -178,9 +178,9 @@ int8_t _z_zint64_decode_with_reader(uint64_t *zint, __z_single_byte_reader_t rea return _Z_RES_OK; } -int8_t _z_zsize_decode_with_reader(_z_zint_t *zint, __z_single_byte_reader_t reader, void *context) { +z_result_t _z_zsize_decode_with_reader(_z_zint_t *zint, __z_single_byte_reader_t reader, void *context) { uint64_t i = 0; - int8_t res = _z_zint64_decode_with_reader(&i, reader, context); + z_result_t res = _z_zint64_decode_with_reader(&i, reader, context); if (res != _Z_RES_OK || i > SIZE_MAX) { res = _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; } else { @@ -189,14 +189,14 @@ int8_t _z_zsize_decode_with_reader(_z_zint_t *zint, __z_single_byte_reader_t rea return res; } -int8_t _z_uint8_decode_reader(uint8_t *zint, void *context) { return _z_uint8_decode(zint, (_z_zbuf_t *)context); } +z_result_t _z_uint8_decode_reader(uint8_t *zint, void *context) { return _z_uint8_decode(zint, (_z_zbuf_t *)context); } -int8_t _z_zint64_decode(uint64_t *zint, _z_zbuf_t *zbf) { +z_result_t _z_zint64_decode(uint64_t *zint, _z_zbuf_t *zbf) { return _z_zint64_decode_with_reader(zint, _z_uint8_decode_reader, (void *)zbf); } -int8_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; uint64_t buf; _Z_RETURN_IF_ERR(_z_zint64_decode(&buf, zbf)); if (buf <= UINT16_MAX) { @@ -207,8 +207,8 @@ int8_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *zbf) { return ret; } -int8_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; uint64_t buf; _Z_RETURN_IF_ERR(_z_zint64_decode(&buf, zbf)); if (buf <= UINT32_MAX) { @@ -219,13 +219,13 @@ int8_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *zbf) { return ret; } -int8_t _z_zsize_decode(_z_zint_t *zint, _z_zbuf_t *zbf) { +z_result_t _z_zsize_decode(_z_zint_t *zint, _z_zbuf_t *zbf) { return _z_zsize_decode_with_reader(zint, _z_uint8_decode_reader, (void *)zbf); } /*------------------ uint8_array ------------------*/ -int8_t _z_buf_encode(_z_wbuf_t *wbf, const uint8_t *buf, size_t len) { - int8_t ret = _Z_RES_OK; +z_result_t _z_buf_encode(_z_wbuf_t *wbf, const uint8_t *buf, size_t len) { + z_result_t ret = _Z_RES_OK; if ((wbf->_expansion_step != 0) && (len > Z_TSID_LENGTH)) { ret |= _z_wbuf_wrap_bytes(wbf, buf, 0, len); @@ -236,10 +236,10 @@ int8_t _z_buf_encode(_z_wbuf_t *wbf, const uint8_t *buf, size_t len) { return ret; } -int8_t _z_slice_val_encode(_z_wbuf_t *wbf, const _z_slice_t *bs) { return _z_buf_encode(wbf, bs->start, bs->len); } +z_result_t _z_slice_val_encode(_z_wbuf_t *wbf, const _z_slice_t *bs) { return _z_buf_encode(wbf, bs->start, bs->len); } -int8_t _z_slice_encode(_z_wbuf_t *wbf, const _z_slice_t *bs) { - int8_t ret = _Z_RES_OK; +z_result_t _z_slice_encode(_z_wbuf_t *wbf, const _z_slice_t *bs) { + z_result_t ret = _Z_RES_OK; _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, bs->len)) _Z_RETURN_IF_ERR(_z_slice_val_encode(wbf, bs)) @@ -247,8 +247,8 @@ int8_t _z_slice_encode(_z_wbuf_t *wbf, const _z_slice_t *bs) { return ret; } -int8_t _z_slice_val_decode_na(_z_slice_t *bs, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_slice_val_decode_na(_z_slice_t *bs, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; if (ret == _Z_RES_OK) { if (_z_zbuf_len(zbf) >= bs->len) { // Check if we have enough bytes to read @@ -268,16 +268,16 @@ int8_t _z_slice_val_decode_na(_z_slice_t *bs, _z_zbuf_t *zbf) { return ret; } -int8_t _z_slice_decode_na(_z_slice_t *bs, _z_zbuf_t *zbf) { +z_result_t _z_slice_decode_na(_z_slice_t *bs, _z_zbuf_t *zbf) { _Z_RETURN_IF_ERR(_z_zsize_decode(&bs->len, zbf)); return _z_slice_val_decode_na(bs, zbf); } -int8_t _z_slice_val_decode(_z_slice_t *bs, _z_zbuf_t *zbf) { return _z_slice_val_decode_na(bs, zbf); } +z_result_t _z_slice_val_decode(_z_slice_t *bs, _z_zbuf_t *zbf) { return _z_slice_val_decode_na(bs, zbf); } -int8_t _z_slice_decode(_z_slice_t *bs, _z_zbuf_t *zbf) { return _z_slice_decode_na(bs, zbf); } +z_result_t _z_slice_decode(_z_slice_t *bs, _z_zbuf_t *zbf) { return _z_slice_decode_na(bs, zbf); } -int8_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *zbf) { +z_result_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *zbf) { _z_slice_t s; _Z_RETURN_IF_ERR(_z_slice_decode(&s, zbf)); if (_z_slice_is_alloced(&s)) { @@ -287,8 +287,8 @@ int8_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *zbf) { } } -int8_t _z_bytes_encode_val(_z_wbuf_t *wbf, const _z_bytes_t *bs) { - int8_t ret = _Z_RES_OK; +z_result_t _z_bytes_encode_val(_z_wbuf_t *wbf, const _z_bytes_t *bs) { + z_result_t ret = _Z_RES_OK; for (size_t i = 0; i < _z_bytes_num_slices(bs); ++i) { const _z_arc_slice_t *arc_s = _z_bytes_get_slice(bs, i); _Z_RETURN_IF_ERR(_z_buf_encode(wbf, _z_arc_slice_data(arc_s), _z_arc_slice_len(arc_s))) @@ -297,21 +297,21 @@ int8_t _z_bytes_encode_val(_z_wbuf_t *wbf, const _z_bytes_t *bs) { return ret; } -int8_t _z_bytes_encode(_z_wbuf_t *wbf, const _z_bytes_t *bs) { +z_result_t _z_bytes_encode(_z_wbuf_t *wbf, const _z_bytes_t *bs) { _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, _z_bytes_len(bs))) return _z_bytes_encode_val(wbf, bs); } /*------------------ string with null terminator ------------------*/ -int8_t _z_str_encode(_z_wbuf_t *wbf, const char *s) { +z_result_t _z_str_encode(_z_wbuf_t *wbf, const char *s) { size_t len = strlen(s); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, len)) // Note that this does not put the string terminator on the wire. return _z_wbuf_write_bytes(wbf, (const uint8_t *)s, 0, len); } -int8_t _z_str_decode(char **str, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_str_decode(char **str, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; _z_zint_t len = 0; ret |= _z_zsize_decode(&len, zbf); @@ -337,13 +337,13 @@ int8_t _z_str_decode(char **str, _z_zbuf_t *zbf) { return ret; } -int8_t _z_string_encode(_z_wbuf_t *wbf, const _z_string_t *s) { +z_result_t _z_string_encode(_z_wbuf_t *wbf, const _z_string_t *s) { _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, _z_string_len(s))) // Note that this does not put the string terminator on the wire. return _z_wbuf_write_bytes(wbf, (const uint8_t *)_z_string_data(s), 0, _z_string_len(s)); } -int8_t _z_string_decode(_z_string_t *str, _z_zbuf_t *zbf) { +z_result_t _z_string_decode(_z_string_t *str, _z_zbuf_t *zbf) { *str = _z_string_null(); _z_zint_t len = 0; // Decode string length @@ -374,7 +374,7 @@ size_t _z_encoding_len(const _z_encoding_t *en) { return en_len; } -int8_t _z_encoding_encode(_z_wbuf_t *wbf, const _z_encoding_t *en) { +z_result_t _z_encoding_encode(_z_wbuf_t *wbf, const _z_encoding_t *en) { bool has_schema = _z_string_check(&en->schema); uint32_t id = (uint32_t)(en->id) << 1; if (has_schema) { @@ -387,7 +387,7 @@ int8_t _z_encoding_encode(_z_wbuf_t *wbf, const _z_encoding_t *en) { return _Z_RES_OK; } -int8_t _z_encoding_decode(_z_encoding_t *en, _z_zbuf_t *zbf) { +z_result_t _z_encoding_decode(_z_encoding_t *en, _z_zbuf_t *zbf) { uint32_t id = 0; bool has_schema = false; _Z_RETURN_IF_ERR(_z_zint32_decode(&id, zbf)); @@ -401,14 +401,14 @@ int8_t _z_encoding_decode(_z_encoding_t *en, _z_zbuf_t *zbf) { return _Z_RES_OK; } -int8_t _z_value_encode(_z_wbuf_t *wbf, const _z_value_t *value) { +z_result_t _z_value_encode(_z_wbuf_t *wbf, const _z_value_t *value) { size_t total_len = _z_encoding_len(&value->encoding) + _z_bytes_len(&value->payload); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, total_len)); _Z_RETURN_IF_ERR(_z_encoding_encode(wbf, &value->encoding)); return _z_bytes_encode_val(wbf, &value->payload); } -int8_t _z_value_decode(_z_value_t *value, _z_zbuf_t *zbf) { +z_result_t _z_value_decode(_z_value_t *value, _z_zbuf_t *zbf) { _Z_RETURN_IF_ERR(_z_encoding_decode(&value->encoding, zbf)); _Z_RETURN_IF_ERR(_z_bytes_from_buf(&value->payload, (uint8_t *)_z_zbuf_start(zbf), _z_zbuf_len(zbf))); return _Z_RES_OK; diff --git a/src/protocol/codec/core.c b/src/protocol/codec/core.c index 9f8db2d09..590b3e261 100644 --- a/src/protocol/codec/core.c +++ b/src/protocol/codec/core.c @@ -16,7 +16,7 @@ #include "zenoh-pico/protocol/iobuf.h" -int8_t _z_zbuf_read_exact(_z_zbuf_t *zbf, uint8_t *dest, size_t length) { +z_result_t _z_zbuf_read_exact(_z_zbuf_t *zbf, uint8_t *dest, size_t length) { if (length > _z_zbuf_len(zbf)) { return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; } diff --git a/src/protocol/codec/declarations.c b/src/protocol/codec/declarations.c index 5c298f3f9..be68a2f81 100644 --- a/src/protocol/codec/declarations.c +++ b/src/protocol/codec/declarations.c @@ -33,7 +33,7 @@ #include "zenoh-pico/session/session.h" #include "zenoh-pico/system/platform.h" -int8_t _z_decl_ext_keyexpr_encode(_z_wbuf_t *wbf, _z_keyexpr_t ke, bool has_next_ext) { +z_result_t _z_decl_ext_keyexpr_encode(_z_wbuf_t *wbf, _z_keyexpr_t ke, bool has_next_ext) { uint8_t header = _Z_MSG_EXT_ENC_ZBUF | _Z_MSG_EXT_FLAG_M | 0x0f | (has_next_ext ? _Z_FLAG_Z_Z : 0); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); uint32_t kelen = (uint32_t)(_z_keyexpr_has_suffix(&ke) ? _z_string_len(&ke._suffix) : 0); @@ -47,7 +47,7 @@ int8_t _z_decl_ext_keyexpr_encode(_z_wbuf_t *wbf, _z_keyexpr_t ke, bool has_next return _Z_RES_OK; } -int8_t _z_decl_kexpr_encode(_z_wbuf_t *wbf, const _z_decl_kexpr_t *decl) { +z_result_t _z_decl_kexpr_encode(_z_wbuf_t *wbf, const _z_decl_kexpr_t *decl) { uint8_t header = _Z_DECL_KEXPR_MID; int has_kesuffix = _z_keyexpr_has_suffix(&decl->_keyexpr); if (has_kesuffix) { @@ -60,7 +60,8 @@ int8_t _z_decl_kexpr_encode(_z_wbuf_t *wbf, const _z_decl_kexpr_t *decl) { return _Z_RES_OK; } -int8_t _z_decl_commons_encode(_z_wbuf_t *wbf, uint8_t header, bool has_extensions, uint32_t id, _z_keyexpr_t keyexpr) { +z_result_t _z_decl_commons_encode(_z_wbuf_t *wbf, uint8_t header, bool has_extensions, uint32_t id, + _z_keyexpr_t keyexpr) { bool has_kesuffix = _z_keyexpr_has_suffix(&keyexpr); if (has_extensions) { header |= _Z_FLAG_Z_Z; @@ -75,16 +76,16 @@ int8_t _z_decl_commons_encode(_z_wbuf_t *wbf, uint8_t header, bool has_extension _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, id)); return _z_keyexpr_encode(wbf, has_kesuffix, &keyexpr); } -int8_t _z_decl_subscriber_encode(_z_wbuf_t *wbf, const _z_decl_subscriber_t *decl) { +z_result_t _z_decl_subscriber_encode(_z_wbuf_t *wbf, const _z_decl_subscriber_t *decl) { uint8_t header = _Z_DECL_SUBSCRIBER_MID; _Z_RETURN_IF_ERR(_z_decl_commons_encode(wbf, header, false, decl->_id, decl->_keyexpr)); return _Z_RES_OK; } -int8_t _z_undecl_kexpr_encode(_z_wbuf_t *wbf, const _z_undecl_kexpr_t *decl) { +z_result_t _z_undecl_kexpr_encode(_z_wbuf_t *wbf, const _z_undecl_kexpr_t *decl) { _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, _Z_UNDECL_KEXPR)); return _z_zsize_encode(wbf, decl->_id); } -int8_t _z_undecl_encode(_z_wbuf_t *wbf, uint8_t header, _z_zint_t decl_id, _z_keyexpr_t ke) { +z_result_t _z_undecl_encode(_z_wbuf_t *wbf, uint8_t header, _z_zint_t decl_id, _z_keyexpr_t ke) { bool has_keyexpr_ext = _z_keyexpr_check(&ke); if (has_keyexpr_ext) { header |= _Z_FLAG_Z_Z; @@ -96,10 +97,10 @@ int8_t _z_undecl_encode(_z_wbuf_t *wbf, uint8_t header, _z_zint_t decl_id, _z_ke } return _Z_RES_OK; } -int8_t _z_undecl_subscriber_encode(_z_wbuf_t *wbf, const _z_undecl_subscriber_t *decl) { +z_result_t _z_undecl_subscriber_encode(_z_wbuf_t *wbf, const _z_undecl_subscriber_t *decl) { return _z_undecl_encode(wbf, _Z_UNDECL_SUBSCRIBER_MID, decl->_id, decl->_ext_keyexpr); } -int8_t _z_decl_queryable_encode(_z_wbuf_t *wbf, const _z_decl_queryable_t *decl) { +z_result_t _z_decl_queryable_encode(_z_wbuf_t *wbf, const _z_decl_queryable_t *decl) { uint8_t header = _Z_DECL_QUERYABLE_MID; bool has_info_ext = decl->_ext_queryable_info._complete || (decl->_ext_queryable_info._distance != 0); _Z_RETURN_IF_ERR(_z_decl_commons_encode(wbf, header, has_info_ext, decl->_id, decl->_keyexpr)); @@ -114,25 +115,25 @@ int8_t _z_decl_queryable_encode(_z_wbuf_t *wbf, const _z_decl_queryable_t *decl) } return _Z_RES_OK; } -int8_t _z_undecl_queryable_encode(_z_wbuf_t *wbf, const _z_undecl_queryable_t *decl) { +z_result_t _z_undecl_queryable_encode(_z_wbuf_t *wbf, const _z_undecl_queryable_t *decl) { return _z_undecl_encode(wbf, _Z_UNDECL_QUERYABLE_MID, decl->_id, decl->_ext_keyexpr); } -int8_t _z_decl_token_encode(_z_wbuf_t *wbf, const _z_decl_token_t *decl) { +z_result_t _z_decl_token_encode(_z_wbuf_t *wbf, const _z_decl_token_t *decl) { uint8_t header = _Z_DECL_TOKEN_MID; _Z_RETURN_IF_ERR(_z_decl_commons_encode(wbf, header, false, decl->_id, decl->_keyexpr)); return _Z_RES_OK; } -int8_t _z_undecl_token_encode(_z_wbuf_t *wbf, const _z_undecl_token_t *decl) { +z_result_t _z_undecl_token_encode(_z_wbuf_t *wbf, const _z_undecl_token_t *decl) { return _z_undecl_encode(wbf, _Z_UNDECL_TOKEN_MID, decl->_id, decl->_ext_keyexpr); } -int8_t _z_decl_final_encode(_z_wbuf_t *wbf) { +z_result_t _z_decl_final_encode(_z_wbuf_t *wbf) { uint8_t header = _Z_DECL_FINAL_MID; _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); return _Z_RES_OK; } -int8_t _z_declaration_encode(_z_wbuf_t *wbf, const _z_declaration_t *decl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_declaration_encode(_z_wbuf_t *wbf, const _z_declaration_t *decl) { + z_result_t ret = _Z_RES_OK; switch (decl->_tag) { case _Z_DECL_KEXPR: { ret = _z_decl_kexpr_encode(wbf, &decl->_body._decl_kexpr); @@ -165,7 +166,7 @@ int8_t _z_declaration_encode(_z_wbuf_t *wbf, const _z_declaration_t *decl) { } return ret; } -int8_t _z_decl_kexpr_decode(_z_decl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_decl_kexpr_decode(_z_decl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header) { *decl = _z_decl_kexpr_null(); _Z_RETURN_IF_ERR(_z_zint16_decode(&decl->_id, zbf)); _Z_RETURN_IF_ERR(_z_keyexpr_decode(&decl->_keyexpr, zbf, _Z_HAS_FLAG(header, _Z_DECL_KEXPR_FLAG_N))); @@ -176,7 +177,7 @@ int8_t _z_decl_kexpr_decode(_z_decl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t heade } return _Z_RES_OK; } -int8_t _z_undecl_kexpr_decode(_z_undecl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_undecl_kexpr_decode(_z_undecl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t header) { *decl = _z_undecl_kexpr_null(); _Z_RETURN_IF_ERR(_z_zint16_decode(&decl->_id, zbf)); @@ -186,7 +187,7 @@ int8_t _z_undecl_kexpr_decode(_z_undecl_kexpr_t *decl, _z_zbuf_t *zbf, uint8_t h return _Z_RES_OK; } -int8_t _z_undecl_decode_extensions(_z_msg_ext_t *extension, void *ctx) { +z_result_t _z_undecl_decode_extensions(_z_msg_ext_t *extension, void *ctx) { _z_keyexpr_t *ke = (_z_keyexpr_t *)ctx; switch (extension->_header) { case _Z_MSG_EXT_ENC_ZBUF | _Z_MSG_EXT_FLAG_M | 0x0f: { @@ -215,14 +216,15 @@ int8_t _z_undecl_decode_extensions(_z_msg_ext_t *extension, void *ctx) { } return _Z_RES_OK; } -int8_t _z_undecl_trivial_decode(_z_zbuf_t *zbf, _z_keyexpr_t *_ext_keyexpr, uint32_t *decl_id, uint8_t header) { +z_result_t _z_undecl_trivial_decode(_z_zbuf_t *zbf, _z_keyexpr_t *_ext_keyexpr, uint32_t *decl_id, uint8_t header) { _Z_RETURN_IF_ERR(_z_zint32_decode(decl_id, zbf)); if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) { _Z_RETURN_IF_ERR(_z_msg_ext_decode_iter(zbf, _z_undecl_decode_extensions, _ext_keyexpr)); } return _Z_RES_OK; } -int8_t _z_decl_commons_decode(_z_zbuf_t *zbf, uint8_t header, bool *has_extensions, uint32_t *id, _z_keyexpr_t *ke) { +z_result_t _z_decl_commons_decode(_z_zbuf_t *zbf, uint8_t header, bool *has_extensions, uint32_t *id, + _z_keyexpr_t *ke) { *has_extensions = _Z_HAS_FLAG(header, _Z_FLAG_Z_Z); uint16_t mapping = _Z_HAS_FLAG(header, _Z_DECL_SUBSCRIBER_FLAG_M) ? _Z_KEYEXPR_MAPPING_UNKNOWN_REMOTE : _Z_KEYEXPR_MAPPING_LOCAL; @@ -246,7 +248,7 @@ int8_t _z_decl_commons_decode(_z_zbuf_t *zbf, uint8_t header, bool *has_extensio } return _Z_RES_OK; } -int8_t _z_decl_subscriber_decode_extensions(_z_msg_ext_t *extension, void *ctx) { +z_result_t _z_decl_subscriber_decode_extensions(_z_msg_ext_t *extension, void *ctx) { _ZP_UNUSED(ctx); switch (extension->_header) { default: @@ -257,7 +259,7 @@ int8_t _z_decl_subscriber_decode_extensions(_z_msg_ext_t *extension, void *ctx) return _Z_RES_OK; } -int8_t _z_decl_subscriber_decode(_z_decl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_decl_subscriber_decode(_z_decl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header) { bool has_ext; *decl = _z_decl_subscriber_null(); _Z_RETURN_IF_ERR(_z_decl_commons_decode(zbf, header, &has_ext, &decl->_id, &decl->_keyexpr)); @@ -266,11 +268,11 @@ int8_t _z_decl_subscriber_decode(_z_decl_subscriber_t *decl, _z_zbuf_t *zbf, uin } return _Z_RES_OK; } -int8_t _z_undecl_subscriber_decode(_z_undecl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_undecl_subscriber_decode(_z_undecl_subscriber_t *decl, _z_zbuf_t *zbf, uint8_t header) { *decl = _z_undecl_subscriber_null(); return _z_undecl_trivial_decode(zbf, &decl->_ext_keyexpr, &decl->_id, header); } -int8_t _z_decl_queryable_decode_extensions(_z_msg_ext_t *extension, void *ctx) { +z_result_t _z_decl_queryable_decode_extensions(_z_msg_ext_t *extension, void *ctx) { _z_decl_queryable_t *decl = (_z_decl_queryable_t *)ctx; switch (extension->_header) { case _Z_MSG_EXT_ENC_ZINT | 0x01: { @@ -285,7 +287,7 @@ int8_t _z_decl_queryable_decode_extensions(_z_msg_ext_t *extension, void *ctx) { } return _Z_RES_OK; } -int8_t _z_decl_queryable_decode(_z_decl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_decl_queryable_decode(_z_decl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header) { bool has_ext; *decl = _z_decl_queryable_null(); _Z_RETURN_IF_ERR(_z_decl_commons_decode(zbf, header, &has_ext, &decl->_id, &decl->_keyexpr)); @@ -294,11 +296,11 @@ int8_t _z_decl_queryable_decode(_z_decl_queryable_t *decl, _z_zbuf_t *zbf, uint8 } return _Z_RES_OK; } -int8_t _z_undecl_queryable_decode(_z_undecl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_undecl_queryable_decode(_z_undecl_queryable_t *decl, _z_zbuf_t *zbf, uint8_t header) { *decl = _z_undecl_queryable_null(); return _z_undecl_trivial_decode(zbf, &decl->_ext_keyexpr, &decl->_id, header); } -int8_t _z_decl_token_decode(_z_decl_token_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_decl_token_decode(_z_decl_token_t *decl, _z_zbuf_t *zbf, uint8_t header) { bool has_ext; *decl = _z_decl_token_null(); _Z_RETURN_IF_ERR(_z_decl_commons_decode(zbf, header, &has_ext, &decl->_id, &decl->_keyexpr)); @@ -307,11 +309,11 @@ int8_t _z_decl_token_decode(_z_decl_token_t *decl, _z_zbuf_t *zbf, uint8_t heade } return _Z_RES_OK; } -int8_t _z_undecl_token_decode(_z_undecl_token_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_undecl_token_decode(_z_undecl_token_t *decl, _z_zbuf_t *zbf, uint8_t header) { return _z_undecl_trivial_decode(zbf, &decl->_ext_keyexpr, &decl->_id, header); } -int8_t _z_decl_final_decode(_z_decl_final_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_decl_final_decode(_z_decl_final_t *decl, _z_zbuf_t *zbf, uint8_t header) { // Nothing to do _ZP_UNUSED(decl); if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) { @@ -320,10 +322,10 @@ int8_t _z_decl_final_decode(_z_decl_final_t *decl, _z_zbuf_t *zbf, uint8_t heade return _Z_RES_OK; } -int8_t _z_declaration_decode(_z_declaration_t *decl, _z_zbuf_t *zbf) { +z_result_t _z_declaration_decode(_z_declaration_t *decl, _z_zbuf_t *zbf) { uint8_t header; _Z_RETURN_IF_ERR(_z_uint8_decode(&header, zbf)); - int8_t ret; + z_result_t ret; switch (_Z_MID(header)) { case _Z_DECL_KEXPR_MID: { decl->_tag = _Z_DECL_KEXPR; diff --git a/src/protocol/codec/ext.c b/src/protocol/codec/ext.c index 2c7aab699..e22b431b3 100644 --- a/src/protocol/codec/ext.c +++ b/src/protocol/codec/ext.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/protocol/ext.h" +#include "zenoh-pico/protocol/codec/ext.h" #include #include @@ -20,58 +20,64 @@ #include "zenoh-pico/collections/slice.h" #include "zenoh-pico/protocol/codec.h" -#include "zenoh-pico/protocol/codec/ext.h" +#include "zenoh-pico/protocol/ext.h" #include "zenoh-pico/system/platform.h" #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/result.h" -int8_t _z_msg_ext_encode_unit(_z_wbuf_t *wbf, const _z_msg_ext_unit_t *ext) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_encode_unit(_z_wbuf_t *wbf, const _z_msg_ext_unit_t *ext) { + z_result_t ret = _Z_RES_OK; (void)(wbf); (void)(ext); return ret; } -int8_t _z_msg_ext_decode_unit(_z_msg_ext_unit_t *ext, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_decode_unit(_z_msg_ext_unit_t *ext, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; (void)(zbf); (void)(ext); return ret; } -int8_t _z_msg_ext_decode_unit_na(_z_msg_ext_unit_t *ext, _z_zbuf_t *zbf) { return _z_msg_ext_decode_unit(ext, zbf); } +z_result_t _z_msg_ext_decode_unit_na(_z_msg_ext_unit_t *ext, _z_zbuf_t *zbf) { + return _z_msg_ext_decode_unit(ext, zbf); +} -int8_t _z_msg_ext_encode_zint(_z_wbuf_t *wbf, const _z_msg_ext_zint_t *ext) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_encode_zint(_z_wbuf_t *wbf, const _z_msg_ext_zint_t *ext) { + z_result_t ret = _Z_RES_OK; _Z_RETURN_IF_ERR(_z_zint64_encode(wbf, ext->_val)) return ret; } -int8_t _z_msg_ext_decode_zint(_z_msg_ext_zint_t *ext, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_decode_zint(_z_msg_ext_zint_t *ext, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; ret |= _z_zint64_decode(&ext->_val, zbf); return ret; } -int8_t _z_msg_ext_decode_zint_na(_z_msg_ext_zint_t *ext, _z_zbuf_t *zbf) { return _z_msg_ext_decode_zint(ext, zbf); } +z_result_t _z_msg_ext_decode_zint_na(_z_msg_ext_zint_t *ext, _z_zbuf_t *zbf) { + return _z_msg_ext_decode_zint(ext, zbf); +} -int8_t _z_msg_ext_encode_zbuf(_z_wbuf_t *wbf, const _z_msg_ext_zbuf_t *ext) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_encode_zbuf(_z_wbuf_t *wbf, const _z_msg_ext_zbuf_t *ext) { + z_result_t ret = _Z_RES_OK; _Z_RETURN_IF_ERR(_z_slice_encode(wbf, &ext->_val)) return ret; } -int8_t _z_msg_ext_decode_zbuf(_z_msg_ext_zbuf_t *ext, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_decode_zbuf(_z_msg_ext_zbuf_t *ext, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; ret |= _z_slice_decode(&ext->_val, zbf); return ret; } -int8_t _z_msg_ext_decode_zbuf_na(_z_msg_ext_zbuf_t *ext, _z_zbuf_t *zbf) { return _z_msg_ext_decode_zbuf(ext, zbf); } +z_result_t _z_msg_ext_decode_zbuf_na(_z_msg_ext_zbuf_t *ext, _z_zbuf_t *zbf) { + return _z_msg_ext_decode_zbuf(ext, zbf); +} /*------------------ Message Extension ------------------*/ -int8_t _z_msg_ext_encode(_z_wbuf_t *wbf, const _z_msg_ext_t *ext, bool has_next) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_encode(_z_wbuf_t *wbf, const _z_msg_ext_t *ext, bool has_next) { + z_result_t ret = _Z_RES_OK; _Z_RETURN_IF_ERR(_z_wbuf_write(wbf, _Z_EXT_FULL_ID(ext->_header) | (has_next << 7))) @@ -97,8 +103,8 @@ int8_t _z_msg_ext_encode(_z_wbuf_t *wbf, const _z_msg_ext_t *ext, bool has_next) return ret; } -int8_t _z_msg_ext_unknown_body_decode(_z_msg_ext_body_t *body, uint8_t enc, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_unknown_body_decode(_z_msg_ext_body_t *body, uint8_t enc, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; switch (enc) { case _Z_MSG_EXT_ENC_UNIT: { @@ -121,8 +127,8 @@ int8_t _z_msg_ext_unknown_body_decode(_z_msg_ext_body_t *body, uint8_t enc, _z_z return ret; } -int8_t _z_msg_ext_decode(_z_msg_ext_t *ext, _z_zbuf_t *zbf, bool *has_next) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_decode(_z_msg_ext_t *ext, _z_zbuf_t *zbf, bool *has_next) { + z_result_t ret = _Z_RES_OK; ret |= _z_uint8_decode(&ext->_header, zbf); // Decode the header if (ret == _Z_RES_OK) { @@ -135,12 +141,12 @@ int8_t _z_msg_ext_decode(_z_msg_ext_t *ext, _z_zbuf_t *zbf, bool *has_next) { return ret; } -int8_t _z_msg_ext_decode_na(_z_msg_ext_t *ext, _z_zbuf_t *zbf, bool *has_next) { +z_result_t _z_msg_ext_decode_na(_z_msg_ext_t *ext, _z_zbuf_t *zbf, bool *has_next) { return _z_msg_ext_decode(ext, zbf, has_next); } -int8_t _z_msg_ext_vec_encode(_z_wbuf_t *wbf, const _z_msg_ext_vec_t *extensions) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_vec_encode(_z_wbuf_t *wbf, const _z_msg_ext_vec_t *extensions) { + z_result_t ret = _Z_RES_OK; size_t len = _z_msg_ext_vec_len(extensions); if (len > 0) { size_t i; @@ -153,20 +159,20 @@ int8_t _z_msg_ext_vec_encode(_z_wbuf_t *wbf, const _z_msg_ext_vec_t *extensions) } return ret; } -int8_t _z_msg_ext_vec_push_callback(_z_msg_ext_t *extension, _z_msg_ext_vec_t *extensions) { +z_result_t _z_msg_ext_vec_push_callback(_z_msg_ext_t *extension, _z_msg_ext_vec_t *extensions) { _z_msg_ext_t *ext = (_z_msg_ext_t *)z_malloc(sizeof(_z_msg_ext_t)); *ext = *extension; *extension = _z_msg_ext_make_unit(0); _z_msg_ext_vec_append(extensions, extension); return 0; } -int8_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf) { +z_result_t _z_msg_ext_vec_decode(_z_msg_ext_vec_t *extensions, _z_zbuf_t *zbf) { _z_msg_ext_vec_reset(extensions); - return _z_msg_ext_decode_iter(zbf, (int8_t(*)(_z_msg_ext_t *, void *))_z_msg_ext_vec_push_callback, + return _z_msg_ext_decode_iter(zbf, (z_result_t(*)(_z_msg_ext_t *, void *))_z_msg_ext_vec_push_callback, (void *)extensions); } -int8_t _z_msg_ext_unknown_error(_z_msg_ext_t *extension, uint8_t trace_id) { +z_result_t _z_msg_ext_unknown_error(_z_msg_ext_t *extension, uint8_t trace_id) { #if (ZENOH_DEBUG >= 1) uint8_t ext_id = _Z_EXT_ID(extension->_header); switch (_Z_EXT_ENC(extension->_header)) { @@ -202,8 +208,8 @@ int8_t _z_msg_ext_unknown_error(_z_msg_ext_t *extension, uint8_t trace_id) { return _Z_ERR_MESSAGE_EXTENSION_MANDATORY_AND_UNKNOWN; } -int8_t _z_msg_ext_skip_non_mandatory(_z_msg_ext_t *extension, void *ctx) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_skip_non_mandatory(_z_msg_ext_t *extension, void *ctx) { + z_result_t ret = _Z_RES_OK; if ((extension->_header & _Z_MSG_EXT_FLAG_M) != 0) { uint8_t trace_id = *(uint8_t *)ctx; ret = _z_msg_ext_unknown_error(extension, trace_id); @@ -211,8 +217,8 @@ int8_t _z_msg_ext_skip_non_mandatory(_z_msg_ext_t *extension, void *ctx) { return ret; } -int8_t _z_msg_ext_decode_iter(_z_zbuf_t *zbf, int8_t (*callback)(_z_msg_ext_t *, void *), void *context) { - int8_t ret = _Z_RES_OK; +z_result_t _z_msg_ext_decode_iter(_z_zbuf_t *zbf, z_result_t (*callback)(_z_msg_ext_t *, void *), void *context) { + z_result_t ret = _Z_RES_OK; bool has_next = true; while (has_next && ret == _Z_RES_OK) { _z_msg_ext_t ext = _z_msg_ext_make_unit(0); @@ -225,6 +231,6 @@ int8_t _z_msg_ext_decode_iter(_z_zbuf_t *zbf, int8_t (*callback)(_z_msg_ext_t *, return ret; } -int8_t _z_msg_ext_skip_non_mandatories(_z_zbuf_t *zbf, uint8_t trace_id) { +z_result_t _z_msg_ext_skip_non_mandatories(_z_zbuf_t *zbf, uint8_t trace_id) { return _z_msg_ext_decode_iter(zbf, _z_msg_ext_skip_non_mandatory, &trace_id); } diff --git a/src/protocol/codec/interest.c b/src/protocol/codec/interest.c index 391699b8f..aeec2fc3d 100644 --- a/src/protocol/codec/interest.c +++ b/src/protocol/codec/interest.c @@ -39,7 +39,7 @@ #define _Z_INTEREST_TRACE_ID 0x13 -int8_t _z_interest_encode(_z_wbuf_t *wbf, const _z_interest_t *interest, bool is_final) { +z_result_t _z_interest_encode(_z_wbuf_t *wbf, const _z_interest_t *interest, bool is_final) { // Set id _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, interest->_id)); if (is_final) { @@ -69,7 +69,7 @@ int8_t _z_interest_encode(_z_wbuf_t *wbf, const _z_interest_t *interest, bool is return _Z_RES_OK; } -int8_t _z_interest_decode(_z_interest_t *interest, _z_zbuf_t *zbf, bool is_final, bool has_ext) { +z_result_t _z_interest_decode(_z_interest_t *interest, _z_zbuf_t *zbf, bool is_final, bool has_ext) { // Decode id _Z_RETURN_IF_ERR(_z_zint32_decode(&interest->_id, zbf)); if (!is_final) { diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index 0d1bdffdd..f2bdf6bfb 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -40,23 +40,23 @@ /* Fields */ /*=============================*/ /*------------------ Payload field ------------------*/ -int8_t _z_payload_encode(_z_wbuf_t *wbf, const _z_slice_t *pld) { - int8_t ret = _Z_RES_OK; +z_result_t _z_payload_encode(_z_wbuf_t *wbf, const _z_slice_t *pld) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _PAYLOAD"); ret |= _z_slice_encode(wbf, pld); return ret; } -int8_t _z_payload_decode_na(_z_slice_t *pld, _z_zbuf_t *zbf) { +z_result_t _z_payload_decode_na(_z_slice_t *pld, _z_zbuf_t *zbf) { _Z_DEBUG("Decoding _PAYLOAD"); return _z_slice_decode(pld, zbf); } -int8_t _z_payload_decode(_z_slice_t *pld, _z_zbuf_t *zbf) { return _z_payload_decode_na(pld, zbf); } +z_result_t _z_payload_decode(_z_slice_t *pld, _z_zbuf_t *zbf) { return _z_payload_decode_na(pld, zbf); } -int8_t _z_id_encode_as_slice(_z_wbuf_t *wbf, const _z_id_t *id) { - int8_t ret = _Z_RES_OK; +z_result_t _z_id_encode_as_slice(_z_wbuf_t *wbf, const _z_id_t *id) { + z_result_t ret = _Z_RES_OK; uint8_t len = _z_id_len(*id); if (len != 0) { @@ -73,8 +73,8 @@ int8_t _z_id_encode_as_slice(_z_wbuf_t *wbf, const _z_id_t *id) { /// /// Note that while `_z_id_t` has an error state (full 0s), this function doesn't /// guarantee that this state will be set in case of errors. -int8_t _z_id_decode_as_slice(_z_id_t *id, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_id_decode_as_slice(_z_id_t *id, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; uint8_t len = _z_zbuf_read(zbf); _z_zbuf_read_bytes(zbf, id->id, 0, len); memset(id->id + len, 0, 16 - len); @@ -82,8 +82,8 @@ int8_t _z_id_decode_as_slice(_z_id_t *id, _z_zbuf_t *zbf) { } /*------------------ Timestamp Field ------------------*/ -int8_t _z_timestamp_encode(_z_wbuf_t *wbf, const _z_timestamp_t *ts) { - int8_t ret = _Z_RES_OK; +z_result_t _z_timestamp_encode(_z_wbuf_t *wbf, const _z_timestamp_t *ts) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _TIMESTAMP"); _Z_RETURN_IF_ERR(_z_zint64_encode(wbf, ts->time)) @@ -91,16 +91,16 @@ int8_t _z_timestamp_encode(_z_wbuf_t *wbf, const _z_timestamp_t *ts) { return ret; } -int8_t _z_timestamp_encode_ext(_z_wbuf_t *wbf, const _z_timestamp_t *ts) { +z_result_t _z_timestamp_encode_ext(_z_wbuf_t *wbf, const _z_timestamp_t *ts) { // Encode extension size then timestamp size_t ext_size = (size_t)(_z_zint_len(ts->time) + 1 + _z_id_len(ts->id)); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, ext_size)); return _z_timestamp_encode(wbf, ts); } -int8_t _z_timestamp_decode(_z_timestamp_t *ts, _z_zbuf_t *zbf) { +z_result_t _z_timestamp_decode(_z_timestamp_t *ts, _z_zbuf_t *zbf) { _Z_DEBUG("Decoding _TIMESTAMP"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; ret |= _z_zint64_decode(&ts->time, zbf); ret |= _z_id_decode_as_slice(&ts->id, zbf); @@ -109,8 +109,8 @@ int8_t _z_timestamp_decode(_z_timestamp_t *ts, _z_zbuf_t *zbf) { } /*------------------ ResKey Field ------------------*/ -int8_t _z_keyexpr_encode(_z_wbuf_t *wbf, bool has_suffix, const _z_keyexpr_t *fld) { - int8_t ret = _Z_RES_OK; +z_result_t _z_keyexpr_encode(_z_wbuf_t *wbf, bool has_suffix, const _z_keyexpr_t *fld) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _RESKEY"); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, fld->_id)) @@ -121,9 +121,9 @@ int8_t _z_keyexpr_encode(_z_wbuf_t *wbf, bool has_suffix, const _z_keyexpr_t *fl return ret; } -int8_t _z_keyexpr_decode(_z_keyexpr_t *ke, _z_zbuf_t *zbf, bool has_suffix) { +z_result_t _z_keyexpr_decode(_z_keyexpr_t *ke, _z_zbuf_t *zbf, bool has_suffix) { _Z_DEBUG("Decoding _RESKEY"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; ret |= _z_zint16_decode(&ke->_id, zbf); if (has_suffix == true) { @@ -144,8 +144,8 @@ int8_t _z_keyexpr_decode(_z_keyexpr_t *ke, _z_zbuf_t *zbf, bool has_suffix) { } /*------------------ Locators Field ------------------*/ -int8_t _z_locators_encode(_z_wbuf_t *wbf, const _z_locator_array_t *la) { - int8_t ret = _Z_RES_OK; +z_result_t _z_locators_encode(_z_wbuf_t *wbf, const _z_locator_array_t *la) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _LOCATORS"); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, la->_len)) for (size_t i = 0; i < la->_len; i++) { @@ -157,9 +157,9 @@ int8_t _z_locators_encode(_z_wbuf_t *wbf, const _z_locator_array_t *la) { return ret; } -int8_t _z_locators_decode_na(_z_locator_array_t *a_loc, _z_zbuf_t *zbf) { +z_result_t _z_locators_decode_na(_z_locator_array_t *a_loc, _z_zbuf_t *zbf) { _Z_DEBUG("Decoding _LOCATORS"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; _z_zint_t len = 0; // Number of elements in the array ret |= _z_zsize_decode(&len, zbf); @@ -185,16 +185,16 @@ int8_t _z_locators_decode_na(_z_locator_array_t *a_loc, _z_zbuf_t *zbf) { return ret; } -int8_t _z_locators_decode(_z_locator_array_t *a_loc, _z_zbuf_t *zbf) { return _z_locators_decode_na(a_loc, zbf); } +z_result_t _z_locators_decode(_z_locator_array_t *a_loc, _z_zbuf_t *zbf) { return _z_locators_decode_na(a_loc, zbf); } /*=============================*/ /* Zenoh Messages */ /*=============================*/ -int8_t _z_source_info_decode(_z_source_info_t *info, _z_zbuf_t *zbf) { +z_result_t _z_source_info_decode(_z_source_info_t *info, _z_zbuf_t *zbf) { uint8_t zidlen = 0; _z_zint_t intbuf; - int8_t ret = _z_uint8_decode(&zidlen, zbf); + z_result_t ret = _z_uint8_decode(&zidlen, zbf); if (ret == _Z_RES_OK) { zidlen >>= 4; if (_z_zbuf_len(zbf) >= zidlen) { @@ -221,8 +221,8 @@ int8_t _z_source_info_decode(_z_source_info_t *info, _z_zbuf_t *zbf) { } return ret; } -int8_t _z_source_info_encode(_z_wbuf_t *wbf, const _z_source_info_t *info) { - int8_t ret = 0; +z_result_t _z_source_info_encode(_z_wbuf_t *wbf, const _z_source_info_t *info) { + z_result_t ret = 0; uint8_t zidlen = _z_id_len(info->_id); ret |= _z_uint8_encode(wbf, zidlen << 4); _z_slice_t zid = _z_slice_alias_buf(info->_id.id, zidlen); @@ -231,8 +231,8 @@ int8_t _z_source_info_encode(_z_wbuf_t *wbf, const _z_source_info_t *info) { ret |= _z_zsize_encode(wbf, info->_source_sn); return ret; } -int8_t _z_source_info_encode_ext(_z_wbuf_t *wbf, const _z_source_info_t *info) { - int8_t ret = 0; +z_result_t _z_source_info_encode_ext(_z_wbuf_t *wbf, const _z_source_info_t *info) { + z_result_t ret = 0; uint8_t zidlen = _z_id_len(info->_id); size_t ext_size = 1u + zidlen + _z_zint_len(info->_entity_id) + _z_zint_len(info->_source_sn); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, ext_size)); @@ -245,7 +245,7 @@ int8_t _z_source_info_encode_ext(_z_wbuf_t *wbf, const _z_source_info_t *info) { } /*------------------ Push Body Field ------------------*/ -int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb) { +z_result_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb) { (void)(wbf); (void)(pshb); uint8_t header = pshb->_is_put ? _Z_MID_Z_PUT : _Z_MID_Z_DEL; @@ -295,9 +295,9 @@ int8_t _z_push_body_encode(_z_wbuf_t *wbf, const _z_push_body_t *pshb) { return 0; } -int8_t _z_push_body_decode_extensions(_z_msg_ext_t *extension, void *ctx) { +z_result_t _z_push_body_decode_extensions(_z_msg_ext_t *extension, void *ctx) { _z_push_body_t *pshb = (_z_push_body_t *)ctx; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; switch (_Z_EXT_FULL_ID(extension->_header)) { case _Z_MSG_EXT_ENC_ZBUF | 0x01: { _z_zbuf_t zbf = _z_slice_as_zbuf(extension->_body._zbuf._val); @@ -322,8 +322,8 @@ int8_t _z_push_body_decode_extensions(_z_msg_ext_t *extension, void *ctx) { return ret; } -int8_t _z_push_body_decode(_z_push_body_t *pshb, _z_zbuf_t *zbf, uint8_t header) { - int8_t ret = _Z_RES_OK; +z_result_t _z_push_body_decode(_z_push_body_t *pshb, _z_zbuf_t *zbf, uint8_t header) { + z_result_t ret = _Z_RES_OK; switch (_Z_MID(header)) { case _Z_MID_Z_PUT: { pshb->_is_put = true; @@ -360,33 +360,33 @@ int8_t _z_push_body_decode(_z_push_body_t *pshb, _z_zbuf_t *zbf, uint8_t header) return ret; } -int8_t _z_put_encode(_z_wbuf_t *wbf, const _z_msg_put_t *put) { +z_result_t _z_put_encode(_z_wbuf_t *wbf, const _z_msg_put_t *put) { _z_push_body_t body = {._is_put = true, ._body = {._put = *put}}; return _z_push_body_encode(wbf, &body); } -int8_t _z_put_decode(_z_msg_put_t *put, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_put_decode(_z_msg_put_t *put, _z_zbuf_t *zbf, uint8_t header) { assert(_Z_MID(header) == _Z_MID_Z_PUT); _z_push_body_t body = {._is_put = true, ._body = {._put = *put}}; - int8_t ret = _z_push_body_decode(&body, zbf, header); + z_result_t ret = _z_push_body_decode(&body, zbf, header); *put = body._body._put; return ret; } -int8_t _z_del_encode(_z_wbuf_t *wbf, const _z_msg_del_t *del) { +z_result_t _z_del_encode(_z_wbuf_t *wbf, const _z_msg_del_t *del) { _z_push_body_t body = {._is_put = false, ._body = {._del = *del}}; return _z_push_body_encode(wbf, &body); } -int8_t _z_del_decode(_z_msg_del_t *del, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_del_decode(_z_msg_del_t *del, _z_zbuf_t *zbf, uint8_t header) { assert(_Z_MID(header) == _Z_MID_Z_DEL); _z_push_body_t body = {._is_put = false, ._body = {._del = *del}}; - int8_t ret = _z_push_body_decode(&body, zbf, header); + z_result_t ret = _z_push_body_decode(&body, zbf, header); *del = body._body._del; return ret; } /*------------------ Query Message ------------------*/ -int8_t _z_query_encode(_z_wbuf_t *wbf, const _z_msg_query_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_query_encode(_z_wbuf_t *wbf, const _z_msg_query_t *msg) { + z_result_t ret = _Z_RES_OK; uint8_t header = _Z_MID_Z_QUERY; bool has_params = _z_slice_check(&msg->_parameters); @@ -431,9 +431,9 @@ int8_t _z_query_encode(_z_wbuf_t *wbf, const _z_msg_query_t *msg) { return ret; } -int8_t _z_query_decode_extensions(_z_msg_ext_t *extension, void *ctx) { +z_result_t _z_query_decode_extensions(_z_msg_ext_t *extension, void *ctx) { _z_msg_query_t *msg = (_z_msg_query_t *)ctx; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; switch (_Z_EXT_FULL_ID(extension->_header)) { case _Z_MSG_EXT_ENC_ZBUF | 0x01: { // Source Info _z_zbuf_t zbf = _z_slice_as_zbuf(extension->_body._zbuf._val); @@ -463,10 +463,10 @@ int8_t _z_query_decode_extensions(_z_msg_ext_t *extension, void *ctx) { return ret; } -int8_t _z_query_decode(_z_msg_query_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_query_decode(_z_msg_query_t *msg, _z_zbuf_t *zbf, uint8_t header) { _Z_DEBUG("Decoding _Z_MID_Z_QUERY"); *msg = (_z_msg_query_t){0}; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Q_C)) { _Z_RETURN_IF_ERR(_z_uint8_decode((uint8_t *)&msg->_consolidation, zbf)); @@ -484,7 +484,7 @@ int8_t _z_query_decode(_z_msg_query_t *msg, _z_zbuf_t *zbf, uint8_t header) { return ret; } -int8_t _z_reply_encode(_z_wbuf_t *wbf, const _z_msg_reply_t *reply) { +z_result_t _z_reply_encode(_z_wbuf_t *wbf, const _z_msg_reply_t *reply) { uint8_t header = _Z_MID_Z_REPLY; bool has_consolidation = reply->_consolidation != Z_CONSOLIDATION_MODE_DEFAULT; if (has_consolidation) { @@ -497,9 +497,9 @@ int8_t _z_reply_encode(_z_wbuf_t *wbf, const _z_msg_reply_t *reply) { _Z_RETURN_IF_ERR(_z_push_body_encode(wbf, &reply->_body)); return _Z_RES_OK; } -int8_t _z_reply_decode_extension(_z_msg_ext_t *extension, void *ctx) { +z_result_t _z_reply_decode_extension(_z_msg_ext_t *extension, void *ctx) { _ZP_UNUSED(ctx); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; switch (_Z_EXT_FULL_ID(extension->_header)) { default: ret = _z_msg_ext_unknown_error(extension, 0x0a); @@ -507,7 +507,7 @@ int8_t _z_reply_decode_extension(_z_msg_ext_t *extension, void *ctx) { } return ret; } -int8_t _z_reply_decode(_z_msg_reply_t *reply, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_reply_decode(_z_msg_reply_t *reply, _z_zbuf_t *zbf, uint8_t header) { *reply = (_z_msg_reply_t){0}; if (_Z_HAS_FLAG(header, _Z_FLAG_Z_R_C)) { _Z_RETURN_IF_ERR(_z_uint8_decode((uint8_t *)&reply->_consolidation, zbf)); @@ -523,8 +523,8 @@ int8_t _z_reply_decode(_z_msg_reply_t *reply, _z_zbuf_t *zbf, uint8_t header) { return _Z_RES_OK; } -int8_t _z_err_encode(_z_wbuf_t *wbf, const _z_msg_err_t *err) { - int8_t ret = _Z_RES_OK; +z_result_t _z_err_encode(_z_wbuf_t *wbf, const _z_msg_err_t *err) { + z_result_t ret = _Z_RES_OK; uint8_t header = _Z_MID_Z_ERR; // Encode header @@ -552,8 +552,8 @@ int8_t _z_err_encode(_z_wbuf_t *wbf, const _z_msg_err_t *err) { _Z_RETURN_IF_ERR(_z_bytes_encode(wbf, &err->_payload)); return ret; } -int8_t _z_err_decode_extension(_z_msg_ext_t *extension, void *ctx) { - int8_t ret = _Z_RES_OK; +z_result_t _z_err_decode_extension(_z_msg_ext_t *extension, void *ctx) { + z_result_t ret = _Z_RES_OK; _z_msg_err_t *reply = (_z_msg_err_t *)ctx; switch (_Z_EXT_FULL_ID(extension->_header)) { case _Z_MSG_EXT_ENC_ZBUF | 0x01: { @@ -568,7 +568,7 @@ int8_t _z_err_decode_extension(_z_msg_ext_t *extension, void *ctx) { } return ret; } -int8_t _z_err_decode(_z_msg_err_t *err, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_err_decode(_z_msg_err_t *err, _z_zbuf_t *zbf, uint8_t header) { *err = (_z_msg_err_t){0}; if (_Z_HAS_FLAG(header, _Z_FLAG_Z_E_E)) { @@ -585,8 +585,8 @@ int8_t _z_err_decode(_z_msg_err_t *err, _z_zbuf_t *zbf, uint8_t header) { /* Scouting Messages */ /*=============================*/ /*------------------ Scout Message ------------------*/ -int8_t _z_scout_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_scout_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_scout_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_scout_t *msg) { + z_result_t ret = _Z_RES_OK; (void)(header); _Z_DEBUG("Encoding _Z_MID_SCOUT"); @@ -606,8 +606,8 @@ int8_t _z_scout_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_scout_t *m return ret; } -int8_t _z_scout_decode(_z_s_msg_scout_t *msg, _z_zbuf_t *zbf, uint8_t header) { - int8_t ret = _Z_RES_OK; +z_result_t _z_scout_decode(_z_s_msg_scout_t *msg, _z_zbuf_t *zbf, uint8_t header) { + z_result_t ret = _Z_RES_OK; (void)(header); _Z_DEBUG("Decoding _Z_MID_SCOUT"); *msg = (_z_s_msg_scout_t){0}; @@ -627,8 +627,8 @@ int8_t _z_scout_decode(_z_s_msg_scout_t *msg, _z_zbuf_t *zbf, uint8_t header) { } /*------------------ Hello Message ------------------*/ -int8_t _z_hello_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_hello_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_hello_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_hello_t *msg) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _Z_MID_HELLO"); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, msg->_version)) @@ -647,9 +647,9 @@ int8_t _z_hello_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_hello_t *m return ret; } -int8_t _z_hello_decode_na(_z_s_msg_hello_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_hello_decode_na(_z_s_msg_hello_t *msg, _z_zbuf_t *zbf, uint8_t header) { _Z_DEBUG("Decoding _Z_MID_HELLO"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; *msg = (_z_s_msg_hello_t){0}; ret |= _z_uint8_decode(&msg->_version, zbf); @@ -678,12 +678,12 @@ int8_t _z_hello_decode_na(_z_s_msg_hello_t *msg, _z_zbuf_t *zbf, uint8_t header) return ret; } -int8_t _z_hello_decode(_z_s_msg_hello_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_hello_decode(_z_s_msg_hello_t *msg, _z_zbuf_t *zbf, uint8_t header) { return _z_hello_decode_na(msg, zbf, header); } -int8_t _z_scouting_message_encode(_z_wbuf_t *wbf, const _z_scouting_message_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_scouting_message_encode(_z_wbuf_t *wbf, const _z_scouting_message_t *msg) { + z_result_t ret = _Z_RES_OK; uint8_t header = msg->_header; @@ -705,8 +705,8 @@ int8_t _z_scouting_message_encode(_z_wbuf_t *wbf, const _z_scouting_message_t *m return ret; } -int8_t _z_scouting_message_decode_na(_z_scouting_message_t *msg, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_scouting_message_decode_na(_z_scouting_message_t *msg, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; *msg = (_z_scouting_message_t){0}; bool is_last = false; @@ -744,6 +744,6 @@ int8_t _z_scouting_message_decode_na(_z_scouting_message_t *msg, _z_zbuf_t *zbf) return ret; } -int8_t _z_scouting_message_decode(_z_scouting_message_t *s_msg, _z_zbuf_t *zbf) { +z_result_t _z_scouting_message_decode(_z_scouting_message_t *s_msg, _z_zbuf_t *zbf) { return _z_scouting_message_decode_na(s_msg, zbf); } diff --git a/src/protocol/codec/network.c b/src/protocol/codec/network.c index 2b8d73867..426c6d150 100644 --- a/src/protocol/codec/network.c +++ b/src/protocol/codec/network.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/protocol/definitions/network.h" +#include "zenoh-pico/protocol/codec/network.h" #include #include @@ -26,11 +26,11 @@ #include "zenoh-pico/protocol/codec/declarations.h" #include "zenoh-pico/protocol/codec/ext.h" #include "zenoh-pico/protocol/codec/interest.h" -#include "zenoh-pico/protocol/codec/network.h" #include "zenoh-pico/protocol/core.h" #include "zenoh-pico/protocol/definitions/core.h" #include "zenoh-pico/protocol/definitions/interest.h" #include "zenoh-pico/protocol/definitions/message.h" +#include "zenoh-pico/protocol/definitions/network.h" #include "zenoh-pico/protocol/ext.h" #include "zenoh-pico/protocol/iobuf.h" #include "zenoh-pico/utils/logging.h" @@ -38,7 +38,7 @@ /*------------------ Push Message ------------------*/ -int8_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg) { +z_result_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg) { uint8_t header = _Z_MID_N_PUSH | (_z_keyexpr_is_local(&msg->_key) ? _Z_FLAG_N_REQUEST_M : 0); bool has_suffix = _z_keyexpr_has_suffix(&msg->_key); bool has_qos_ext = msg->_qos._val != _Z_N_QOS_DEFAULT._val; @@ -67,8 +67,8 @@ int8_t _z_push_encode(_z_wbuf_t *wbf, const _z_n_msg_push_t *msg) { return _Z_RES_OK; } -int8_t _z_push_decode_ext_cb(_z_msg_ext_t *extension, void *ctx) { - int8_t ret = _Z_RES_OK; +z_result_t _z_push_decode_ext_cb(_z_msg_ext_t *extension, void *ctx) { + z_result_t ret = _Z_RES_OK; _z_n_msg_push_t *msg = (_z_n_msg_push_t *)ctx; switch (_Z_EXT_FULL_ID(extension->_header)) { case _Z_MSG_EXT_ENC_ZINT | 0x01: { // QOS ext @@ -91,8 +91,8 @@ int8_t _z_push_decode_ext_cb(_z_msg_ext_t *extension, void *ctx) { return ret; } -int8_t _z_push_decode(_z_n_msg_push_t *msg, _z_zbuf_t *zbf, uint8_t header) { - int8_t ret = _Z_RES_OK; +z_result_t _z_push_decode(_z_n_msg_push_t *msg, _z_zbuf_t *zbf, uint8_t header) { + z_result_t ret = _Z_RES_OK; *msg = (_z_n_msg_push_t){0}; msg->_qos = _Z_N_QOS_DEFAULT; ret |= _z_keyexpr_decode(&msg->_key, zbf, _Z_HAS_FLAG(header, _Z_FLAG_N_PUSH_N)); @@ -111,8 +111,8 @@ int8_t _z_push_decode(_z_n_msg_push_t *msg, _z_zbuf_t *zbf, uint8_t header) { } /*------------------ Request Message ------------------*/ -int8_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg) { + z_result_t ret = _Z_RES_OK; uint8_t header = _Z_MID_N_REQUEST | (_z_keyexpr_is_local(&msg->_key) ? _Z_FLAG_N_REQUEST_M : 0); bool has_suffix = _z_keyexpr_has_suffix(&msg->_key); if (has_suffix) { @@ -167,7 +167,7 @@ int8_t _z_request_encode(_z_wbuf_t *wbf, const _z_n_msg_request_t *msg) { } return ret; } -int8_t _z_request_decode_extensions(_z_msg_ext_t *extension, void *ctx) { +z_result_t _z_request_decode_extensions(_z_msg_ext_t *extension, void *ctx) { _z_n_msg_request_t *msg = (_z_n_msg_request_t *)ctx; switch (_Z_EXT_FULL_ID(extension->_header)) { case 0x01 | _Z_MSG_EXT_ENC_ZINT: { // QOS ext @@ -204,7 +204,7 @@ int8_t _z_request_decode_extensions(_z_msg_ext_t *extension, void *ctx) { } return _Z_RES_OK; } -int8_t _z_request_decode(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, const uint8_t header) { +z_result_t _z_request_decode(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, const uint8_t header) { *msg = (_z_n_msg_request_t){0}; msg->_ext_qos = _Z_N_QOS_DEFAULT; _Z_RETURN_IF_ERR(_z_zsize_decode(&msg->_rid, zbf)); @@ -236,8 +236,8 @@ int8_t _z_request_decode(_z_n_msg_request_t *msg, _z_zbuf_t *zbf, const uint8_t } /*------------------ Response Message ------------------*/ -int8_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) { + z_result_t ret = _Z_RES_OK; uint8_t header = _Z_MID_N_RESPONSE; _Z_DEBUG("Encoding _Z_MID_N_RESPONSE"); bool has_qos_ext = msg->_ext_qos._val != _Z_N_QOS_DEFAULT._val; @@ -301,8 +301,8 @@ int8_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) { return ret; } -int8_t _z_response_decode_extension(_z_msg_ext_t *extension, void *ctx) { - int8_t ret = _Z_RES_OK; +z_result_t _z_response_decode_extension(_z_msg_ext_t *extension, void *ctx) { + z_result_t ret = _Z_RES_OK; _z_n_msg_response_t *msg = (_z_n_msg_response_t *)ctx; switch (_Z_EXT_FULL_ID(extension->_header)) { case _Z_MSG_EXT_ENC_ZINT | 0x01: { @@ -332,11 +332,11 @@ int8_t _z_response_decode_extension(_z_msg_ext_t *extension, void *ctx) { return ret; } -int8_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t header) { _Z_DEBUG("Decoding _Z_MID_N_RESPONSE"); *msg = (_z_n_msg_response_t){0}; msg->_ext_qos = _Z_N_QOS_DEFAULT; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; _z_keyexpr_set_mapping(&msg->_key, _Z_HAS_FLAG(header, _Z_FLAG_N_RESPONSE_M) ? _Z_KEYEXPR_MAPPING_UNKNOWN_REMOTE : _Z_KEYEXPR_MAPPING_LOCAL); _Z_RETURN_IF_ERR(_z_zsize_decode(&msg->_request_id, zbf)); @@ -368,8 +368,8 @@ int8_t _z_response_decode(_z_n_msg_response_t *msg, _z_zbuf_t *zbf, uint8_t head } /*------------------ Response Final Message ------------------*/ -int8_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t *msg) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _Z_MID_N_RESPONSE_FINAL"); uint8_t header = _Z_MID_N_RESPONSE_FINAL; _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, header)); @@ -378,11 +378,11 @@ int8_t _z_response_final_encode(_z_wbuf_t *wbf, const _z_n_msg_response_final_t return ret; } -int8_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, uint8_t header) { (void)(header); *msg = (_z_n_msg_response_final_t){0}; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; ret |= _z_zsize_decode(&msg->_request_id, zbf); if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) { _Z_RETURN_IF_ERR(_z_msg_ext_skip_non_mandatories(zbf, 0x1a)); @@ -390,7 +390,7 @@ int8_t _z_response_final_decode(_z_n_msg_response_final_t *msg, _z_zbuf_t *zbf, return ret; } -int8_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl) { +z_result_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl) { uint8_t header = _Z_MID_N_DECLARE; bool has_qos_ext = decl->_ext_qos._val != _Z_N_QOS_DEFAULT._val; bool has_timestamp_ext = _z_timestamp_check(&decl->_ext_timestamp); @@ -421,7 +421,7 @@ int8_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl) { // Encode declaration return _z_declaration_encode(wbf, &decl->_decl); } -int8_t _z_declare_decode_extensions(_z_msg_ext_t *extension, void *ctx) { +z_result_t _z_declare_decode_extensions(_z_msg_ext_t *extension, void *ctx) { _z_n_msg_declare_t *decl = (_z_n_msg_declare_t *)ctx; switch (_Z_EXT_FULL_ID(extension->_header)) { case _Z_MSG_EXT_ENC_ZINT | 0x01: { @@ -439,7 +439,7 @@ int8_t _z_declare_decode_extensions(_z_msg_ext_t *extension, void *ctx) { } return _Z_RES_OK; } -int8_t _z_declare_decode(_z_n_msg_declare_t *decl, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_declare_decode(_z_n_msg_declare_t *decl, _z_zbuf_t *zbf, uint8_t header) { *decl = (_z_n_msg_declare_t){0}; decl->_ext_qos = _Z_N_QOS_DEFAULT; // Retrieve interest id @@ -455,7 +455,7 @@ int8_t _z_declare_decode(_z_n_msg_declare_t *decl, _z_zbuf_t *zbf, uint8_t heade return _z_declaration_decode(&decl->_decl, zbf); } -int8_t _z_n_interest_encode(_z_wbuf_t *wbf, const _z_n_msg_interest_t *interest) { +z_result_t _z_n_interest_encode(_z_wbuf_t *wbf, const _z_n_msg_interest_t *interest) { // Set header uint8_t header = _Z_MID_N_INTEREST; bool is_final = true; @@ -471,7 +471,7 @@ int8_t _z_n_interest_encode(_z_wbuf_t *wbf, const _z_n_msg_interest_t *interest) return _z_interest_encode(wbf, &interest->_interest, is_final); } -int8_t _z_n_interest_decode(_z_n_msg_interest_t *interest, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_n_interest_decode(_z_n_msg_interest_t *interest, _z_zbuf_t *zbf, uint8_t header) { interest->_interest = _z_interest_null(); bool is_final = true; bool has_ext = false; @@ -491,7 +491,7 @@ int8_t _z_n_interest_decode(_z_n_msg_interest_t *interest, _z_zbuf_t *zbf, uint8 return _z_interest_decode(&interest->_interest, zbf, is_final, has_ext); } -int8_t _z_network_message_encode(_z_wbuf_t *wbf, const _z_network_message_t *msg) { +z_result_t _z_network_message_encode(_z_wbuf_t *wbf, const _z_network_message_t *msg) { switch (msg->_tag) { case _Z_N_DECLARE: { return _z_declare_encode(wbf, &msg->_body._declare); @@ -515,7 +515,7 @@ int8_t _z_network_message_encode(_z_wbuf_t *wbf, const _z_network_message_t *msg return _Z_ERR_GENERIC; } } -int8_t _z_network_message_decode(_z_network_message_t *msg, _z_zbuf_t *zbf) { +z_result_t _z_network_message_decode(_z_network_message_t *msg, _z_zbuf_t *zbf) { uint8_t header; _Z_RETURN_IF_ERR(_z_uint8_decode(&header, zbf)); switch (_Z_MID(header)) { diff --git a/src/protocol/codec/transport.c b/src/protocol/codec/transport.c index 90b8efbba..7eff8715b 100644 --- a/src/protocol/codec/transport.c +++ b/src/protocol/codec/transport.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/protocol/definitions/transport.h" +#include "zenoh-pico/protocol/codec/transport.h" #include #include @@ -21,8 +21,8 @@ #include "zenoh-pico/protocol/codec/core.h" #include "zenoh-pico/protocol/codec/ext.h" #include "zenoh-pico/protocol/codec/network.h" -#include "zenoh-pico/protocol/codec/transport.h" #include "zenoh-pico/protocol/definitions/core.h" +#include "zenoh-pico/protocol/definitions/transport.h" #include "zenoh-pico/protocol/ext.h" #include "zenoh-pico/protocol/iobuf.h" #include "zenoh-pico/utils/logging.h" @@ -37,8 +37,8 @@ z_whatami_t _z_whatami_from_uint8(uint8_t b) { } /*------------------ Join Message ------------------*/ -int8_t _z_join_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_join_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_join_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_join_t *msg) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _Z_MID_T_JOIN"); _Z_RETURN_IF_ERR(_z_wbuf_write(wbf, msg->_version)); @@ -86,8 +86,8 @@ int8_t _z_join_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_join_t *msg return ret; } -int8_t _z_join_decode_ext(_z_msg_ext_t *extension, void *ctx) { - int8_t ret = _Z_RES_OK; +z_result_t _z_join_decode_ext(_z_msg_ext_t *extension, void *ctx) { + z_result_t ret = _Z_RES_OK; _z_t_msg_join_t *msg = (_z_t_msg_join_t *)ctx; if (_Z_EXT_FULL_ID(extension->_header) == (_Z_MSG_EXT_ENC_ZBUF | _Z_MSG_EXT_FLAG_M | 1)) { // QOS: (enc=zbuf)(mandatory=true)(id=1) @@ -103,9 +103,9 @@ int8_t _z_join_decode_ext(_z_msg_ext_t *extension, void *ctx) { return ret; } -int8_t _z_join_decode(_z_t_msg_join_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_join_decode(_z_t_msg_join_t *msg, _z_zbuf_t *zbf, uint8_t header) { _Z_DEBUG("Decoding _Z_MID_T_JOIN"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; *msg = (_z_t_msg_join_t){0}; ret |= _z_uint8_decode(&msg->_version, zbf); @@ -155,9 +155,9 @@ int8_t _z_join_decode(_z_t_msg_join_t *msg, _z_zbuf_t *zbf, uint8_t header) { } /*------------------ Init Message ------------------*/ -int8_t _z_init_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_init_t *msg) { +z_result_t _z_init_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_init_t *msg) { _Z_DEBUG("Encoding _Z_MID_T_INIT"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; _Z_RETURN_IF_ERR(_z_wbuf_write(wbf, msg->_version)) @@ -183,10 +183,10 @@ int8_t _z_init_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_init_t *msg return ret; } -int8_t _z_init_decode(_z_t_msg_init_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_init_decode(_z_t_msg_init_t *msg, _z_zbuf_t *zbf, uint8_t header) { _Z_DEBUG("Decoding _Z_MID_T_INIT"); *msg = (_z_t_msg_init_t){0}; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; ret |= _z_uint8_decode(&msg->_version, zbf); @@ -230,8 +230,8 @@ int8_t _z_init_decode(_z_t_msg_init_t *msg, _z_zbuf_t *zbf, uint8_t header) { } /*------------------ Open Message ------------------*/ -int8_t _z_open_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_open_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_open_t *msg) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _Z_MID_T_OPEN"); if (_Z_HAS_FLAG(header, _Z_FLAG_T_OPEN_T) == true) { @@ -249,9 +249,9 @@ int8_t _z_open_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_open_t *msg return ret; } -int8_t _z_open_decode(_z_t_msg_open_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_open_decode(_z_t_msg_open_t *msg, _z_zbuf_t *zbf, uint8_t header) { _Z_DEBUG("Decoding _Z_MID_T_OPEN"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; *msg = (_z_t_msg_open_t){0}; ret |= _z_zsize_decode(&msg->_lease, zbf); @@ -277,9 +277,9 @@ int8_t _z_open_decode(_z_t_msg_open_t *msg, _z_zbuf_t *zbf, uint8_t header) { } /*------------------ Close Message ------------------*/ -int8_t _z_close_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_close_t *msg) { +z_result_t _z_close_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_close_t *msg) { (void)(header); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _Z_MID_T_CLOSE"); ret |= _z_wbuf_write(wbf, msg->_reason); @@ -287,9 +287,9 @@ int8_t _z_close_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_close_t *m return ret; } -int8_t _z_close_decode(_z_t_msg_close_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_close_decode(_z_t_msg_close_t *msg, _z_zbuf_t *zbf, uint8_t header) { (void)(header); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; *msg = (_z_t_msg_close_t){0}; _Z_DEBUG("Decoding _Z_MID_T_CLOSE"); @@ -299,24 +299,24 @@ int8_t _z_close_decode(_z_t_msg_close_t *msg, _z_zbuf_t *zbf, uint8_t header) { } /*------------------ Keep Alive Message ------------------*/ -int8_t _z_keep_alive_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_keep_alive_t *msg) { +z_result_t _z_keep_alive_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_keep_alive_t *msg) { (void)(wbf); (void)(header); (void)(msg); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _Z_MID_T_KEEP_ALIVE"); return ret; } -int8_t _z_keep_alive_decode(_z_t_msg_keep_alive_t *msg, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_keep_alive_decode(_z_t_msg_keep_alive_t *msg, _z_zbuf_t *zbf, uint8_t header) { (void)(msg); (void)(zbf); (void)(header); *msg = (_z_t_msg_keep_alive_t){0}; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Decoding _Z_MID_T_KEEP_ALIVE"); if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) { @@ -328,8 +328,8 @@ int8_t _z_keep_alive_decode(_z_t_msg_keep_alive_t *msg, _z_zbuf_t *zbf, uint8_t /*------------------ Frame Message ------------------*/ -int8_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_t *msg) { + z_result_t ret = _Z_RES_OK; _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_sn)) @@ -346,8 +346,8 @@ int8_t _z_frame_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_frame_t *m return ret; } -int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header) { - int8_t ret = _Z_RES_OK; +z_result_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header) { + z_result_t ret = _Z_RES_OK; *msg = (_z_t_msg_frame_t){0}; ret |= _z_zsize_decode(&msg->_sn, zbf); @@ -384,8 +384,8 @@ int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header) { } /*------------------ Fragment Message ------------------*/ -int8_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fragment_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fragment_t *msg) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _Z_TRANSPORT_FRAGMENT"); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_sn)) if (_Z_HAS_FLAG(header, _Z_FLAG_T_Z)) { @@ -398,8 +398,8 @@ int8_t _z_fragment_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_fragmen return ret; } -int8_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t header) { - int8_t ret = _Z_RES_OK; +z_result_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t header) { + z_result_t ret = _Z_RES_OK; *msg = (_z_t_msg_fragment_t){0}; _Z_DEBUG("Decoding _Z_TRANSPORT_FRAGMENT"); @@ -417,9 +417,9 @@ int8_t _z_fragment_decode(_z_t_msg_fragment_t *msg, _z_zbuf_t *zbf, uint8_t head } /*------------------ Transport Extensions Message ------------------*/ -int8_t _z_extensions_encode(_z_wbuf_t *wbf, uint8_t header, const _z_msg_ext_vec_t *v_ext) { +z_result_t _z_extensions_encode(_z_wbuf_t *wbf, uint8_t header, const _z_msg_ext_vec_t *v_ext) { (void)(header); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Encoding _Z_TRANSPORT_EXTENSIONS"); if (_Z_HAS_FLAG(header, _Z_FLAG_T_Z) == true) { @@ -429,9 +429,9 @@ int8_t _z_extensions_encode(_z_wbuf_t *wbf, uint8_t header, const _z_msg_ext_vec return ret; } -int8_t _z_extensions_decode(_z_msg_ext_vec_t *v_ext, _z_zbuf_t *zbf, uint8_t header) { +z_result_t _z_extensions_decode(_z_msg_ext_vec_t *v_ext, _z_zbuf_t *zbf, uint8_t header) { (void)(header); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; _Z_DEBUG("Decoding _Z_TRANSPORT_EXTENSIONS"); if (_Z_HAS_FLAG(header, _Z_FLAG_T_Z) == true) { @@ -444,8 +444,8 @@ int8_t _z_extensions_decode(_z_msg_ext_vec_t *v_ext, _z_zbuf_t *zbf, uint8_t hea } /*------------------ Transport Message ------------------*/ -int8_t _z_transport_message_encode(_z_wbuf_t *wbf, const _z_transport_message_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_transport_message_encode(_z_wbuf_t *wbf, const _z_transport_message_t *msg) { + z_result_t ret = _Z_RES_OK; uint8_t header = msg->_header; @@ -481,8 +481,8 @@ int8_t _z_transport_message_encode(_z_wbuf_t *wbf, const _z_transport_message_t return ret; } -int8_t _z_transport_message_decode(_z_transport_message_t *msg, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; +z_result_t _z_transport_message_decode(_z_transport_message_t *msg, _z_zbuf_t *zbf) { + z_result_t ret = _Z_RES_OK; ret |= _z_uint8_decode(&msg->_header, zbf); // Decode the header if (ret == _Z_RES_OK) { diff --git a/src/protocol/config.c b/src/protocol/config.c index 4695de3c1..37fa57a47 100644 --- a/src/protocol/config.c +++ b/src/protocol/config.c @@ -20,13 +20,13 @@ #include "zenoh-pico/utils/pointers.h" -int8_t _z_config_init(_z_config_t *ps) { +z_result_t _z_config_init(_z_config_t *ps) { _z_str_intmap_init(ps); return 0; } -int8_t _zp_config_insert(_z_config_t *ps, uint8_t key, const char *value) { - int8_t ret = _Z_RES_OK; +z_result_t _zp_config_insert(_z_config_t *ps, uint8_t key, const char *value) { + z_result_t ret = _Z_RES_OK; char *res = _z_str_intmap_insert(ps, key, _z_str_clone(value)); if (strcmp(res, value) != 0) { @@ -39,9 +39,9 @@ int8_t _zp_config_insert(_z_config_t *ps, uint8_t key, const char *value) { char *_z_config_get(const _z_config_t *ps, uint8_t key) { return _z_str_intmap_get(ps, key); } /*------------------ int-string map ------------------*/ -int8_t _z_str_intmap_from_strn(_z_str_intmap_t *strint, const char *s, uint8_t argc, _z_str_intmapping_t argv[], - size_t n) { - int8_t ret = _Z_RES_OK; +z_result_t _z_str_intmap_from_strn(_z_str_intmap_t *strint, const char *s, uint8_t argc, _z_str_intmapping_t argv[], + size_t n) { + z_result_t ret = _Z_RES_OK; *strint = _z_str_intmap_make(); // Check the string contains only the right @@ -98,7 +98,7 @@ int8_t _z_str_intmap_from_strn(_z_str_intmap_t *strint, const char *s, uint8_t a return ret; } -int8_t _z_str_intmap_from_str(_z_str_intmap_t *strint, const char *s, uint8_t argc, _z_str_intmapping_t argv[]) { +z_result_t _z_str_intmap_from_str(_z_str_intmap_t *strint, const char *s, uint8_t argc, _z_str_intmapping_t argv[]) { return _z_str_intmap_from_strn(strint, s, argc, argv, strlen(s)); } diff --git a/src/protocol/core.c b/src/protocol/core.c index f0a8ad702..ed0479cc5 100644 --- a/src/protocol/core.c +++ b/src/protocol/core.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/protocol/core.h" +#include "zenoh-pico/protocol/codec/core.h" #include #include @@ -20,7 +20,7 @@ #include "zenoh-pico/api/primitives.h" #include "zenoh-pico/api/types.h" #include "zenoh-pico/collections/slice.h" -#include "zenoh-pico/protocol/codec/core.h" +#include "zenoh-pico/protocol/core.h" #include "zenoh-pico/protocol/iobuf.h" #include "zenoh-pico/utils/endianness.h" #include "zenoh-pico/utils/logging.h" @@ -85,14 +85,14 @@ _z_value_t _z_value_steal(_z_value_t *value) { *value = _z_value_null(); return ret; } -int8_t _z_value_copy(_z_value_t *dst, const _z_value_t *src) { +z_result_t _z_value_copy(_z_value_t *dst, const _z_value_t *src) { *dst = _z_value_null(); _Z_RETURN_IF_ERR(_z_encoding_copy(&dst->encoding, &src->encoding)); _Z_CLEAN_RETURN_IF_ERR(_z_bytes_copy(&dst->payload, &src->payload), _z_encoding_clear(&dst->encoding)); return _Z_RES_OK; } -int8_t _z_hello_copy(_z_hello_t *dst, const _z_hello_t *src) { +z_result_t _z_hello_copy(_z_hello_t *dst, const _z_hello_t *src) { *dst = _z_hello_null(); _Z_RETURN_IF_ERR(_z_string_svec_copy(&dst->_locators, &src->_locators) ? _Z_RES_OK : _Z_ERR_SYSTEM_OUT_OF_MEMORY); dst->_version = src->_version; diff --git a/src/protocol/iobuf.c b/src/protocol/iobuf.c index 9422a5453..65c40be06 100644 --- a/src/protocol/iobuf.c +++ b/src/protocol/iobuf.c @@ -357,7 +357,7 @@ uint8_t _z_wbuf_get(const _z_wbuf_t *wbf, size_t pos) { return _z_iosli_get(ios, current); } -int8_t _z_wbuf_write(_z_wbuf_t *wbf, uint8_t b) { +z_result_t _z_wbuf_write(_z_wbuf_t *wbf, uint8_t b) { _z_iosli_t *ios = _z_wbuf_get_iosli(wbf, wbf->_w_idx); size_t writable = _z_iosli_writable(ios); if (writable == (size_t)0) { @@ -376,8 +376,8 @@ int8_t _z_wbuf_write(_z_wbuf_t *wbf, uint8_t b) { return _Z_RES_OK; } -int8_t _z_wbuf_write_bytes(_z_wbuf_t *wbf, const uint8_t *bs, size_t offset, size_t length) { - int8_t ret = _Z_RES_OK; +z_result_t _z_wbuf_write_bytes(_z_wbuf_t *wbf, const uint8_t *bs, size_t offset, size_t length) { + z_result_t ret = _Z_RES_OK; size_t loffset = offset; size_t llength = length; @@ -410,8 +410,8 @@ int8_t _z_wbuf_write_bytes(_z_wbuf_t *wbf, const uint8_t *bs, size_t offset, siz return ret; } -int8_t _z_wbuf_wrap_bytes(_z_wbuf_t *wbf, const uint8_t *bs, size_t offset, size_t length) { - int8_t ret = _Z_RES_OK; +z_result_t _z_wbuf_wrap_bytes(_z_wbuf_t *wbf, const uint8_t *bs, size_t offset, size_t length) { + z_result_t ret = _Z_RES_OK; _z_iosli_t *ios = _z_wbuf_get_iosli(wbf, wbf->_w_idx); size_t writable = _z_iosli_writable(ios); @@ -517,8 +517,8 @@ _z_zbuf_t _z_wbuf_to_zbuf(const _z_wbuf_t *wbf) { return zbf; } -int8_t _z_wbuf_siphon(_z_wbuf_t *dst, _z_wbuf_t *src, size_t length) { - int8_t ret = _Z_RES_OK; +z_result_t _z_wbuf_siphon(_z_wbuf_t *dst, _z_wbuf_t *src, size_t length) { + z_result_t ret = _Z_RES_OK; for (size_t i = 0; i < length; i++) { ret = _z_wbuf_write(dst, _z_wbuf_read(src)); diff --git a/src/protocol/keyexpr.c b/src/protocol/keyexpr.c index 9b23072f3..a097b2c40 100644 --- a/src/protocol/keyexpr.c +++ b/src/protocol/keyexpr.c @@ -48,7 +48,7 @@ _z_keyexpr_t _z_keyexpr_from_substr(uint16_t rid, const char *str, size_t len) { }; } -int8_t _z_keyexpr_copy(_z_keyexpr_t *dst, const _z_keyexpr_t *src) { +z_result_t _z_keyexpr_copy(_z_keyexpr_t *dst, const _z_keyexpr_t *src) { *dst = _z_keyexpr_null(); dst->_id = src->_id; dst->_mapping = src->_mapping; diff --git a/src/session/interest.c b/src/session/interest.c index 317ec3717..a16884ee7 100644 --- a/src/session/interest.c +++ b/src/session/interest.c @@ -93,7 +93,7 @@ static _z_session_interest_rc_list_t *__unsafe_z_get_interest_by_key_and_flags(_ return __z_get_interest_by_key_and_flags(intrs, flags, key); } -static int8_t _z_interest_send_decl_resource(_z_session_t *zn, uint32_t interest_id) { +static z_result_t _z_interest_send_decl_resource(_z_session_t *zn, uint32_t interest_id) { _zp_session_lock_mutex(zn); _z_resource_list_t *res_list = _z_resource_list_clone(zn->_local_resources); _zp_session_unlock_mutex(zn); @@ -115,7 +115,7 @@ static int8_t _z_interest_send_decl_resource(_z_session_t *zn, uint32_t interest } #if Z_FEATURE_SUBSCRIPTION == 1 -static int8_t _z_interest_send_decl_subscriber(_z_session_t *zn, uint32_t interest_id) { +static z_result_t _z_interest_send_decl_subscriber(_z_session_t *zn, uint32_t interest_id) { _zp_session_lock_mutex(zn); _z_subscription_rc_list_t *sub_list = _z_subscription_rc_list_clone(zn->_local_subscriptions); _zp_session_unlock_mutex(zn); @@ -136,7 +136,7 @@ static int8_t _z_interest_send_decl_subscriber(_z_session_t *zn, uint32_t intere return _Z_RES_OK; } #else -static int8_t _z_interest_send_decl_subscriber(_z_session_t *zn, uint32_t interest_id) { +static z_result_t _z_interest_send_decl_subscriber(_z_session_t *zn, uint32_t interest_id) { _ZP_UNUSED(zn); _ZP_UNUSED(interest_id); return _Z_RES_OK; @@ -144,7 +144,7 @@ static int8_t _z_interest_send_decl_subscriber(_z_session_t *zn, uint32_t intere #endif #if Z_FEATURE_QUERYABLE == 1 -static int8_t _z_interest_send_decl_queryable(_z_session_t *zn, uint32_t interest_id) { +static z_result_t _z_interest_send_decl_queryable(_z_session_t *zn, uint32_t interest_id) { _zp_session_lock_mutex(zn); _z_session_queryable_rc_list_t *qle_list = _z_session_queryable_rc_list_clone(zn->_local_queryable); _zp_session_unlock_mutex(zn); @@ -166,14 +166,14 @@ static int8_t _z_interest_send_decl_queryable(_z_session_t *zn, uint32_t interes return _Z_RES_OK; } #else -static int8_t _z_interest_send_decl_queryable(_z_session_t *zn, uint32_t interest_id) { +static z_result_t _z_interest_send_decl_queryable(_z_session_t *zn, uint32_t interest_id) { _ZP_UNUSED(zn); _ZP_UNUSED(interest_id); return _Z_RES_OK; } #endif -static int8_t _z_interest_send_declare_final(_z_session_t *zn, uint32_t interest_id) { +static z_result_t _z_interest_send_declare_final(_z_session_t *zn, uint32_t interest_id) { _z_declaration_t decl = _z_make_decl_final(); _z_network_message_t n_msg = _z_n_msg_make_declare(decl, true, interest_id); if (_z_send_n_msg(zn, &n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) { @@ -205,7 +205,7 @@ _z_session_interest_rc_t *_z_register_interest(_z_session_t *zn, _z_session_inte return ret; } -static int8_t _unsafe_z_register_declare(_z_session_t *zn, const _z_keyexpr_t *key, uint32_t id, uint8_t type) { +static z_result_t _unsafe_z_register_declare(_z_session_t *zn, const _z_keyexpr_t *key, uint32_t id, uint8_t type) { _z_declare_data_t *decl = NULL; decl = (_z_declare_data_t *)z_malloc(sizeof(_z_declare_data_t)); if (decl == NULL) { @@ -235,7 +235,7 @@ static _z_keyexpr_t _unsafe_z_get_key_from_declare(_z_session_t *zn, uint32_t id return _z_keyexpr_null(); } -static int8_t _unsafe_z_unregister_declare(_z_session_t *zn, uint32_t id, uint8_t type) { +static z_result_t _unsafe_z_unregister_declare(_z_session_t *zn, uint32_t id, uint8_t type) { _z_declare_data_t decl = { ._key = _z_keyexpr_null(), ._id = id, @@ -245,7 +245,7 @@ static int8_t _unsafe_z_unregister_declare(_z_session_t *zn, uint32_t id, uint8_ return _Z_RES_OK; } -int8_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *decl) { +z_result_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *decl) { const _z_keyexpr_t *decl_key = NULL; _z_interest_msg_t msg; uint8_t flags = 0; @@ -295,7 +295,7 @@ int8_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *de return _Z_RES_OK; } -int8_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl) { +z_result_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl) { _z_interest_msg_t msg; uint8_t flags = 0; uint8_t decl_type = 0; @@ -356,7 +356,7 @@ void _z_flush_interest(_z_session_t *zn) { _zp_session_unlock_mutex(zn); } -int8_t _z_interest_process_declare_final(_z_session_t *zn, uint32_t id) { +z_result_t _z_interest_process_declare_final(_z_session_t *zn, uint32_t id) { _z_interest_msg_t msg = {.type = _Z_INTEREST_MSG_TYPE_FINAL, .id = id}; // Retrieve interest _zp_session_lock_mutex(zn); @@ -372,14 +372,14 @@ int8_t _z_interest_process_declare_final(_z_session_t *zn, uint32_t id) { return _Z_RES_OK; } -int8_t _z_interest_process_interest_final(_z_session_t *zn, uint32_t id) { +z_result_t _z_interest_process_interest_final(_z_session_t *zn, uint32_t id) { _ZP_UNUSED(zn); _ZP_UNUSED(id); // TODO: Update future masks return _Z_RES_OK; } -int8_t _z_interest_process_interest(_z_session_t *zn, _z_keyexpr_t key, uint32_t id, uint8_t flags) { +z_result_t _z_interest_process_interest(_z_session_t *zn, _z_keyexpr_t key, uint32_t id, uint8_t flags) { // TODO: process restricted flag & associated key _ZP_UNUSED(key); // Check transport type @@ -413,31 +413,31 @@ int8_t _z_interest_process_interest(_z_session_t *zn, _z_keyexpr_t key, uint32_t #else void _z_flush_interest(_z_session_t *zn) { _ZP_UNUSED(zn); } -int8_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *decl) { +z_result_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *decl) { _ZP_UNUSED(zn); _ZP_UNUSED(decl); return _Z_RES_OK; } -int8_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl) { +z_result_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl) { _ZP_UNUSED(zn); _ZP_UNUSED(decl); return _Z_RES_OK; } -int8_t _z_interest_process_declare_final(_z_session_t *zn, uint32_t id) { +z_result_t _z_interest_process_declare_final(_z_session_t *zn, uint32_t id) { _ZP_UNUSED(zn); _ZP_UNUSED(id); return _Z_RES_OK; } -int8_t _z_interest_process_interest_final(_z_session_t *zn, uint32_t id) { +z_result_t _z_interest_process_interest_final(_z_session_t *zn, uint32_t id) { _ZP_UNUSED(zn); _ZP_UNUSED(id); return _Z_RES_OK; } -int8_t _z_interest_process_interest(_z_session_t *zn, _z_keyexpr_t key, uint32_t id, uint8_t flags) { +z_result_t _z_interest_process_interest(_z_session_t *zn, _z_keyexpr_t key, uint32_t id, uint8_t flags) { _ZP_UNUSED(zn); _ZP_UNUSED(key); _ZP_UNUSED(id); diff --git a/src/session/push.c b/src/session/push.c index eeff7ac8d..6b45de25b 100644 --- a/src/session/push.c +++ b/src/session/push.c @@ -22,8 +22,8 @@ #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_SUBSCRIPTION == 1 -int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push, z_reliability_t reliability) { - int8_t ret = _Z_RES_OK; +z_result_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push, z_reliability_t reliability) { + z_result_t ret = _Z_RES_OK; // TODO check body to know where to dispatch @@ -42,7 +42,7 @@ int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push, z_reliability_t return ret; } #else -int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push, z_reliability_t reliability) { +z_result_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push, z_reliability_t reliability) { _ZP_UNUSED(zn); _ZP_UNUSED(push); _ZP_UNUSED(reliability); diff --git a/src/session/query.c b/src/session/query.c index 11251914f..9515f47d3 100644 --- a/src/session/query.c +++ b/src/session/query.c @@ -74,8 +74,8 @@ _z_pending_query_t *_z_get_pending_query_by_id(_z_session_t *zn, const _z_zint_t return pql; } -int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) { - int8_t ret = _Z_RES_OK; +z_result_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG(">>> Allocating query for (%ju:%.*s)", (uintmax_t)pen_qry->_key._id, (int)_z_string_len(&pen_qry->_key._suffix), _z_string_data(&pen_qry->_key._suffix)); @@ -94,9 +94,9 @@ int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) return ret; } -int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, const _z_keyexpr_t keyexpr, - _z_msg_put_t *msg, z_sample_kind_t kind) { - int8_t ret = _Z_RES_OK; +z_result_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, const _z_keyexpr_t keyexpr, + _z_msg_put_t *msg, z_sample_kind_t kind) { + z_result_t ret = _Z_RES_OK; _zp_session_lock_mutex(zn); @@ -179,8 +179,8 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons return ret; } -int8_t _z_trigger_query_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t *msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_trigger_query_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t *msg) { + z_result_t ret = _Z_RES_OK; _zp_session_lock_mutex(zn); @@ -209,8 +209,8 @@ int8_t _z_trigger_query_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t * return ret; } -int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { - int8_t ret = _Z_RES_OK; +z_result_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { + z_result_t ret = _Z_RES_OK; _zp_session_lock_mutex(zn); diff --git a/src/session/queryable.c b/src/session/queryable.c index 45e58abd0..3e05a70c3 100644 --- a/src/session/queryable.c +++ b/src/session/queryable.c @@ -132,9 +132,9 @@ _z_session_queryable_rc_t *_z_register_session_queryable(_z_session_t *zn, _z_se return ret; } -int8_t _z_trigger_queryables(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, const _z_keyexpr_t q_key, uint32_t qid, - const _z_bytes_t attachment) { - int8_t ret = _Z_RES_OK; +z_result_t _z_trigger_queryables(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, const _z_keyexpr_t q_key, uint32_t qid, + const _z_bytes_t attachment) { + z_result_t ret = _Z_RES_OK; _z_session_t *zn = _Z_RC_IN_VAL(zsrc); _zp_session_lock_mutex(zn); diff --git a/src/session/reply.c b/src/session/reply.c index 19835aa49..7eb13194c 100644 --- a/src/session/reply.c +++ b/src/session/reply.c @@ -19,8 +19,8 @@ #include "zenoh-pico/session/query.h" #include "zenoh-pico/utils/logging.h" -int8_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key, _z_msg_reply_t *reply) { - int8_t ret = _Z_RES_OK; +z_result_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key, _z_msg_reply_t *reply) { + z_result_t ret = _Z_RES_OK; // TODO check id to know where to dispatch @@ -36,8 +36,8 @@ int8_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key return ret; } -int8_t _z_trigger_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t *error) { - int8_t ret = _Z_RES_OK; +z_result_t _z_trigger_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t *error) { + z_result_t ret = _Z_RES_OK; // TODO check id to know where to dispatch @@ -51,8 +51,8 @@ int8_t _z_trigger_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err_t *error) return ret; } -int8_t _z_trigger_reply_final(_z_session_t *zn, _z_n_msg_response_final_t *final) { - int8_t ret = _Z_RES_OK; +z_result_t _z_trigger_reply_final(_z_session_t *zn, _z_n_msg_response_final_t *final) { + z_result_t ret = _Z_RES_OK; #if Z_FEATURE_QUERY == 1 // TODO check id to know where to dispatch diff --git a/src/session/rx.c b/src/session/rx.c index d8c2a4537..afacc75d7 100644 --- a/src/session/rx.c +++ b/src/session/rx.c @@ -35,8 +35,8 @@ #include "zenoh-pico/utils/logging.h" /*------------------ Handle message ------------------*/ -int8_t _z_handle_network_message(_z_session_rc_t *zsrc, _z_zenoh_message_t *msg, uint16_t local_peer_id) { - int8_t ret = _Z_RES_OK; +z_result_t _z_handle_network_message(_z_session_rc_t *zsrc, _z_zenoh_message_t *msg, uint16_t local_peer_id) { + z_result_t ret = _Z_RES_OK; _z_session_t *zn = _Z_RC_IN_VAL(zsrc); switch (msg->_tag) { diff --git a/src/session/scout.c b/src/session/scout.c index cc8979cbe..7c35d1e21 100644 --- a/src/session/scout.c +++ b/src/session/scout.c @@ -28,7 +28,7 @@ _z_hello_list_t *__z_scout_loop(const _z_wbuf_t *wbf, _z_string_t *locator, unsigned long period, bool exit_on_first) { // Define an empty array _z_hello_list_t *ret = NULL; - int8_t err = _Z_RES_OK; + z_result_t err = _Z_RES_OK; _z_endpoint_t ep; err = _z_endpoint_from_string(&ep, locator); diff --git a/src/session/subscription.c b/src/session/subscription.c index 43a578491..b7bf19f26 100644 --- a/src/session/subscription.c +++ b/src/session/subscription.c @@ -141,15 +141,15 @@ _z_subscription_rc_t *_z_register_subscription(_z_session_t *zn, uint8_t is_loca void _z_trigger_local_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, const _z_bytes_t payload, _z_encoding_t *encoding, const _z_n_qos_t qos, const _z_timestamp_t *timestamp, const _z_bytes_t attachment, z_reliability_t reliability) { - int8_t ret = _z_trigger_subscriptions(zn, keyexpr, payload, encoding, Z_SAMPLE_KIND_PUT, timestamp, qos, attachment, - reliability); + z_result_t ret = _z_trigger_subscriptions(zn, keyexpr, payload, encoding, Z_SAMPLE_KIND_PUT, timestamp, qos, + attachment, reliability); (void)ret; } -int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, const _z_bytes_t payload, - _z_encoding_t *encoding, const _z_zint_t kind, const _z_timestamp_t *timestamp, - const _z_n_qos_t qos, const _z_bytes_t attachment, z_reliability_t reliability) { - int8_t ret = _Z_RES_OK; +z_result_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, const _z_bytes_t payload, + _z_encoding_t *encoding, const _z_zint_t kind, const _z_timestamp_t *timestamp, + const _z_n_qos_t qos, const _z_bytes_t attachment, z_reliability_t reliability) { + z_result_t ret = _Z_RES_OK; _zp_session_lock_mutex(zn); diff --git a/src/session/tx.c b/src/session/tx.c index 50f55f9e4..64746930e 100644 --- a/src/session/tx.c +++ b/src/session/tx.c @@ -18,9 +18,9 @@ #include "zenoh-pico/transport/unicast/tx.h" #include "zenoh-pico/utils/logging.h" -int8_t _z_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_send_n_msg(_z_session_t *zn, const _z_network_message_t *z_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG(">> send network message"); // Call transport function switch (zn->_tp._type) { diff --git a/src/session/utils.c b/src/session/utils.c index 8b5902496..7b9179912 100644 --- a/src/session/utils.c +++ b/src/session/utils.c @@ -40,15 +40,15 @@ void _z_timestamp_clear(_z_timestamp_t *tstamp) { bool _z_timestamp_check(const _z_timestamp_t *stamp) { return _z_id_check(stamp->id); } -int8_t _z_session_generate_zid(_z_id_t *bs, uint8_t size) { - int8_t ret = _Z_RES_OK; +z_result_t _z_session_generate_zid(_z_id_t *bs, uint8_t size) { + z_result_t ret = _Z_RES_OK; z_random_fill((uint8_t *)bs->id, size); return ret; } /*------------------ Init/Free/Close session ------------------*/ -int8_t _z_session_init(_z_session_rc_t *zsrc, _z_id_t *zid) { - int8_t ret = _Z_RES_OK; +z_result_t _z_session_init(_z_session_rc_t *zsrc, _z_id_t *zid) { + z_result_t ret = _Z_RES_OK; _z_session_t *zn = _Z_RC_IN_VAL(zsrc); // Initialize the counters to 1 @@ -124,8 +124,8 @@ void _z_session_clear(_z_session_t *zn) { #endif // Z_FEATURE_MULTI_THREAD == 1 } -int8_t _z_session_close(_z_session_t *zn, uint8_t reason) { - int8_t ret = _Z_ERR_GENERIC; +z_result_t _z_session_close(_z_session_t *zn, uint8_t reason) { + z_result_t ret = _Z_ERR_GENERIC; if (zn != NULL) { ret = _z_transport_close(&zn->_tp, reason); diff --git a/src/system/arduino/esp32/network.cpp b/src/system/arduino/esp32/network.cpp index cbfe0360c..826684ef5 100644 --- a/src/system/arduino/esp32/network.cpp +++ b/src/system/arduino/esp32/network.cpp @@ -34,8 +34,8 @@ extern "C" { #if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ -int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; struct addrinfo hints; (void)memset(&hints, 0, sizeof(hints)); @@ -53,8 +53,8 @@ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_tcp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } -int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { @@ -95,8 +95,8 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u return ret; } -int8_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; @@ -145,8 +145,8 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ -int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; struct addrinfo hints; (void)memset(&hints, 0, sizeof(hints)); @@ -166,8 +166,8 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); #endif #if Z_FEATURE_LINK_UDP_UNICAST == 1 -int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { @@ -188,8 +188,8 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ return ret; } -int8_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; (void)tout; @@ -239,9 +239,9 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s #endif #if Z_FEATURE_LINK_UDP_MULTICAST == 1 -int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, - uint32_t tout, const char *iface) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, + uint32_t tout, const char *iface) { + z_result_t ret = _Z_RES_OK; struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; @@ -345,10 +345,10 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin return ret; } -int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, - const char *iface, const char *join) { +z_result_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, + const char *iface, const char *join) { (void)join; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; @@ -547,8 +547,8 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, #if Z_FEATURE_LINK_BLUETOOTH == 1 /*------------------ Bluetooth sockets ------------------*/ -int8_t _z_open_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout) { + z_result_t ret = _Z_RES_OK; if (profile == _Z_BT_PROFILE_SPP) { sock->_bts = new BluetoothSerial(); @@ -573,8 +573,8 @@ int8_t _z_open_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, ui return ret; } -int8_t _z_listen_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t profile, uint32_t tout) { + z_result_t ret = _Z_RES_OK; if (profile == _Z_BT_PROFILE_SPP) { sock->_bts = new BluetoothSerial(); @@ -644,8 +644,8 @@ size_t _z_send_bt(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len #if Z_FEATURE_LINK_SERIAL == 1 /*------------------ Serial sockets ------------------*/ -int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; uint8_t uart = 255; if (rxpin == 3 && txpin == 1) { @@ -679,8 +679,8 @@ int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint3 return ret; } -int8_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; uint8_t uart = 255; uint32_t rxpin = 0; @@ -722,8 +722,8 @@ int8_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t ba return ret; } -int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(txpin); (void)(rxpin); @@ -735,8 +735,8 @@ int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uin return ret; } -int8_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(dev); (void)(baudrate); @@ -753,7 +753,7 @@ void _z_close_serial(_z_sys_net_socket_t *sock) { } size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; uint8_t *before_cobs = new uint8_t[_Z_SERIAL_MAX_COBS_BUF_SIZE](); size_t rb = 0; @@ -822,7 +822,7 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t } size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; uint8_t *before_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MFS_SIZE); size_t i = 0; diff --git a/src/system/arduino/esp32/system.c b/src/system/arduino/esp32/system.c index 3e3266c0a..cb785640b 100644 --- a/src/system/arduino/esp32/system.c +++ b/src/system/arduino/esp32/system.c @@ -60,7 +60,7 @@ void z_task_wrapper(z_task_arg *targ) { } /*------------------ Task ------------------*/ -int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { +z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { int ret = 0; z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg)); @@ -77,12 +77,12 @@ int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), return ret; } -int8_t _z_task_join(_z_task_t *task) { +z_result_t _z_task_join(_z_task_t *task) { // Note: task/thread join not supported on FreeRTOS API, so we force its deletion instead. return _z_task_cancel(task); } -int8_t _z_task_cancel(_z_task_t *task) { +z_result_t _z_task_cancel(_z_task_t *task) { vTaskDelete(*task); return 0; } @@ -94,26 +94,26 @@ void _z_task_free(_z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, NULL)); } +z_result_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, NULL)); } -int8_t _z_mutex_drop(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_destroy(m)); } +z_result_t _z_mutex_drop(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_destroy(m)); } -int8_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } +z_result_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } -int8_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } +z_result_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } -int8_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } +z_result_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } /*------------------ Condvar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, NULL)); } +z_result_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, NULL)); } -int8_t _z_condvar_free(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } +z_result_t _z_condvar_free(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } -int8_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } +z_result_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } -int8_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } +z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ @@ -204,10 +204,10 @@ unsigned long z_time_elapsed_s(z_time_t *time) { return elapsed; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t) { +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t) { z_time_t now; gettimeofday(&now, NULL); t->secs = now.tv_sec; t->nanos = now.tv_usec * 1000; return 0; -} \ No newline at end of file +} diff --git a/src/system/arduino/opencr/network.cpp b/src/system/arduino/opencr/network.cpp index 0d75a298d..b690559f1 100644 --- a/src/system/arduino/opencr/network.cpp +++ b/src/system/arduino/opencr/network.cpp @@ -29,8 +29,8 @@ extern "C" { #if Z_FEATURE_LINK_TCP == 1 /*------------------ UDP sockets ------------------*/ -int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; // Parse and check the validity of the IP address ep->_iptcp._addr = new IPAddress(); @@ -54,8 +54,8 @@ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_tcp(_z_sys_net_endpoint_t *ep) { delete ep->_iptcp._addr; } -int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_tcp = new WiFiClient(); if (!sock->_tcp->connect(*rep._iptcp._addr, rep._iptcp._port)) { @@ -69,8 +69,8 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u return ret; } -int8_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; @@ -121,8 +121,8 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ -int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; // Parse and check the validity of the IP address ep->_iptcp._addr = new IPAddress(); @@ -149,8 +149,8 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { delete ep->_iptcp._addr; #if Z_FEATURE_LINK_UDP_UNICAST == 1 -int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)rep; @@ -167,8 +167,8 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ return ret; } -int8_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; (void)tout; @@ -230,9 +230,9 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s #endif #if Z_FEATURE_LINK_UDP_MULTICAST == 1 -int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, - uint32_t tout, const char *iface) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, + uint32_t tout, const char *iface) { + z_result_t ret = _Z_RES_OK; (void)(rep); sock->_udp = new WiFiUDP(); @@ -251,10 +251,10 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin return ret; } -int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, - const char *iface, const char *join) { +z_result_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, + const char *iface, const char *join) { (void)join; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; sock->_udp = new WiFiUDP(); if (!sock->_udp->beginMulticast(*rep._iptcp._addr, rep._iptcp._port)) { diff --git a/src/system/arduino/opencr/system.c b/src/system/arduino/opencr/system.c index 9fb1c93c3..2c97707f3 100644 --- a/src/system/arduino/opencr/system.c +++ b/src/system/arduino/opencr/system.c @@ -63,11 +63,11 @@ void z_free(void *ptr) { #error "Multi-threading not supported yet on OpenCR port. Disable it by defining Z_FEATURE_MULTI_THREAD=0" /*------------------ Task ------------------*/ -int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return -1; } +z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return -1; } -int8_t _z_task_join(_z_task_t *task) { return -1; } +z_result_t _z_task_join(_z_task_t *task) { return -1; } -int8_t _z_task_cancel(_z_task_t *task) { return -1; } +z_result_t _z_task_cancel(_z_task_t *task) { return -1; } void _z_task_free(_z_task_t **task) { _z_task_t *ptr = *task; @@ -76,25 +76,25 @@ void _z_task_free(_z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m) { return -1; } +z_result_t _z_mutex_init(_z_mutex_t *m) { return -1; } -int8_t _z_mutex_drop(_z_mutex_t *m) { return -1; } +z_result_t _z_mutex_drop(_z_mutex_t *m) { return -1; } -int8_t _z_mutex_lock(_z_mutex_t *m) { return -1; } +z_result_t _z_mutex_lock(_z_mutex_t *m) { return -1; } -int8_t _z_mutex_try_lock(_z_mutex_t *m) { return -1; } +z_result_t _z_mutex_try_lock(_z_mutex_t *m) { return -1; } -int8_t _z_mutex_unlock(_z_mutex_t *m) { return -1; } +z_result_t _z_mutex_unlock(_z_mutex_t *m) { return -1; } /*------------------ Condvar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t *cv) { return -1; } +z_result_t _z_condvar_init(_z_condvar_t *cv) { return -1; } -int8_t _z_condvar_drop(_z_condvar_t *cv) { return -1; } +z_result_t _z_condvar_drop(_z_condvar_t *cv) { return -1; } -int8_t _z_condvar_signal(_z_condvar_t *cv) { return -1; } -int8_t _z_condvar_signal_all(_z_condvar_t *cv) { return -1; } +z_result_t _z_condvar_signal(_z_condvar_t *cv) { return -1; } +z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { return -1; } -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return -1; } +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return -1; } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ @@ -197,10 +197,10 @@ unsigned long z_time_elapsed_s(z_time_t *time) { return elapsed; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t) { +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t) { z_time_t now; gettimeofday(&now, NULL); t->secs = now.tv_sec; t->nanos = now.tv_usec * 1000; return 0; -} \ No newline at end of file +} diff --git a/src/system/emscripten/network.c b/src/system/emscripten/network.c index 4db1dadb3..b170ca855 100644 --- a/src/system/emscripten/network.c +++ b/src/system/emscripten/network.c @@ -33,8 +33,8 @@ #define WS_LINK_SLEEP 1 /*------------------ TCP sockets ------------------*/ -int8_t _z_create_endpoint_ws(_z_sys_net_endpoint_t *ep, const char *s_addr, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_ws(_z_sys_net_endpoint_t *ep, const char *s_addr, const char *s_port) { + z_result_t ret = _Z_RES_OK; struct addrinfo hints; (void)memset(&hints, 0, sizeof(hints)); @@ -53,8 +53,8 @@ int8_t _z_create_endpoint_ws(_z_sys_net_endpoint_t *ep, const char *s_addr, cons void _z_free_endpoint_ws(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } /*------------------ TCP sockets ------------------*/ -int8_t _z_open_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_ws._fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_ws._fd != -1) { @@ -95,8 +95,8 @@ int8_t _z_open_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, ui return ret; } -int8_t _z_listen_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; diff --git a/src/system/emscripten/system.c b/src/system/emscripten/system.c index e576fdb28..1dd8fe213 100644 --- a/src/system/emscripten/system.c +++ b/src/system/emscripten/system.c @@ -44,13 +44,13 @@ void z_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ -int8_t _z_task_init(_z_task_t *task, pthread_attr_t *attr, void *(*fun)(void *), void *arg) { +z_result_t _z_task_init(_z_task_t *task, pthread_attr_t *attr, void *(*fun)(void *), void *arg) { _Z_CHECK_SYS_ERR(pthread_create(task, attr, fun, arg)); } -int8_t _z_task_join(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_join(*task, NULL)); } +z_result_t _z_task_join(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_join(*task, NULL)); } -int8_t _z_task_cancel(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_cancel(*task)); } +z_result_t _z_task_cancel(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_cancel(*task)); } void _z_task_free(_z_task_t **task) { _z_task_t *ptr = *task; @@ -59,26 +59,26 @@ void _z_task_free(_z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, 0)); } +z_result_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, 0)); } -int8_t _z_mutex_drop(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_destroy(m)); } +z_result_t _z_mutex_drop(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_destroy(m)); } -int8_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } +z_result_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } -int8_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } +z_result_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } -int8_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } +z_result_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } /*------------------ Condvar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, 0)); } +z_result_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, 0)); } -int8_t _z_condvar_drop(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } +z_result_t _z_condvar_drop(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } -int8_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } +z_result_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } -int8_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } +z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ @@ -133,7 +133,7 @@ unsigned long z_time_elapsed_ms(z_time_t *time) { unsigned long z_time_elapsed_s(z_time_t *time) { return z_time_elapsed_ms(time) * 1000; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t) { +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t) { double date = emscripten_date_now(); t->secs = (uint32_t)(date / 1000); t->nanos = (uint32_t)((date - t->secs * 1000) * 1000000); diff --git a/src/system/espidf/network.c b/src/system/espidf/network.c index d60a9a4f4..95590ae20 100644 --- a/src/system/espidf/network.c +++ b/src/system/espidf/network.c @@ -30,8 +30,8 @@ #if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ -int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; struct addrinfo hints; (void)memset(&hints, 0, sizeof(hints)); @@ -49,8 +49,8 @@ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_tcp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } -int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { @@ -91,8 +91,8 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u return ret; } -int8_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; @@ -141,8 +141,8 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ -int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; struct addrinfo hints; (void)memset(&hints, 0, sizeof(hints)); @@ -162,8 +162,8 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); #endif #if Z_FEATURE_LINK_UDP_UNICAST == 1 -int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { @@ -184,8 +184,8 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ return ret; } -int8_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; (void)tout; @@ -235,9 +235,9 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s #endif #if Z_FEATURE_LINK_UDP_MULTICAST == 1 -int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, - uint32_t tout, const char *iface) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, + uint32_t tout, const char *iface) { + z_result_t ret = _Z_RES_OK; struct sockaddr *lsockaddr = NULL; socklen_t addrlen = 0; @@ -341,10 +341,10 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin return ret; } -int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, - const char *iface, const char *join) { +z_result_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, + const char *iface, const char *join) { (void)join; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; @@ -543,8 +543,8 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, #if Z_FEATURE_LINK_SERIAL == 1 /*------------------ Serial sockets ------------------*/ -int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(txpin); (void)(rxpin); @@ -556,8 +556,8 @@ int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint3 return ret; } -int8_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; uint32_t rxpin = 0; uint32_t txpin = 0; @@ -599,8 +599,8 @@ int8_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t ba return ret; } -int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(txpin); (void)(rxpin); @@ -612,8 +612,8 @@ int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uin return ret; } -int8_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(dev); (void)(baudrate); @@ -633,7 +633,7 @@ void _z_close_serial(_z_sys_net_socket_t *sock) { } size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; size_t rb = 0; while (rb < _Z_SERIAL_MAX_COBS_BUF_SIZE) { @@ -711,7 +711,7 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t } size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; uint8_t *before_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MFS_SIZE); size_t i = 0; diff --git a/src/system/espidf/system.c b/src/system/espidf/system.c index 351591891..065999795 100644 --- a/src/system/espidf/system.c +++ b/src/system/espidf/system.c @@ -74,7 +74,7 @@ static z_task_attr_t z_default_task_attr = { }; /*------------------ Thread ------------------*/ -int8_t _z_task_init(_z_task_t *task, z_task_attr_t *arg_attr, void *(*fun)(void *), void *arg) { +z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *arg_attr, void *(*fun)(void *), void *arg) { z_task_attr_t *attr = arg_attr; z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg)); if (z_arg == NULL) { @@ -110,12 +110,12 @@ int8_t _z_task_init(_z_task_t *task, z_task_attr_t *arg_attr, void *(*fun)(void return 0; } -int8_t _z_task_join(_z_task_t *task) { +z_result_t _z_task_join(_z_task_t *task) { xEventGroupWaitBits(task->join_event, 1, pdFALSE, pdFALSE, portMAX_DELAY); return 0; } -int8_t z_task_cancel(_z_task_t *task) { +z_result_t z_task_cancel(_z_task_t *task) { vTaskDelete(task->handle); return 0; } @@ -126,26 +126,26 @@ void _z_task_free(_z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, NULL)); } +z_result_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, NULL)); } -int8_t _z_mutex_drop(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_destroy(m)); } +z_result_t _z_mutex_drop(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_destroy(m)); } -int8_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } +z_result_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } -int8_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } +z_result_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } -int8_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } +z_result_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } /*------------------ Condvar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, NULL)); } +z_result_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, NULL)); } -int8_t _z_condvar_drop(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } +z_result_t _z_condvar_drop(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } -int8_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } +z_result_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } -int8_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } +z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ @@ -236,7 +236,7 @@ unsigned long z_time_elapsed_s(z_time_t *time) { return elapsed; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t) { +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t) { z_time_t now; gettimeofday(&now, NULL); t->secs = now.tv_sec; diff --git a/src/system/flipper/network.c b/src/system/flipper/network.c index 7067ae27f..f03b3c647 100644 --- a/src/system/flipper/network.c +++ b/src/system/flipper/network.c @@ -41,11 +41,11 @@ static void _z_serial_received_byte_callback(FuriHalSerialHandle* handle, FuriHa } } -int8_t _z_open_serial_from_pins(_z_sys_net_socket_t* sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { +z_result_t _z_open_serial_from_pins(_z_sys_net_socket_t* sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { return _Z_ERR_GENERIC; } -int8_t _z_open_serial_from_dev(_z_sys_net_socket_t* sock, char* dev, uint32_t baudrate) { +z_result_t _z_open_serial_from_dev(_z_sys_net_socket_t* sock, char* dev, uint32_t baudrate) { if (furi_hal_serial_control_is_busy(FuriHalSerialIdUsart)) { _Z_ERROR("Serial port is busy"); return _Z_ERR_TRANSPORT_OPEN_FAILED; @@ -80,7 +80,7 @@ int8_t _z_open_serial_from_dev(_z_sys_net_socket_t* sock, char* dev, uint32_t ba return _Z_RES_OK; } -int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t* sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { +z_result_t _z_listen_serial_from_pins(_z_sys_net_socket_t* sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { (void)(sock); (void)(txpin); (void)(rxpin); @@ -89,7 +89,7 @@ int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t* sock, uint32_t txpin, uin return _Z_ERR_GENERIC; } -int8_t _z_listen_serial_from_dev(_z_sys_net_socket_t* sock, char* dev, uint32_t baudrate) { +z_result_t _z_listen_serial_from_dev(_z_sys_net_socket_t* sock, char* dev, uint32_t baudrate) { (void)(sock); (void)(dev); (void)(baudrate); @@ -117,7 +117,7 @@ void _z_close_serial(_z_sys_net_socket_t* sock) { } size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t* ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; uint8_t* before_cobs = (uint8_t*)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); size_t rb = 0; @@ -189,7 +189,7 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t* ptr, size_t } size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t* ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; uint8_t* before_cobs = (uint8_t*)z_malloc(_Z_SERIAL_MFS_SIZE); size_t i = 0; diff --git a/src/system/flipper/system.c b/src/system/flipper/system.c index ec264137d..cbeac7de2 100644 --- a/src/system/flipper/system.c +++ b/src/system/flipper/system.c @@ -62,7 +62,7 @@ void z_free(void* ptr) { return free(ptr); } /*------------------ Task ------------------*/ -int8_t _z_task_init(_z_task_t* task, z_task_attr_t* attr, void* (*fun)(void*), void* arg) { +z_result_t _z_task_init(_z_task_t* task, z_task_attr_t* attr, void* (*fun)(void*), void* arg) { if (task == NULL) { return -1; } @@ -80,14 +80,14 @@ int8_t _z_task_init(_z_task_t* task, z_task_attr_t* attr, void* (*fun)(void*), v return _Z_RES_OK; } -int8_t _z_task_join(_z_task_t* task) { +z_result_t _z_task_join(_z_task_t* task) { if (task == NULL) { return -1; } return furi_thread_join(*task); } -int8_t _z_task_cancel(_z_task_t* task) { return -1; } +z_result_t _z_task_cancel(_z_task_t* task) { return -1; } void _z_task_free(_z_task_t** task) { if (task == NULL || *task == NULL) { @@ -98,7 +98,7 @@ void _z_task_free(_z_task_t** task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t* m) { +z_result_t _z_mutex_init(_z_mutex_t* m) { if (m == NULL) { return -1; } @@ -106,7 +106,7 @@ int8_t _z_mutex_init(_z_mutex_t* m) { return (*m != 0) ? _Z_RES_OK : _Z_ERR_SYSTEM_TASK_FAILED; } -int8_t _z_mutex_drop(_z_mutex_t* m) { +z_result_t _z_mutex_drop(_z_mutex_t* m) { if (m == NULL) { return -1; } @@ -118,7 +118,7 @@ int8_t _z_mutex_drop(_z_mutex_t* m) { return 0; } -int8_t _z_mutex_lock(_z_mutex_t* m) { +z_result_t _z_mutex_lock(_z_mutex_t* m) { if (m == NULL) { return -1; } @@ -128,9 +128,9 @@ int8_t _z_mutex_lock(_z_mutex_t* m) { return furi_mutex_acquire(*m, FuriWaitForever); } -int8_t _z_mutex_try_lock(_z_mutex_t* m) { return -1; } +z_result_t _z_mutex_try_lock(_z_mutex_t* m) { return -1; } -int8_t _z_mutex_unlock(_z_mutex_t* m) { +z_result_t _z_mutex_unlock(_z_mutex_t* m) { if (m == NULL) { return -1; } @@ -141,15 +141,15 @@ int8_t _z_mutex_unlock(_z_mutex_t* m) { } /*------------------ Condvar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t* cv) { return -1; } +z_result_t _z_condvar_init(_z_condvar_t* cv) { return -1; } -int8_t _z_condvar_drop(_z_condvar_t* cv) { return -1; } +z_result_t _z_condvar_drop(_z_condvar_t* cv) { return -1; } -int8_t _z_condvar_signal(_z_condvar_t* cv) { return -1; } +z_result_t _z_condvar_signal(_z_condvar_t* cv) { return -1; } -int8_t _z_condvar_signal_all(_z_condvar_t* cv) { return -1; } +z_result_t _z_condvar_signal_all(_z_condvar_t* cv) { return -1; } -int8_t _z_condvar_wait(_z_condvar_t* cv, _z_mutex_t* m) { return -1; } +z_result_t _z_condvar_wait(_z_condvar_t* cv, _z_mutex_t* m) { return -1; } /*------------------ Sleep ------------------*/ int z_sleep_us(size_t time) { @@ -296,4 +296,4 @@ struct tm* localtime(const time_t* timep) { return &t; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch* t) { return -1; } +z_result_t zp_get_time_since_epoch(zp_time_since_epoch* t) { return -1; } diff --git a/src/system/freertos_plus_tcp/network.c b/src/system/freertos_plus_tcp/network.c index 57057c58b..1956ffad8 100644 --- a/src/system/freertos_plus_tcp/network.c +++ b/src/system/freertos_plus_tcp/network.c @@ -25,8 +25,8 @@ #if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ -int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; if (FreeRTOS_getaddrinfo(s_address, NULL, NULL, &ep->_iptcp) < 0) { ret = _Z_ERR_GENERIC; @@ -48,8 +48,8 @@ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_tcp(_z_sys_net_endpoint_t *ep) { FreeRTOS_freeaddrinfo(ep->_iptcp); } -int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_socket = FreeRTOS_socket(rep._iptcp->ai_family, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP); if (sock->_socket != FREERTOS_INVALID_SOCKET) { @@ -67,8 +67,8 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u return ret; } -int8_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; @@ -114,8 +114,8 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ -int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; if (FreeRTOS_getaddrinfo(s_address, NULL, NULL, &ep->_iptcp) < 0) { ret = _Z_ERR_GENERIC; @@ -139,8 +139,8 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { FreeRTOS_freeaddrinfo(ep- #endif #if Z_FEATURE_LINK_UDP_UNICAST == 1 -int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_socket = FreeRTOS_socket(rep._iptcp->ai_family, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP); if (sock->_socket != FREERTOS_INVALID_SOCKET) { @@ -156,8 +156,8 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ return ret; } -int8_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)rep; (void)tout; diff --git a/src/system/freertos_plus_tcp/system.c b/src/system/freertos_plus_tcp/system.c index 54a9fbf24..a454e7204 100644 --- a/src/system/freertos_plus_tcp/system.c +++ b/src/system/freertos_plus_tcp/system.c @@ -85,7 +85,7 @@ static z_task_attr_t z_default_task_attr = { }; /*------------------ Thread ------------------*/ -int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { +z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg)); if (z_arg == NULL) { return -1; @@ -119,12 +119,12 @@ int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), return 0; } -int8_t _z_task_join(_z_task_t *task) { +z_result_t _z_task_join(_z_task_t *task) { xEventGroupWaitBits(task->join_event, 1, pdFALSE, pdFALSE, portMAX_DELAY); return 0; } -int8_t _z_task_cancel(_z_task_t *task) { +z_result_t _z_task_cancel(_z_task_t *task) { vTaskDelete(task->handle); return 0; } @@ -135,29 +135,29 @@ void _z_task_free(_z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m) { +z_result_t _z_mutex_init(_z_mutex_t *m) { *m = xSemaphoreCreateRecursiveMutex(); return *m == NULL ? -1 : 0; } -int8_t _z_mutex_drop(_z_mutex_t *m) { +z_result_t _z_mutex_drop(_z_mutex_t *m) { z_free(*m); return 0; } -int8_t _z_mutex_lock(_z_mutex_t *m) { return xSemaphoreTakeRecursive(*m, portMAX_DELAY) == pdTRUE ? 0 : -1; } +z_result_t _z_mutex_lock(_z_mutex_t *m) { return xSemaphoreTakeRecursive(*m, portMAX_DELAY) == pdTRUE ? 0 : -1; } -int8_t _z_mutex_try_lock(_z_mutex_t *m) { return xSemaphoreTakeRecursive(*m, 0) == pdTRUE ? 0 : -1; } +z_result_t _z_mutex_try_lock(_z_mutex_t *m) { return xSemaphoreTakeRecursive(*m, 0) == pdTRUE ? 0 : -1; } -int8_t _z_mutex_unlock(_z_mutex_t *m) { return xSemaphoreGiveRecursive(*m) == pdTRUE ? 0 : -1; } +z_result_t _z_mutex_unlock(_z_mutex_t *m) { return xSemaphoreGiveRecursive(*m) == pdTRUE ? 0 : -1; } /*------------------ CondVar ------------------*/ // Condition variables not supported in FreeRTOS -int8_t _z_condvar_init(_z_condvar_t *cv) { return -1; } -int8_t _z_condvar_drop(_z_condvar_t *cv) { return -1; } -int8_t _z_condvar_signal(_z_condvar_t *cv) { return -1; } -int8_t _z_condvar_signal_all(_z_condvar_t *cv) { return -1; } -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return -1; } +z_result_t _z_condvar_init(_z_condvar_t *cv) { return -1; } +z_result_t _z_condvar_drop(_z_condvar_t *cv) { return -1; } +z_result_t _z_condvar_signal(_z_condvar_t *cv) { return -1; } +z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { return -1; } +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return -1; } #endif // Z_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ @@ -204,4 +204,4 @@ unsigned long z_time_elapsed_ms(z_time_t *time) { unsigned long z_time_elapsed_s(z_time_t *time) { return z_time_elapsed_ms(time) / 1000; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t) { return -1; } +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t) { return -1; } diff --git a/src/system/mbed/network.cpp b/src/system/mbed/network.cpp index 8b96a86e9..310a107af 100644 --- a/src/system/mbed/network.cpp +++ b/src/system/mbed/network.cpp @@ -33,8 +33,8 @@ extern "C" { #if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ -int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; // Parse and check the validity of the port uint32_t port = strtoul(s_port, NULL, 10); @@ -49,8 +49,8 @@ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_tcp(_z_sys_net_endpoint_t *ep) { delete ep->_iptcp; } -int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_tcp = new TCPSocket(); sock->_tcp->set_timeout(tout); @@ -69,8 +69,8 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u return ret; } -int8_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; @@ -117,8 +117,8 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ -int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; // Parse and check the validity of the port uint32_t port = strtoul(s_port, NULL, 10); @@ -135,8 +135,8 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { delete ep->_iptcp; } #endif #if Z_FEATURE_LINK_UDP_UNICAST == 1 -int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)rep; @@ -153,8 +153,8 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ return ret; } -int8_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; (void)tout; @@ -206,9 +206,9 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s #endif #if Z_FEATURE_LINK_UDP_MULTICAST == 1 -int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, - uint32_t tout, const char *iface) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, + uint32_t tout, const char *iface) { + z_result_t ret = _Z_RES_OK; (void)(lep); // Multicast messages are not self-consumed, so no need to save the local address sock->_udp = new UDPSocket(); @@ -224,10 +224,10 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin return ret; } -int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, - const char *iface, const char *join) { +z_result_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, + const char *iface, const char *join) { (void)join; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; sock->_udp = new UDPSocket(); sock->_udp->set_timeout(tout); @@ -320,8 +320,8 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, #if Z_FEATURE_LINK_SERIAL == 1 -int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; sock->_serial = new BufferedSerial(PinName(txpin), PinName(rxpin), baudrate); if (sock->_serial != NULL) { @@ -335,8 +335,8 @@ int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint3 return ret; } -int8_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *device, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *device, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(device); @@ -346,8 +346,8 @@ int8_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *device, uint32_t return ret; } -int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)txpin; (void)rxpin; @@ -359,8 +359,8 @@ int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uin return ret; } -int8_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *device, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *device, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(device); @@ -373,7 +373,7 @@ int8_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *device, uint32 void _z_close_serial(_z_sys_net_socket_t *sock) { delete sock->_serial; } size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; uint8_t *before_cobs = new uint8_t[_Z_SERIAL_MAX_COBS_BUF_SIZE](); size_t rb = 0; @@ -442,7 +442,7 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t } size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; uint8_t *before_cobs = new uint8_t[_Z_SERIAL_MFS_SIZE](); size_t i = 0; diff --git a/src/system/mbed/system.cpp b/src/system/mbed/system.cpp index 036225e9b..5429cfd12 100644 --- a/src/system/mbed/system.cpp +++ b/src/system/mbed/system.cpp @@ -41,19 +41,19 @@ void z_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ -int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { +z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { *task = new Thread(); mbed::Callback c = mbed::Callback(fun, arg); return ((Thread *)*task)->start(c); } -int8_t _z_task_join(_z_task_t *task) { +z_result_t _z_task_join(_z_task_t *task) { int res = ((Thread *)*task)->join(); delete ((Thread *)*task); return res; } -int8_t _z_task_cancel(_z_task_t *task) { +z_result_t _z_task_cancel(_z_task_t *task) { int res = ((Thread *)*task)->terminate(); delete ((Thread *)*task); return res; @@ -66,47 +66,47 @@ void _z_task_free(_z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m) { +z_result_t _z_mutex_init(_z_mutex_t *m) { *m = new Mutex(); return 0; } -int8_t _z_mutex_drop(_z_mutex_t *m) { +z_result_t _z_mutex_drop(_z_mutex_t *m) { delete ((Mutex *)*m); return 0; } -int8_t _z_mutex_lock(_z_mutex_t *m) { +z_result_t _z_mutex_lock(_z_mutex_t *m) { ((Mutex *)*m)->lock(); return 0; } -int8_t _z_mutex_try_lock(_z_mutex_t *m) { return (((Mutex *)*m)->trylock() == true) ? 0 : -1; } +z_result_t _z_mutex_try_lock(_z_mutex_t *m) { return (((Mutex *)*m)->trylock() == true) ? 0 : -1; } -int8_t _z_mutex_unlock(_z_mutex_t *m) { +z_result_t _z_mutex_unlock(_z_mutex_t *m) { ((Mutex *)*m)->unlock(); return 0; } /*------------------ Condvar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t *cv) { return 0; } +z_result_t _z_condvar_init(_z_condvar_t *cv) { return 0; } -int8_t _z_condvar_drop(_z_condvar_t *cv) { +z_result_t _z_condvar_drop(_z_condvar_t *cv) { delete ((ConditionVariable *)*cv); return 0; } -int8_t _z_condvar_signal(_z_condvar_t *cv) { +z_result_t _z_condvar_signal(_z_condvar_t *cv) { ((ConditionVariable *)*cv)->notify_one(); return 0; } -int8_t _z_condvar_signal_all(_z_condvar_t *cv) { +z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { ((ConditionVariable *)*cv)->notify_all(); return 0; } -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { *cv = new ConditionVariable(*((Mutex *)*m)); ((ConditionVariable *)*cv)->wait(); return 0; @@ -189,7 +189,7 @@ unsigned long z_time_elapsed_s(z_time_t *time) { return elapsed; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t) { +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t) { z_time_t now; gettimeofday(&now, NULL); t->secs = now.tv_sec; diff --git a/src/system/platform-common.c b/src/system/platform-common.c index ab1a9d2e4..ba6616658 100644 --- a/src/system/platform-common.c +++ b/src/system/platform-common.c @@ -23,13 +23,13 @@ void _z_report_system_error(int errcode) { _Z_ERROR("System error: %i", errcode) /*------------------ Thread ------------------*/ _Z_OWNED_FUNCTIONS_SYSTEM_IMPL(_z_task_t, task) -int8_t z_task_init(z_owned_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { +z_result_t z_task_init(z_owned_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return _z_task_init(&task->_val, attr, fun, arg); } -int8_t z_task_join(z_owned_task_t *task) { +z_result_t z_task_join(z_owned_task_t *task) { _z_task_t *ptr = &task->_val; - int8_t ret = _z_task_join(ptr); + z_result_t ret = _z_task_join(ptr); _z_task_free(&ptr); return ret; } @@ -37,20 +37,20 @@ int8_t z_task_join(z_owned_task_t *task) { /*------------------ Mutex ------------------*/ _Z_OWNED_FUNCTIONS_SYSTEM_IMPL(_z_mutex_t, mutex) -int8_t z_mutex_init(z_owned_mutex_t *m) { return _z_mutex_init(&m->_val); } -int8_t z_mutex_drop(z_moved_mutex_t *m) { return _z_mutex_drop(&m->_this._val); } +z_result_t z_mutex_init(z_owned_mutex_t *m) { return _z_mutex_init(&m->_val); } +z_result_t z_mutex_drop(z_moved_mutex_t *m) { return _z_mutex_drop(&m->_this._val); } -int8_t z_mutex_lock(z_loaned_mutex_t *m) { return _z_mutex_lock(m); } -int8_t z_mutex_try_lock(z_loaned_mutex_t *m) { return _z_mutex_try_lock(m); } -int8_t z_mutex_unlock(z_loaned_mutex_t *m) { return _z_mutex_unlock(m); } +z_result_t z_mutex_lock(z_loaned_mutex_t *m) { return _z_mutex_lock(m); } +z_result_t z_mutex_try_lock(z_loaned_mutex_t *m) { return _z_mutex_try_lock(m); } +z_result_t z_mutex_unlock(z_loaned_mutex_t *m) { return _z_mutex_unlock(m); } /*------------------ CondVar ------------------*/ _Z_OWNED_FUNCTIONS_SYSTEM_IMPL(_z_condvar_t, condvar) -int8_t z_condvar_init(z_owned_condvar_t *cv) { return _z_condvar_init(&cv->_val); } -int8_t z_condvar_drop(z_moved_condvar_t *cv) { return _z_condvar_drop(&cv->_this._val); } +z_result_t z_condvar_init(z_owned_condvar_t *cv) { return _z_condvar_init(&cv->_val); } +z_result_t z_condvar_drop(z_moved_condvar_t *cv) { return _z_condvar_drop(&cv->_this._val); } -int8_t z_condvar_signal(z_loaned_condvar_t *cv) { return _z_condvar_signal(cv); } -int8_t z_condvar_wait(z_loaned_condvar_t *cv, z_loaned_mutex_t *m) { return _z_condvar_wait(cv, m); } +z_result_t z_condvar_signal(z_loaned_condvar_t *cv) { return _z_condvar_signal(cv); } +z_result_t z_condvar_wait(z_loaned_condvar_t *cv, z_loaned_mutex_t *m) { return _z_condvar_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 diff --git a/src/system/unix/link/raweth.c b/src/system/unix/link/raweth.c index 015894754..f1abcf325 100644 --- a/src/system/unix/link/raweth.c +++ b/src/system/unix/link/raweth.c @@ -32,7 +32,6 @@ #include "zenoh-pico/collections/string.h" #include "zenoh-pico/config.h" #include "zenoh-pico/protocol/keyexpr.h" -#include "zenoh-pico/system/link/raweth.h" #include "zenoh-pico/system/platform/unix.h" #include "zenoh-pico/utils/logging.h" #include "zenoh-pico/utils/pointers.h" @@ -46,8 +45,8 @@ void _z_raweth_clear_mapping_entry(_zp_raweth_mapping_entry_t *entry) { _z_keyexpr_clear(&entry->_keyexpr); } -int8_t _z_open_raweth(_z_sys_net_socket_t *sock, const char *interface) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_raweth(_z_sys_net_socket_t *sock, const char *interface) { + z_result_t ret = _Z_RES_OK; // Open a raw network socket in promiscuous mode sock->_fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if (sock->_fd == -1) { @@ -75,8 +74,8 @@ int8_t _z_open_raweth(_z_sys_net_socket_t *sock, const char *interface) { return ret; } -int8_t _z_close_raweth(_z_sys_net_socket_t *sock) { - int8_t ret = _Z_RES_OK; +z_result_t _z_close_raweth(_z_sys_net_socket_t *sock) { + z_result_t ret = _Z_RES_OK; if (close(sock->_fd) != 0) { ret = _Z_ERR_GENERIC; } diff --git a/src/system/unix/network.c b/src/system/unix/network.c index 95ae2ddf9..4e1b21036 100644 --- a/src/system/unix/network.c +++ b/src/system/unix/network.c @@ -34,8 +34,8 @@ #if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ -int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; struct addrinfo hints; (void)memset(&hints, 0, sizeof(hints)); @@ -54,8 +54,8 @@ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_tcp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } /*------------------ TCP sockets ------------------*/ -int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { @@ -106,8 +106,8 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u return ret; } -int8_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; @@ -160,8 +160,8 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ -int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; struct addrinfo hints; (void)memset(&hints, 0, sizeof(hints)); @@ -181,8 +181,8 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); #endif #if Z_FEATURE_LINK_UDP_UNICAST == 1 -int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { @@ -203,11 +203,11 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ return ret; } -int8_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { +z_result_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { (void)sock; (void)lep; (void)tout; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; // @TODO: To be implemented ret = _Z_ERR_GENERIC; @@ -290,9 +290,9 @@ unsigned int __get_ip_from_iface(const char *iface, int sa_family, struct sockad return addrlen; } -int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, - uint32_t tout, const char *iface) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, + uint32_t tout, const char *iface) { + z_result_t ret = _Z_RES_OK; struct sockaddr *lsockaddr = NULL; unsigned int addrlen = __get_ip_from_iface(iface, rep._iptcp->ai_family, &lsockaddr); @@ -368,9 +368,9 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin return ret; } -int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, - const char *iface, const char *join) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, + const char *iface, const char *join) { + z_result_t ret = _Z_RES_OK; struct sockaddr *lsockaddr = NULL; unsigned int addrlen = __get_ip_from_iface(iface, rep._iptcp->ai_family, &lsockaddr); diff --git a/src/system/unix/system.c b/src/system/unix/system.c index e38233daa..380f1b948 100644 --- a/src/system/unix/system.c +++ b/src/system/unix/system.c @@ -101,13 +101,13 @@ void z_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ -int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { +z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { _Z_CHECK_SYS_ERR(pthread_create(task, attr, fun, arg)); } -int8_t _z_task_join(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_join(*task, NULL)); } +z_result_t _z_task_join(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_join(*task, NULL)); } -int8_t _z_task_cancel(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_cancel(*task)); } +z_result_t _z_task_cancel(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_cancel(*task)); } void _z_task_free(_z_task_t **task) { _z_task_t *ptr = *task; @@ -116,26 +116,26 @@ void _z_task_free(_z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, 0)); } +z_result_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, 0)); } -int8_t _z_mutex_drop(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_destroy(m)); } +z_result_t _z_mutex_drop(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_destroy(m)); } -int8_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } +z_result_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } -int8_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } +z_result_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } -int8_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } +z_result_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } /*------------------ Condvar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, 0)); } +z_result_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, 0)); } -int8_t _z_condvar_drop(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } +z_result_t _z_condvar_drop(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } -int8_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } +z_result_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } -int8_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } +z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ @@ -228,7 +228,7 @@ unsigned long z_time_elapsed_s(z_time_t *time) { return elapsed; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t) { +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t) { z_time_t now; gettimeofday(&now, NULL); t->secs = (uint32_t)now.tv_sec; diff --git a/src/system/windows/network.c b/src/system/windows/network.c index 4d00ebd2a..21fc706b3 100644 --- a/src/system/windows/network.c +++ b/src/system/windows/network.c @@ -28,8 +28,8 @@ WSADATA wsaData; #if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ -int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; if (WSAStartup(MAKEWORD(2, 2), &wsaData) == 0) { ADDRINFOA hints; @@ -55,8 +55,8 @@ void _z_free_endpoint_tcp(_z_sys_net_endpoint_t *ep) { } /*------------------ TCP sockets ------------------*/ -int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { ret = _Z_ERR_GENERIC; @@ -110,8 +110,8 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u return ret; } -int8_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; @@ -161,8 +161,8 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ -int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; if (WSAStartup(MAKEWORD(2, 2), &wsaData) == 0) { ADDRINFOA hints; @@ -189,8 +189,8 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { #endif #if Z_FEATURE_LINK_UDP_UNICAST == 1 -int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { ret = _Z_ERR_GENERIC; @@ -213,11 +213,11 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ return ret; } -int8_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { +z_result_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { (void)sock; (void)lep; (void)tout; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; // @TODO: To be implemented ret = _Z_ERR_GENERIC; @@ -308,9 +308,9 @@ unsigned int __get_ip_from_iface(const char *iface, int sa_family, SOCKADDR **ls return addrlen; } -int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, - uint32_t tout, const char *iface) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, + uint32_t tout, const char *iface) { + z_result_t ret = _Z_RES_OK; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { ret = _Z_ERR_GENERIC; @@ -409,10 +409,10 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin return ret; } -int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, - const char *iface, const char *join) { +z_result_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, + const char *iface, const char *join) { (void)join; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { ret = _Z_ERR_GENERIC; diff --git a/src/system/windows/system.c b/src/system/windows/system.c index 6356fe077..55cefb569 100644 --- a/src/system/windows/system.c +++ b/src/system/windows/system.c @@ -60,9 +60,9 @@ void z_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ -int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { +z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { (void)(attr); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; *task = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)fun, arg, 0, NULL); if (*task == NULL) { ret = _Z_ERR_SYSTEM_TASK_FAILED; @@ -70,14 +70,14 @@ int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), return ret; } -int8_t _z_task_join(_z_task_t *task) { - int8_t ret = _Z_RES_OK; +z_result_t _z_task_join(_z_task_t *task) { + z_result_t ret = _Z_RES_OK; WaitForSingleObject(*task, INFINITE); return ret; } -int8_t _z_task_cancel(_z_task_t *task) { - int8_t ret = _Z_RES_OK; +z_result_t _z_task_cancel(_z_task_t *task) { + z_result_t ret = _Z_RES_OK; TerminateThread(*task, 0); return ret; } @@ -90,65 +90,65 @@ void _z_task_free(_z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m) { - int8_t ret = _Z_RES_OK; +z_result_t _z_mutex_init(_z_mutex_t *m) { + z_result_t ret = _Z_RES_OK; InitializeSRWLock(m); return ret; } -int8_t _z_mutex_drop(_z_mutex_t *m) { +z_result_t _z_mutex_drop(_z_mutex_t *m) { (void)(m); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; return ret; } -int8_t _z_mutex_lock(_z_mutex_t *m) { - int8_t ret = _Z_RES_OK; +z_result_t _z_mutex_lock(_z_mutex_t *m) { + z_result_t ret = _Z_RES_OK; AcquireSRWLockExclusive(m); return ret; } -int8_t _z_mutex_try_lock(_z_mutex_t *m) { - int8_t ret = _Z_RES_OK; +z_result_t _z_mutex_try_lock(_z_mutex_t *m) { + z_result_t ret = _Z_RES_OK; if (TryAcquireSRWLockExclusive(m) == 0) { ret = _Z_ERR_GENERIC; } return ret; } -int8_t _z_mutex_unlock(_z_mutex_t *m) { - int8_t ret = _Z_RES_OK; +z_result_t _z_mutex_unlock(_z_mutex_t *m) { + z_result_t ret = _Z_RES_OK; ReleaseSRWLockExclusive(m); return ret; } /*------------------ Condvar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t *cv) { - int8_t ret = _Z_RES_OK; +z_result_t _z_condvar_init(_z_condvar_t *cv) { + z_result_t ret = _Z_RES_OK; InitializeConditionVariable(cv); return ret; } -int8_t _z_condvar_drop(_z_condvar_t *cv) { +z_result_t _z_condvar_drop(_z_condvar_t *cv) { (void)(cv); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; return ret; } -int8_t _z_condvar_signal(_z_condvar_t *cv) { - int8_t ret = _Z_RES_OK; +z_result_t _z_condvar_signal(_z_condvar_t *cv) { + z_result_t ret = _Z_RES_OK; WakeConditionVariable(cv); return ret; } -int8_t _z_condvar_signal_all(_z_condvar_t *cv) { - int8_t ret = _Z_RES_OK; +z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { + z_result_t ret = _Z_RES_OK; WakeAllConditionVariable(cv); return ret; } -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { - int8_t ret = _Z_RES_OK; +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { + z_result_t ret = _Z_RES_OK; SleepConditionVariableSRW(cv, m, INFINITE, 0); return ret; } @@ -264,7 +264,7 @@ unsigned long z_time_elapsed_s(z_time_t *time) { return elapsed; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t) { +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t) { z_time_t now; ftime(&now); t->secs = (uint32_t)now.time; diff --git a/src/system/zephyr/network.c b/src/system/zephyr/network.c index c115d95fb..f5ed536d9 100644 --- a/src/system/zephyr/network.c +++ b/src/system/zephyr/network.c @@ -36,8 +36,8 @@ #if Z_FEATURE_LINK_TCP == 1 /*------------------ TCP sockets ------------------*/ -int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; struct addrinfo hints; (void)memset(&hints, 0, sizeof(hints)); @@ -55,8 +55,8 @@ int8_t _z_create_endpoint_tcp(_z_sys_net_endpoint_t *ep, const char *s_address, void _z_free_endpoint_tcp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); } -int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { @@ -99,8 +99,8 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u return ret; } -int8_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; @@ -149,8 +149,8 @@ size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t le #if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1 /*------------------ UDP sockets ------------------*/ -int8_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { - int8_t ret = _Z_RES_OK; +z_result_t _z_create_endpoint_udp(_z_sys_net_endpoint_t *ep, const char *s_address, const char *s_port) { + z_result_t ret = _Z_RES_OK; struct addrinfo hints; (void)memset(&hints, 0, sizeof(hints)); @@ -170,8 +170,8 @@ void _z_free_endpoint_udp(_z_sys_net_endpoint_t *ep) { freeaddrinfo(ep->_iptcp); #endif #if Z_FEATURE_LINK_UDP_UNICAST == 1 -int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { @@ -193,8 +193,8 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ return ret; } -int8_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t lep, uint32_t tout) { + z_result_t ret = _Z_RES_OK; (void)sock; (void)lep; (void)tout; @@ -244,9 +244,9 @@ size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, s #endif #if Z_FEATURE_LINK_UDP_MULTICAST == 1 -int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, - uint32_t tout, const char *iface) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, _z_sys_net_endpoint_t *lep, + uint32_t tout, const char *iface) { + z_result_t ret = _Z_RES_OK; struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; @@ -336,10 +336,10 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin return ret; } -int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, - const char *iface, const char *join) { +z_result_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, uint32_t tout, + const char *iface, const char *join) { (void)join; - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; @@ -554,8 +554,8 @@ size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, #endif // Z_FEATURE_LINK_UDP_MULTICAST == 1 #if Z_FEATURE_LINK_SERIAL == 1 -int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(txpin); (void)(rxpin); @@ -567,8 +567,8 @@ int8_t _z_open_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint3 return ret; } -int8_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; sock->_serial = device_get_binding(dev); if (sock->_serial != NULL) { @@ -589,8 +589,8 @@ int8_t _z_open_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t ba return ret; } -int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uint32_t rxpin, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(txpin); (void)(rxpin); @@ -602,8 +602,8 @@ int8_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin, uin return ret; } -int8_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { - int8_t ret = _Z_RES_OK; +z_result_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate) { + z_result_t ret = _Z_RES_OK; (void)(sock); (void)(dev); (void)(baudrate); @@ -617,7 +617,7 @@ int8_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t void _z_close_serial(_z_sys_net_socket_t *sock) {} size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; uint8_t *before_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); size_t rb = 0; @@ -690,7 +690,7 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t } size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; uint8_t *before_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MFS_SIZE); size_t i = 0; diff --git a/src/system/zephyr/system.c b/src/system/zephyr/system.c index 8cb8e89d1..f592f725c 100644 --- a/src/system/zephyr/system.c +++ b/src/system/zephyr/system.c @@ -71,7 +71,7 @@ K_THREAD_STACK_ARRAY_DEFINE(thread_stack_area, Z_THREADS_NUM, Z_PTHREAD_STACK_SI static int thread_index = 0; /*------------------ Task ------------------*/ -int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { +z_result_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { z_task_attr_t *lattr = NULL; z_task_attr_t tmp; if (attr == NULL) { @@ -83,9 +83,9 @@ int8_t _z_task_init(_z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), _Z_CHECK_SYS_ERR(pthread_create(task, lattr, fun, arg)); } -int8_t _z_task_join(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_join(*task, NULL)); } +z_result_t _z_task_join(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_join(*task, NULL)); } -int8_t _z_task_cancel(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_cancel(*task)); } +z_result_t _z_task_cancel(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_cancel(*task)); } void _z_task_free(_z_task_t **task) { _z_task_t *ptr = *task; @@ -94,31 +94,31 @@ void _z_task_free(_z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, 0)); } +z_result_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, 0)); } -int8_t _z_mutex_drop(_z_mutex_t *m) { +z_result_t _z_mutex_drop(_z_mutex_t *m) { if (m == NULL) { return 0; } _Z_CHECK_SYS_ERR(pthread_mutex_destroy(m)); } -int8_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } +z_result_t _z_mutex_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_lock(m)); } -int8_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } +z_result_t _z_mutex_try_lock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_trylock(m)); } -int8_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } +z_result_t _z_mutex_unlock(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_unlock(m)); } /*------------------ Condvar ------------------*/ -int8_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, 0)); } +z_result_t _z_condvar_init(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_init(cv, 0)); } -int8_t _z_condvar_drop(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } +z_result_t _z_condvar_drop(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_destroy(cv)); } -int8_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } +z_result_t _z_condvar_signal(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_signal(cv)); } -int8_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } +z_result_t _z_condvar_signal_all(_z_condvar_t *cv) { _Z_CHECK_SYS_ERR(pthread_cond_broadcast(cv)); } -int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } +z_result_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_cond_wait(cv, m)); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ @@ -224,7 +224,7 @@ unsigned long z_time_elapsed_s(z_time_t *time) { return elapsed; } -int8_t zp_get_time_since_epoch(zp_time_since_epoch *t) { +z_result_t zp_get_time_since_epoch(zp_time_since_epoch *t) { z_time_t now; gettimeofday(&now, NULL); t->secs = now.tv_sec; diff --git a/src/transport/common/lease.c b/src/transport/common/lease.c index 3079e9484..0617e9abb 100644 --- a/src/transport/common/lease.c +++ b/src/transport/common/lease.c @@ -19,8 +19,8 @@ #include "zenoh-pico/transport/multicast/lease.h" #include "zenoh-pico/transport/unicast/lease.h" -int8_t _z_send_keep_alive(_z_transport_t *zt) { - int8_t ret = _Z_RES_OK; +z_result_t _z_send_keep_alive(_z_transport_t *zt) { + z_result_t ret = _Z_RES_OK; switch (zt->_type) { case _Z_TRANSPORT_UNICAST_TYPE: ret = _zp_unicast_send_keep_alive(&zt->_transport._unicast); @@ -38,8 +38,8 @@ int8_t _z_send_keep_alive(_z_transport_t *zt) { return ret; } -int8_t _z_send_join(_z_transport_t *zt) { - int8_t ret = _Z_RES_OK; +z_result_t _z_send_join(_z_transport_t *zt) { + z_result_t ret = _Z_RES_OK; // Join task only applies to multicast transports switch (zt->_type) { case _Z_TRANSPORT_MULTICAST_TYPE: diff --git a/src/transport/common/read.c b/src/transport/common/read.c index d7db6c61d..efab9dbed 100644 --- a/src/transport/common/read.c +++ b/src/transport/common/read.c @@ -20,8 +20,8 @@ #include "zenoh-pico/transport/raweth/read.h" #include "zenoh-pico/transport/unicast/read.h" -int8_t _z_read(_z_transport_t *zt) { - int8_t ret = _Z_RES_OK; +z_result_t _z_read(_z_transport_t *zt) { + z_result_t ret = _Z_RES_OK; switch (zt->_type) { case _Z_TRANSPORT_UNICAST_TYPE: ret = _zp_unicast_read(&zt->_transport._unicast); diff --git a/src/transport/common/rx.c b/src/transport/common/rx.c index fd8343f8b..5c5c68073 100644 --- a/src/transport/common/rx.c +++ b/src/transport/common/rx.c @@ -32,8 +32,8 @@ size_t _z_read_stream_size(_z_zbuf_t *zbuf) { return _z_host_le_load16(stream_size); } -int8_t _z_link_recv_t_msg(_z_transport_message_t *t_msg, const _z_link_t *zl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_link_recv_t_msg(_z_transport_message_t *t_msg, const _z_link_t *zl) { + z_result_t ret = _Z_RES_OK; // Create and prepare the buffer _z_zbuf_t zbf = _z_zbuf_make(Z_BATCH_UNICAST_SIZE); diff --git a/src/transport/common/tx.c b/src/transport/common/tx.c index 6821bedaa..75a837cbe 100644 --- a/src/transport/common/tx.c +++ b/src/transport/common/tx.c @@ -70,8 +70,8 @@ void __unsafe_z_finalize_wbuf(_z_wbuf_t *buf, uint8_t link_flow_capability) { } } -int8_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg) { + z_result_t ret = _Z_RES_OK; switch (zt->_type) { case _Z_TRANSPORT_UNICAST_TYPE: ret = _z_unicast_send_t_msg(&zt->_transport._unicast, t_msg); @@ -89,8 +89,8 @@ int8_t _z_send_t_msg(_z_transport_t *zt, const _z_transport_message_t *t_msg) { return ret; } -int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg) { + z_result_t ret = _Z_RES_OK; // Create and prepare the buffer to serialize the message on uint16_t mtu = (zl->_mtu < Z_BATCH_UNICAST_SIZE) ? zl->_mtu : Z_BATCH_UNICAST_SIZE; @@ -135,8 +135,8 @@ int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_m return ret; } -int8_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z_reliability_t reliability, size_t sn) { - int8_t ret = _Z_RES_OK; +z_result_t __unsafe_z_serialize_zenoh_fragment(_z_wbuf_t *dst, _z_wbuf_t *src, z_reliability_t reliability, size_t sn) { + z_result_t ret = _Z_RES_OK; // Assume first that this is not the final fragment bool is_final = false; diff --git a/src/transport/manager.c b/src/transport/manager.c index 5d9f1646c..360f5329d 100644 --- a/src/transport/manager.c +++ b/src/transport/manager.c @@ -20,8 +20,8 @@ #include "zenoh-pico/transport/multicast/transport.h" #include "zenoh-pico/transport/unicast/transport.h" -int8_t _z_new_transport_client(_z_transport_t *zt, _z_string_t *locator, _z_id_t *local_zid) { - int8_t ret = _Z_RES_OK; +z_result_t _z_new_transport_client(_z_transport_t *zt, _z_string_t *locator, _z_id_t *local_zid) { + z_result_t ret = _Z_RES_OK; // Init link _z_link_t zl; memset(&zl, 0, sizeof(_z_link_t)); @@ -62,8 +62,8 @@ int8_t _z_new_transport_client(_z_transport_t *zt, _z_string_t *locator, _z_id_t return ret; } -int8_t _z_new_transport_peer(_z_transport_t *zt, _z_string_t *locator, _z_id_t *local_zid) { - int8_t ret = _Z_RES_OK; +z_result_t _z_new_transport_peer(_z_transport_t *zt, _z_string_t *locator, _z_id_t *local_zid) { + z_result_t ret = _Z_RES_OK; // Init link _z_link_t zl; memset(&zl, 0, sizeof(_z_link_t)); @@ -101,8 +101,8 @@ int8_t _z_new_transport_peer(_z_transport_t *zt, _z_string_t *locator, _z_id_t * return ret; } -int8_t _z_new_transport(_z_transport_t *zt, _z_id_t *bs, _z_string_t *locator, z_whatami_t mode) { - int8_t ret; +z_result_t _z_new_transport(_z_transport_t *zt, _z_id_t *bs, _z_string_t *locator, z_whatami_t mode) { + z_result_t ret; if (mode == Z_WHATAMI_CLIENT) { ret = _z_new_transport_client(zt, locator, bs); diff --git a/src/transport/multicast/lease.c b/src/transport/multicast/lease.c index f9b5e78f3..50c299f3a 100644 --- a/src/transport/multicast/lease.c +++ b/src/transport/multicast/lease.c @@ -12,18 +12,18 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/multicast/lease.h" +#include "zenoh-pico/transport/common/lease.h" #include #include "zenoh-pico/config.h" #include "zenoh-pico/session/utils.h" -#include "zenoh-pico/transport/common/lease.h" +#include "zenoh-pico/transport/multicast/lease.h" #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1 -int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { +z_result_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { _z_conduit_sn_list_t next_sn; next_sn._is_qos = false; next_sn._val._plain._best_effort = ztm->_sn_tx_best_effort; @@ -35,18 +35,18 @@ int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { return ztm->_send_f(ztm, &jsm); } -int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { +z_result_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { _z_transport_message_t t_msg = _z_t_msg_make_keep_alive(); return ztm->_send_f(ztm, &t_msg); } #else -int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { +z_result_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { +z_result_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -186,7 +186,7 @@ void *_zp_multicast_lease_task(void *ztm_arg) { return 0; } -int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, z_task_attr_t *attr, _z_task_t *task) { +z_result_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); ztm->_lease_task_running = true; // Init before z_task_init for concurrency issue @@ -200,7 +200,7 @@ int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, z_task_attr return _Z_RES_OK; } -int8_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm) { +z_result_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm) { ztm->_lease_task_running = false; return _Z_RES_OK; } @@ -211,14 +211,14 @@ void *_zp_multicast_lease_task(void *ztm_arg) { return NULL; } -int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, void *attr, void *task) { +z_result_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, void *attr, void *task) { _ZP_UNUSED(ztm); _ZP_UNUSED(attr); _ZP_UNUSED(task); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm) { +z_result_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } diff --git a/src/transport/multicast/read.c b/src/transport/multicast/read.c index 5565dd005..965f11a32 100644 --- a/src/transport/multicast/read.c +++ b/src/transport/multicast/read.c @@ -26,8 +26,8 @@ #if Z_FEATURE_MULTICAST_TRANSPORT == 1 -int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) { - int8_t ret = _Z_RES_OK; +z_result_t _zp_multicast_read(_z_transport_multicast_t *ztm) { + z_result_t ret = _Z_RES_OK; _z_slice_t addr; _z_transport_message_t t_msg; @@ -40,7 +40,7 @@ int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) { return ret; } #else -int8_t _zp_multicast_read(_z_transport_multicast_t *ztm) { +z_result_t _zp_multicast_read(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -98,7 +98,7 @@ void *_zp_multicast_read_task(void *ztm_arg) { _z_zbuf_t zbuf = _z_zbuf_view(&ztm->_zbuf, to_read); while (_z_zbuf_len(&zbuf) > 0) { - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; // Decode one session message _z_transport_message_t t_msg; @@ -127,7 +127,7 @@ void *_zp_multicast_read_task(void *ztm_arg) { return NULL; } -int8_t _zp_multicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { +z_result_t _zp_multicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); zt->_transport._multicast._read_task_running = true; // Init before z_task_init for concurrency issue @@ -141,7 +141,7 @@ int8_t _zp_multicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z return _Z_RES_OK; } -int8_t _zp_multicast_stop_read_task(_z_transport_t *zt) { +z_result_t _zp_multicast_stop_read_task(_z_transport_t *zt) { zt->_transport._multicast._read_task_running = false; return _Z_RES_OK; } @@ -152,14 +152,14 @@ void *_zp_multicast_read_task(void *ztm_arg) { return NULL; } -int8_t _zp_multicast_start_read_task(_z_transport_t *zt, void *attr, void *task) { +z_result_t _zp_multicast_start_read_task(_z_transport_t *zt, void *attr, void *task) { _ZP_UNUSED(zt); _ZP_UNUSED(attr); _ZP_UNUSED(task); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _zp_multicast_stop_read_task(_z_transport_t *zt) { +z_result_t _zp_multicast_stop_read_task(_z_transport_t *zt) { _ZP_UNUSED(zt); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } diff --git a/src/transport/multicast/rx.c b/src/transport/multicast/rx.c index 73e40dee1..d531c6199 100644 --- a/src/transport/multicast/rx.c +++ b/src/transport/multicast/rx.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/multicast/rx.h" +#include "zenoh-pico/transport/common/rx.h" #include #include @@ -24,15 +24,15 @@ #include "zenoh-pico/protocol/definitions/transport.h" #include "zenoh-pico/protocol/iobuf.h" #include "zenoh-pico/session/utils.h" -#include "zenoh-pico/transport/common/rx.h" +#include "zenoh-pico/transport/multicast/rx.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_MULTICAST_TRANSPORT == 1 -static int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, - _z_slice_t *addr) { +static z_result_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, + _z_slice_t *addr) { _Z_DEBUG(">> recv session msg"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock @@ -89,11 +89,11 @@ static int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_trans return ret; } -int8_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { +z_result_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { return _z_multicast_recv_t_msg_na(ztm, t_msg, addr); } #else -int8_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { +z_result_t _z_multicast_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { _ZP_UNUSED(ztm); _ZP_UNUSED(t_msg); _ZP_UNUSED(addr); @@ -121,9 +121,9 @@ static _z_transport_peer_entry_t *_z_find_peer_entry(_z_transport_peer_entry_lis return ret; } -int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, - _z_slice_t *addr) { - int8_t ret = _Z_RES_OK; +z_result_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, + _z_slice_t *addr) { + z_result_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 // Acquire and keep the lock _z_mutex_lock(&ztm->_mutex_peer); @@ -351,8 +351,8 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t return ret; } #else -int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, - _z_slice_t *addr) { +z_result_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, + _z_slice_t *addr) { _ZP_UNUSED(ztm); _ZP_UNUSED(t_msg); _ZP_UNUSED(addr); diff --git a/src/transport/multicast/transport.c b/src/transport/multicast/transport.c index 75835cdd2..d0f6abb3a 100644 --- a/src/transport/multicast/transport.c +++ b/src/transport/multicast/transport.c @@ -31,9 +31,9 @@ #if Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1 -int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, - _z_transport_multicast_establish_param_t *param) { - int8_t ret = _Z_RES_OK; +z_result_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, + _z_transport_multicast_establish_param_t *param) { + z_result_t ret = _Z_RES_OK; // Transport specific information _z_transport_multicast_t *ztm = NULL; switch (zl->_cap._transport) { @@ -119,9 +119,9 @@ int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, return ret; } -int8_t _z_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid) { - int8_t ret = _Z_RES_OK; +z_result_t _z_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid) { + z_result_t ret = _Z_RES_OK; _z_zint_t initial_sn_tx = 0; z_random_fill(&initial_sn_tx, sizeof(initial_sn_tx)); @@ -156,18 +156,18 @@ int8_t _z_multicast_open_peer(_z_transport_multicast_establish_param_t *param, c return ret; } -int8_t _z_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid) { +z_result_t _z_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid) { _ZP_UNUSED(param); _ZP_UNUSED(zl); _ZP_UNUSED(local_zid); - int8_t ret = _Z_ERR_CONFIG_UNSUPPORTED_CLIENT_MULTICAST; + z_result_t ret = _Z_ERR_CONFIG_UNSUPPORTED_CLIENT_MULTICAST; // @TODO: not implemented return ret; } -int8_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, bool link_only) { - int8_t ret = _Z_RES_OK; +z_result_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, bool link_only) { + z_result_t ret = _Z_RES_OK; // Send and clear message _z_transport_message_t cm = _z_t_msg_make_close(reason, link_only); ret = ztm->_send_f(ztm, &cm); @@ -175,7 +175,7 @@ int8_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, bo return ret; } -int8_t _z_multicast_transport_close(_z_transport_multicast_t *ztm, uint8_t reason) { +z_result_t _z_multicast_transport_close(_z_transport_multicast_t *ztm, uint8_t reason) { return _z_multicast_send_close(ztm, reason, false); } @@ -208,38 +208,38 @@ void _z_multicast_transport_clear(_z_transport_t *zt) { #else -int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, - _z_transport_multicast_establish_param_t *param) { +z_result_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, + _z_transport_multicast_establish_param_t *param) { _ZP_UNUSED(zt); _ZP_UNUSED(zl); _ZP_UNUSED(param); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid) { +z_result_t _z_multicast_open_peer(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid) { _ZP_UNUSED(param); _ZP_UNUSED(zl); _ZP_UNUSED(local_zid); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid) { +z_result_t _z_multicast_open_client(_z_transport_multicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid) { _ZP_UNUSED(param); _ZP_UNUSED(zl); _ZP_UNUSED(local_zid); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, bool link_only) { +z_result_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason, bool link_only) { _ZP_UNUSED(ztm); _ZP_UNUSED(reason); _ZP_UNUSED(link_only); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_multicast_transport_close(_z_transport_multicast_t *ztm, uint8_t reason) { +z_result_t _z_multicast_transport_close(_z_transport_multicast_t *ztm, uint8_t reason) { _ZP_UNUSED(ztm); _ZP_UNUSED(reason); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; diff --git a/src/transport/multicast/tx.c b/src/transport/multicast/tx.c index d51f4b3cf..eedd49509 100644 --- a/src/transport/multicast/tx.c +++ b/src/transport/multicast/tx.c @@ -12,12 +12,12 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/multicast/tx.h" +#include "zenoh-pico/transport/common/tx.h" #include "zenoh-pico/config.h" #include "zenoh-pico/protocol/codec/network.h" #include "zenoh-pico/protocol/codec/transport.h" -#include "zenoh-pico/transport/common/tx.h" +#include "zenoh-pico/transport/multicast/tx.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" @@ -40,8 +40,8 @@ _z_zint_t __unsafe_z_multicast_get_sn(_z_transport_multicast_t *ztm, z_reliabili return sn; } -int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG(">> send session message"); #if Z_FEATURE_MULTI_THREAD == 1 @@ -71,9 +71,9 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport return ret; } -int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG(">> send network message"); _z_transport_multicast_t *ztm = &zn->_tp._transport._multicast; @@ -86,8 +86,8 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m #endif // Z_FEATURE_MULTI_THREAD == 1 } else { #if Z_FEATURE_MULTI_THREAD == 1 - int8_t locked = _z_mutex_try_lock(&ztm->_mutex_tx); - if (locked != (int8_t)0) { + z_result_t locked = _z_mutex_try_lock(&ztm->_mutex_tx); + if (locked != 0) { _Z_INFO("Dropping zenoh message because of congestion control"); // We failed to acquire the lock, drop the message drop = true; @@ -161,14 +161,14 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m } #else -int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg) { +z_result_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg) { _ZP_UNUSED(ztm); _ZP_UNUSED(t_msg); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl) { +z_result_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl) { _ZP_UNUSED(zn); _ZP_UNUSED(n_msg); _ZP_UNUSED(reliability); diff --git a/src/transport/raweth/link.c b/src/transport/raweth/link.c index 75ebdfac0..7ef740082 100644 --- a/src/transport/raweth/link.c +++ b/src/transport/raweth/link.c @@ -70,16 +70,16 @@ static const char *_z_get_iface_raweth(_z_str_intmap_t *config); static bool _z_valid_ethtype_raweth(_z_str_intmap_t *config); static long _z_get_ethtype_raweth(_z_str_intmap_t *config); static size_t _z_valid_mapping_raweth(_z_str_intmap_t *config); -static int8_t _z_get_mapping_raweth(_z_str_intmap_t *config, _zp_raweth_mapping_array_t *array, size_t size); +static z_result_t _z_get_mapping_raweth(_z_str_intmap_t *config, _zp_raweth_mapping_array_t *array, size_t size); static size_t _z_valid_whitelist_raweth(_z_str_intmap_t *config); -static int8_t _z_get_whitelist_raweth(_z_str_intmap_t *config, _zp_raweth_whitelist_array_t *array, size_t size); -static int8_t _z_get_mapping_entry(char *entry, _zp_raweth_mapping_entry_t *storage); +static z_result_t _z_get_whitelist_raweth(_z_str_intmap_t *config, _zp_raweth_whitelist_array_t *array, size_t size); +static z_result_t _z_get_mapping_entry(char *entry, _zp_raweth_mapping_entry_t *storage); static bool _z_valid_mapping_entry(char *entry); static bool _z_valid_address_raweth_inner(const _z_string_t *address); static bool _z_valid_address_raweth(const char *address); static uint8_t *_z_parse_address_raweth(const char *address); -static int8_t _z_f_link_open_raweth(_z_link_t *self); -static int8_t _z_f_link_listen_raweth(_z_link_t *self); +static z_result_t _z_f_link_open_raweth(_z_link_t *self); +static z_result_t _z_f_link_listen_raweth(_z_link_t *self); static void _z_f_link_close_raweth(_z_link_t *self); static void _z_f_link_free_raweth(_z_link_t *self); static size_t _z_f_link_write_raweth(const _z_link_t *self, const uint8_t *ptr, size_t len); @@ -140,7 +140,7 @@ static size_t _z_valid_mapping_raweth(_z_str_intmap_t *config) { return size; } -static int8_t _z_get_mapping_raweth(_z_str_intmap_t *config, _zp_raweth_mapping_array_t *array, size_t size) { +static z_result_t _z_get_mapping_raweth(_z_str_intmap_t *config, _zp_raweth_mapping_array_t *array, size_t size) { // Retrieve data const char *cfg_str = _z_str_intmap_get(config, RAWETH_CONFIG_MAPPING_KEY); if (cfg_str == NULL) { @@ -206,7 +206,7 @@ static size_t _z_valid_whitelist_raweth(_z_str_intmap_t *config) { return size; } -static int8_t _z_get_whitelist_raweth(_z_str_intmap_t *config, _zp_raweth_whitelist_array_t *array, size_t size) { +static z_result_t _z_get_whitelist_raweth(_z_str_intmap_t *config, _zp_raweth_whitelist_array_t *array, size_t size) { // Retrieve data const char *cfg_str = _z_str_intmap_get(config, RAWETH_CONFIG_WHITELIST_KEY); if (cfg_str == NULL) { @@ -246,7 +246,7 @@ static int8_t _z_get_whitelist_raweth(_z_str_intmap_t *config, _zp_raweth_whitel return _Z_RES_OK; } -static int8_t _z_get_mapping_entry(char *entry, _zp_raweth_mapping_entry_t *storage) { +static z_result_t _z_get_mapping_entry(char *entry, _zp_raweth_mapping_entry_t *storage) { size_t len = strlen(entry); const char *entry_end = &entry[len - (size_t)1]; @@ -358,7 +358,7 @@ static uint8_t *_z_parse_address_raweth(const char *address) { return ret; } -static int8_t _z_f_link_open_raweth(_z_link_t *self) { +static z_result_t _z_f_link_open_raweth(_z_link_t *self) { // Init arrays self->_socket._raweth._mapping = _zp_raweth_mapping_array_empty(); self->_socket._raweth._whitelist = _zp_raweth_whitelist_array_empty(); @@ -409,7 +409,7 @@ static int8_t _z_f_link_open_raweth(_z_link_t *self) { return _z_open_raweth(&self->_socket._raweth._sock, self->_socket._raweth._interface); } -static int8_t _z_f_link_listen_raweth(_z_link_t *self) { return _z_f_link_open_raweth(self); } +static z_result_t _z_f_link_listen_raweth(_z_link_t *self) { return _z_f_link_open_raweth(self); } static void _z_f_link_close_raweth(_z_link_t *self) { // Close connection @@ -455,8 +455,8 @@ static size_t _z_f_link_read_exact_raweth(const _z_link_t *self, uint8_t *ptr, s static uint16_t _z_get_link_mtu_raweth(void) { return _ZP_MAX_ETH_FRAME_SIZE; } -int8_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint) { + z_result_t ret = _Z_RES_OK; // Check the root _z_string_t str_cmp = _z_string_alias_str(RAWETH_SCHEMA); @@ -466,8 +466,8 @@ int8_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint) { return ret; } -int8_t _z_new_link_raweth(_z_link_t *zl, _z_endpoint_t endpoint) { - int8_t ret = _Z_RES_OK; +z_result_t _z_new_link_raweth(_z_link_t *zl, _z_endpoint_t endpoint) { + z_result_t ret = _Z_RES_OK; zl->_cap._transport = Z_LINK_CAP_TRANSPORT_RAWETH; zl->_cap._is_reliable = false; @@ -500,18 +500,18 @@ char *_z_raweth_config_to_str(const _z_str_intmap_t *s) { return _z_str_intmap_to_str(s, RAWETH_CONFIG_ARGC, args); } -int8_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s) { +z_result_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s) { RAWETH_CONFIG_MAPPING_BUILD return _z_str_intmap_from_strn(strint, s, RAWETH_CONFIG_ARGC, args, strlen(s)); } #else -int8_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint) { +z_result_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint) { _ZP_UNUSED(endpoint); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_new_link_raweth(_z_link_t *zl, _z_endpoint_t endpoint) { +z_result_t _z_new_link_raweth(_z_link_t *zl, _z_endpoint_t endpoint) { _ZP_UNUSED(zl); _ZP_UNUSED(endpoint); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; @@ -526,7 +526,7 @@ char *_z_raweth_config_to_str(const _z_str_intmap_t *s) { return NULL; } -int8_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s) { +z_result_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s) { _ZP_UNUSED(strint); _ZP_UNUSED(s); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; diff --git a/src/transport/raweth/read.c b/src/transport/raweth/read.c index 81cf0fd3d..a2f080e7b 100644 --- a/src/transport/raweth/read.c +++ b/src/transport/raweth/read.c @@ -26,8 +26,8 @@ #if Z_FEATURE_RAWETH_TRANSPORT == 1 -int8_t _zp_raweth_read(_z_transport_multicast_t *ztm) { - int8_t ret = _Z_RES_OK; +z_result_t _zp_raweth_read(_z_transport_multicast_t *ztm) { + z_result_t ret = _Z_RES_OK; _z_slice_t addr; _z_transport_message_t t_msg; @@ -41,7 +41,7 @@ int8_t _zp_raweth_read(_z_transport_multicast_t *ztm) { } #else -int8_t _zp_raweth_read(_z_transport_multicast_t *ztm) { +z_result_t _zp_raweth_read(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -57,7 +57,7 @@ void *_zp_raweth_read_task(void *ztm_arg) { // Task loop while (ztm->_read_task_running == true) { // Read message from link - int8_t ret = _z_raweth_recv_t_msg(ztm, &t_msg, &addr); + z_result_t ret = _z_raweth_recv_t_msg(ztm, &t_msg, &addr); switch (ret) { case _Z_RES_OK: // Process message @@ -87,7 +87,7 @@ void *_zp_raweth_read_task(void *ztm_arg) { return NULL; } -int8_t _zp_raweth_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { +z_result_t _zp_raweth_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); zt->_transport._unicast._lease_task_running = true; // Init before z_task_init for concurrency issue @@ -101,7 +101,7 @@ int8_t _zp_raweth_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_ta return _Z_RES_OK; } -int8_t _zp_raweth_stop_read_task(_z_transport_t *zt) { +z_result_t _zp_raweth_stop_read_task(_z_transport_t *zt) { zt->_transport._raweth._read_task_running = false; return _Z_RES_OK; } @@ -111,14 +111,14 @@ void *_zp_raweth_read_task(void *ztm_arg) { _ZP_UNUSED(ztm_arg); return NULL; } -int8_t _zp_raweth_start_read_task(_z_transport_t *zt, void *attr, void *task) { +z_result_t _zp_raweth_start_read_task(_z_transport_t *zt, void *attr, void *task) { _ZP_UNUSED(zt); _ZP_UNUSED(attr); _ZP_UNUSED(task); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _zp_raweth_stop_read_task(_z_transport_t *zt) { +z_result_t _zp_raweth_stop_read_task(_z_transport_t *zt) { _ZP_UNUSED(zt); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } diff --git a/src/transport/raweth/rx.c b/src/transport/raweth/rx.c index b186c4b9b..59b57e512 100644 --- a/src/transport/raweth/rx.c +++ b/src/transport/raweth/rx.c @@ -73,9 +73,9 @@ static size_t _z_raweth_link_recv_zbuf(const _z_link_t *link, _z_zbuf_t *zbf, _z } /*------------------ Reception helper ------------------*/ -int8_t _z_raweth_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { +z_result_t _z_raweth_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { _Z_DEBUG(">> recv session msg"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock @@ -113,12 +113,12 @@ int8_t _z_raweth_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_messa return ret; } -int8_t _z_raweth_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { +z_result_t _z_raweth_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { return _z_raweth_recv_t_msg_na(ztm, t_msg, addr); } #else -int8_t _z_raweth_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { +z_result_t _z_raweth_recv_t_msg(_z_transport_multicast_t *ztm, _z_transport_message_t *t_msg, _z_slice_t *addr) { _ZP_UNUSED(ztm); _ZP_UNUSED(t_msg); _ZP_UNUSED(addr); diff --git a/src/transport/raweth/tx.c b/src/transport/raweth/tx.c index ecfc26fd1..b4ddc5def 100644 --- a/src/transport/raweth/tx.c +++ b/src/transport/raweth/tx.c @@ -48,8 +48,8 @@ static int _zp_raweth_find_map_entry(const _z_keyexpr_t *keyexpr, _z_raweth_sock return -1; } -static int8_t _zp_raweth_set_socket(const _z_keyexpr_t *keyexpr, _z_raweth_socket_t *sock) { - int8_t ret = _Z_RES_OK; +static z_result_t _zp_raweth_set_socket(const _z_keyexpr_t *keyexpr, _z_raweth_socket_t *sock) { + z_result_t ret = _Z_RES_OK; if (_zp_raweth_mapping_array_len(&sock->_mapping) < 1) { return _Z_ERR_GENERIC; @@ -116,7 +116,7 @@ static void __unsafe_z_raweth_prepare_header(_z_link_t *zl, _z_wbuf_t *wbf) { * Make sure that the following mutexes are locked before calling this function: * - ztm->_mutex_inner */ -static int8_t __unsafe_z_raweth_write_header(_z_link_t *zl, _z_wbuf_t *wbf) { +static z_result_t __unsafe_z_raweth_write_header(_z_link_t *zl, _z_wbuf_t *wbf) { _z_raweth_socket_t *resocket = &zl->_socket._raweth; // Save and reset buffer position size_t wpos = _z_wbuf_len(wbf); @@ -149,8 +149,8 @@ static int8_t __unsafe_z_raweth_write_header(_z_link_t *zl, _z_wbuf_t *wbf) { return _Z_RES_OK; } -static int8_t _z_raweth_link_send_wbuf(const _z_link_t *zl, const _z_wbuf_t *wbf) { - int8_t ret = _Z_RES_OK; +static z_result_t _z_raweth_link_send_wbuf(const _z_link_t *zl, const _z_wbuf_t *wbf) { + z_result_t ret = _Z_RES_OK; for (size_t i = 0; (i < _z_wbuf_len_iosli(wbf)) && (ret == _Z_RES_OK); i++) { _z_slice_t bs = _z_iosli_to_bytes(_z_wbuf_get_iosli(wbf, i)); size_t n = bs.len; @@ -168,8 +168,8 @@ static int8_t _z_raweth_link_send_wbuf(const _z_link_t *zl, const _z_wbuf_t *wbf return ret; } -int8_t _z_raweth_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_raweth_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg) { + z_result_t ret = _Z_RES_OK; // Create and prepare the buffer to serialize the message on uint16_t mtu = (zl->_mtu < Z_BATCH_UNICAST_SIZE) ? zl->_mtu : Z_BATCH_UNICAST_SIZE; @@ -192,8 +192,8 @@ int8_t _z_raweth_link_send_t_msg(const _z_link_t *zl, const _z_transport_message return ret; } -int8_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG(">> send session message"); #if Z_FEATURE_MULTI_THREAD == 1 @@ -221,9 +221,9 @@ int8_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_me return ret; } -int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl) { + z_result_t ret = _Z_RES_OK; _z_transport_multicast_t *ztm = &zn->_tp._transport._raweth; _Z_DEBUG(">> send network message"); @@ -232,7 +232,7 @@ int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) { _z_mutex_lock(&ztm->_mutex_tx); } else { - if (_z_mutex_try_lock(&ztm->_mutex_tx) != (int8_t)0) { + if (_z_mutex_try_lock(&ztm->_mutex_tx) != 0) { _Z_INFO("Dropping zenoh message because of congestion control"); // We failed to acquire the lock, drop the message return ret; @@ -321,19 +321,19 @@ int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, } #else -int8_t _z_raweth_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg) { +z_result_t _z_raweth_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_msg) { _ZP_UNUSED(zl); _ZP_UNUSED(t_msg); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg) { +z_result_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_message_t *t_msg) { _ZP_UNUSED(ztm); _ZP_UNUSED(t_msg); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl) { +z_result_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl) { _ZP_UNUSED(zn); _ZP_UNUSED(n_msg); _ZP_UNUSED(reliability); diff --git a/src/transport/transport.c b/src/transport/transport.c index d81574201..57aca8c7f 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/transport.h" +#include "zenoh-pico/transport/multicast/transport.h" #include #include @@ -22,18 +22,18 @@ #include "zenoh-pico/link/link.h" #include "zenoh-pico/protocol/core.h" #include "zenoh-pico/transport/multicast/rx.h" -#include "zenoh-pico/transport/multicast/transport.h" #include "zenoh-pico/transport/multicast/tx.h" #include "zenoh-pico/transport/raweth/rx.h" #include "zenoh-pico/transport/raweth/tx.h" +#include "zenoh-pico/transport/transport.h" #include "zenoh-pico/transport/unicast/rx.h" #include "zenoh-pico/transport/unicast/transport.h" #include "zenoh-pico/transport/unicast/tx.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" -int8_t _z_send_close(_z_transport_t *zt, uint8_t reason, bool link_only) { - int8_t ret = _Z_RES_OK; +z_result_t _z_send_close(_z_transport_t *zt, uint8_t reason, bool link_only) { + z_result_t ret = _Z_RES_OK; // Call transport function switch (zt->_type) { case _Z_TRANSPORT_UNICAST_TYPE: @@ -50,7 +50,7 @@ int8_t _z_send_close(_z_transport_t *zt, uint8_t reason, bool link_only) { return ret; } -int8_t _z_transport_close(_z_transport_t *zt, uint8_t reason) { return _z_send_close(zt, reason, false); } +z_result_t _z_transport_close(_z_transport_t *zt, uint8_t reason) { return _z_send_close(zt, reason, false); } void _z_transport_clear(_z_transport_t *zt) { switch (zt->_type) { diff --git a/src/transport/unicast/lease.c b/src/transport/unicast/lease.c index 3555d251c..32358eaba 100644 --- a/src/transport/unicast/lease.c +++ b/src/transport/unicast/lease.c @@ -20,8 +20,8 @@ #if Z_FEATURE_UNICAST_TRANSPORT == 1 -int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { - int8_t ret = _Z_RES_OK; +z_result_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { + z_result_t ret = _Z_RES_OK; _z_transport_message_t t_msg = _z_t_msg_make_keep_alive(); ret = _z_unicast_send_t_msg(ztu, &t_msg); @@ -30,7 +30,7 @@ int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { } #else -int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { +z_result_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu) { _ZP_UNUSED(ztu); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -95,7 +95,7 @@ void *_zp_unicast_lease_task(void *ztu_arg) { return 0; } -int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { +z_result_t _zp_unicast_start_lease_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); zt->_transport._unicast._lease_task_running = true; // Init before z_task_init for concurrency issue @@ -108,7 +108,7 @@ int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, z_task_attr_t *attr, _z_ return _Z_RES_OK; } -int8_t _zp_unicast_stop_lease_task(_z_transport_t *zt) { +z_result_t _zp_unicast_stop_lease_task(_z_transport_t *zt) { zt->_transport._unicast._lease_task_running = false; return _Z_RES_OK; } @@ -119,14 +119,14 @@ void *_zp_unicast_lease_task(void *ztu_arg) { return NULL; } -int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, void *attr, void *task) { +z_result_t _zp_unicast_start_lease_task(_z_transport_t *zt, void *attr, void *task) { _ZP_UNUSED(zt); _ZP_UNUSED(attr); _ZP_UNUSED(task); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _zp_unicast_stop_lease_task(_z_transport_t *zt) { +z_result_t _zp_unicast_stop_lease_task(_z_transport_t *zt) { _ZP_UNUSED(zt); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } diff --git a/src/transport/unicast/read.c b/src/transport/unicast/read.c index 77d782595..a43f1404c 100644 --- a/src/transport/unicast/read.c +++ b/src/transport/unicast/read.c @@ -24,8 +24,8 @@ #if Z_FEATURE_UNICAST_TRANSPORT == 1 -int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) { - int8_t ret = _Z_RES_OK; +z_result_t _zp_unicast_read(_z_transport_unicast_t *ztu) { + z_result_t ret = _Z_RES_OK; _z_transport_message_t t_msg; ret = _z_unicast_recv_t_msg(ztu, &t_msg); @@ -38,7 +38,7 @@ int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) { } #else -int8_t _zp_unicast_read(_z_transport_unicast_t *ztu) { +z_result_t _zp_unicast_read(_z_transport_unicast_t *ztu) { _ZP_UNUSED(ztu); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } @@ -97,7 +97,7 @@ void *_zp_unicast_read_task(void *ztu_arg) { // Decode one session message _z_transport_message_t t_msg; - int8_t ret = _z_transport_message_decode(&t_msg, &zbuf); + z_result_t ret = _z_transport_message_decode(&t_msg, &zbuf); if (ret == _Z_RES_OK) { ret = _z_unicast_handle_transport_message(ztu, &t_msg); @@ -120,7 +120,7 @@ void *_zp_unicast_read_task(void *ztu_arg) { return NULL; } -int8_t _zp_unicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { +z_result_t _zp_unicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); zt->_transport._unicast._read_task_running = true; // Init before z_task_init for concurrency issue @@ -134,7 +134,7 @@ int8_t _zp_unicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_t return _Z_RES_OK; } -int8_t _zp_unicast_stop_read_task(_z_transport_t *zt) { +z_result_t _zp_unicast_stop_read_task(_z_transport_t *zt) { zt->_transport._unicast._read_task_running = false; return _Z_RES_OK; } @@ -146,14 +146,14 @@ void *_zp_unicast_read_task(void *ztu_arg) { return NULL; } -int8_t _zp_unicast_start_read_task(_z_transport_t *zt, void *attr, void *task) { +z_result_t _zp_unicast_start_read_task(_z_transport_t *zt, void *attr, void *task) { _ZP_UNUSED(zt); _ZP_UNUSED(attr); _ZP_UNUSED(task); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _zp_unicast_stop_read_task(_z_transport_t *zt) { +z_result_t _zp_unicast_stop_read_task(_z_transport_t *zt) { _ZP_UNUSED(zt); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } diff --git a/src/transport/unicast/rx.c b/src/transport/unicast/rx.c index be2884af9..23c6859b9 100644 --- a/src/transport/unicast/rx.c +++ b/src/transport/unicast/rx.c @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/transport/unicast/rx.h" +#include "zenoh-pico/transport/common/rx.h" #include @@ -22,15 +22,15 @@ #include "zenoh-pico/protocol/core.h" #include "zenoh-pico/protocol/iobuf.h" #include "zenoh-pico/session/utils.h" -#include "zenoh-pico/transport/common/rx.h" +#include "zenoh-pico/transport/unicast/rx.h" #include "zenoh-pico/transport/utils.h" #include "zenoh-pico/utils/logging.h" #if Z_FEATURE_UNICAST_TRANSPORT == 1 -int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { +z_result_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { _Z_DEBUG(">> recv session msg"); - int8_t ret = _Z_RES_OK; + z_result_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock _z_mutex_lock(&ztu->_mutex_rx); @@ -92,12 +92,12 @@ int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_messag return ret; } -int8_t _z_unicast_recv_t_msg(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { +z_result_t _z_unicast_recv_t_msg(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { return _z_unicast_recv_t_msg_na(ztu, t_msg); } -int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { + z_result_t ret = _Z_RES_OK; switch (_Z_MID(t_msg->_header)) { case _Z_MID_T_FRAME: { @@ -216,13 +216,13 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans return ret; } #else -int8_t _z_unicast_recv_t_msg(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { +z_result_t _z_unicast_recv_t_msg(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { _ZP_UNUSED(ztu); _ZP_UNUSED(t_msg); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { +z_result_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { _ZP_UNUSED(ztu); _ZP_UNUSED(t_msg); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; diff --git a/src/transport/unicast/transport.c b/src/transport/unicast/transport.c index c43c2c85a..c4433ac1a 100644 --- a/src/transport/unicast/transport.c +++ b/src/transport/unicast/transport.c @@ -31,8 +31,9 @@ #if Z_FEATURE_UNICAST_TRANSPORT == 1 -int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transport_unicast_establish_param_t *param) { - int8_t ret = _Z_RES_OK; +z_result_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, + _z_transport_unicast_establish_param_t *param) { + z_result_t ret = _Z_RES_OK; zt->_type = _Z_TRANSPORT_UNICAST_TYPE; @@ -157,9 +158,9 @@ int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transpo return ret; } -int8_t _z_unicast_open_client(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid) { - int8_t ret = _Z_RES_OK; +z_result_t _z_unicast_open_client(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid) { + z_result_t ret = _Z_RES_OK; _z_id_t zid = *local_zid; _z_transport_message_t ism = _z_t_msg_make_init_syn(Z_WHATAMI_CLIENT, zid); @@ -251,18 +252,18 @@ int8_t _z_unicast_open_client(_z_transport_unicast_establish_param_t *param, con return ret; } -int8_t _z_unicast_open_peer(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid) { +z_result_t _z_unicast_open_peer(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid) { _ZP_UNUSED(param); _ZP_UNUSED(zl); _ZP_UNUSED(local_zid); - int8_t ret = _Z_ERR_CONFIG_UNSUPPORTED_PEER_UNICAST; + z_result_t ret = _Z_ERR_CONFIG_UNSUPPORTED_PEER_UNICAST; // @TODO: not implemented return ret; } -int8_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, bool link_only) { - int8_t ret = _Z_RES_OK; +z_result_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, bool link_only) { + z_result_t ret = _Z_RES_OK; // Send and clear message _z_transport_message_t cm = _z_t_msg_make_close(reason, link_only); ret = _z_unicast_send_t_msg(ztu, &cm); @@ -270,7 +271,7 @@ int8_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, bool l return ret; } -int8_t _z_unicast_transport_close(_z_transport_unicast_t *ztu, uint8_t reason) { +z_result_t _z_unicast_transport_close(_z_transport_unicast_t *ztu, uint8_t reason) { return _z_unicast_send_close(ztu, reason, false); } @@ -307,37 +308,38 @@ void _z_unicast_transport_clear(_z_transport_t *zt) { #else -int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transport_unicast_establish_param_t *param) { +z_result_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, + _z_transport_unicast_establish_param_t *param) { _ZP_UNUSED(zt); _ZP_UNUSED(zl); _ZP_UNUSED(param); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_unicast_open_client(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid) { +z_result_t _z_unicast_open_client(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid) { _ZP_UNUSED(param); _ZP_UNUSED(zl); _ZP_UNUSED(local_zid); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_unicast_open_peer(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, - const _z_id_t *local_zid) { +z_result_t _z_unicast_open_peer(_z_transport_unicast_establish_param_t *param, const _z_link_t *zl, + const _z_id_t *local_zid) { _ZP_UNUSED(param); _ZP_UNUSED(zl); _ZP_UNUSED(local_zid); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, bool link_only) { +z_result_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, bool link_only) { _ZP_UNUSED(ztu); _ZP_UNUSED(reason); _ZP_UNUSED(link_only); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_unicast_transport_close(_z_transport_unicast_t *ztu, uint8_t reason) { +z_result_t _z_unicast_transport_close(_z_transport_unicast_t *ztu, uint8_t reason) { _ZP_UNUSED(ztu); _ZP_UNUSED(reason); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; diff --git a/src/transport/unicast/tx.c b/src/transport/unicast/tx.c index 4fc097770..a2d946b30 100644 --- a/src/transport/unicast/tx.c +++ b/src/transport/unicast/tx.c @@ -43,8 +43,8 @@ _z_zint_t __unsafe_z_unicast_get_sn(_z_transport_unicast_t *ztu, z_reliability_t return sn; } -int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_message_t *t_msg) { - int8_t ret = _Z_RES_OK; +z_result_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_message_t *t_msg) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG(">> send session message"); #if Z_FEATURE_MULTI_THREAD == 1 @@ -74,9 +74,9 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes return ret; } -int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl) { - int8_t ret = _Z_RES_OK; +z_result_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl) { + z_result_t ret = _Z_RES_OK; _Z_DEBUG(">> send network message"); _z_transport_unicast_t *ztu = &zn->_tp._transport._unicast; @@ -89,8 +89,8 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg #endif // Z_FEATURE_MULTI_THREAD == 1 } else { #if Z_FEATURE_MULTI_THREAD == 1 - int8_t locked = _z_mutex_try_lock(&ztu->_mutex_tx); - if (locked != (int8_t)0) { + z_result_t locked = _z_mutex_try_lock(&ztu->_mutex_tx); + if (locked != 0) { _Z_INFO("Dropping zenoh message because of congestion control"); // We failed to acquire the lock, drop the message drop = true; @@ -170,14 +170,14 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg return ret; } #else -int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_message_t *t_msg) { +z_result_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_message_t *t_msg) { _ZP_UNUSED(ztu); _ZP_UNUSED(t_msg); return _Z_ERR_TRANSPORT_NOT_AVAILABLE; } -int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, - z_congestion_control_t cong_ctrl) { +z_result_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, z_reliability_t reliability, + z_congestion_control_t cong_ctrl) { _ZP_UNUSED(zn); _ZP_UNUSED(n_msg); _ZP_UNUSED(reliability); diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 17b5101d2..9b95d33d0 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -16,6 +16,8 @@ #include #include +#include "zenoh-pico/utils/result.h" + #undef NDEBUG #include @@ -151,11 +153,11 @@ int main(int argc, char **argv) { char *keyexpr_str = (char *)z_malloc(keyexpr_len + 1); memcpy(keyexpr_str, URI, keyexpr_len); keyexpr_str[keyexpr_len] = '\0'; - int8_t _ret_int8 = z_keyexpr_is_canon(keyexpr_str, keyexpr_len); - assert(_ret_int8 < 0); + z_result_t _ret_res = z_keyexpr_is_canon(keyexpr_str, keyexpr_len); + assert(_ret_res < 0); - _ret_int8 = z_keyexpr_canonize(keyexpr_str, &keyexpr_len); - assert_eq(_ret_int8, 0); + _ret_res = z_keyexpr_canonize(keyexpr_str, &keyexpr_len); + assert_eq(_ret_res, 0); assert_eq(strlen(URI), keyexpr_len); printf("Ok\n"); @@ -169,8 +171,8 @@ int main(int argc, char **argv) { z_config_default(&_ret_config); assert(z_internal_check(_ret_config)); #ifdef ZENOH_PICO - _ret_int8 = zp_config_insert(z_loan_mut(_ret_config), Z_CONFIG_CONNECT_KEY, argv[1]); - assert_eq(_ret_int8, 0); + _ret_res = zp_config_insert(z_loan_mut(_ret_config), Z_CONFIG_CONNECT_KEY, argv[1]); + assert_eq(_ret_res, 0); const char *_ret_cstr = zp_config_get(z_loan(_ret_config), Z_CONFIG_CONNECT_KEY); assert_eq(strlen(_ret_cstr), strlen(argv[1])); assert_eq(strncmp(_ret_cstr, argv[1], strlen(_ret_cstr)), 0); @@ -186,8 +188,8 @@ int main(int argc, char **argv) { printf("Testing Scouting..."); z_owned_closure_hello_t _ret_closure_hello; z_closure(&_ret_closure_hello, hello_handler, NULL, NULL); - _ret_int8 = z_scout(z_move(_ret_sconfig), z_move(_ret_closure_hello), NULL); - assert_eq(_ret_int8, 0); + _ret_res = z_scout(z_move(_ret_sconfig), z_move(_ret_closure_hello), NULL); + assert_eq(_ret_res, 0); assert(hellos >= 1); uint32_t _scouting_timeout = (uint32_t)strtoul(SCOUTING_TIMEOUT, NULL, 10); @@ -207,14 +209,14 @@ int main(int argc, char **argv) { z_owned_closure_zid_t _ret_closure_zid; z_closure(&_ret_closure_zid, zid_handler, NULL, NULL); - _ret_int8 = z_info_peers_zid(z_loan(s1), z_move(_ret_closure_zid)); - assert_eq(_ret_int8, 0); + _ret_res = z_info_peers_zid(z_loan(s1), z_move(_ret_closure_zid)); + assert_eq(_ret_res, 0); z_sleep_s(SLEEP); assert_eq(zids, 0); z_closure(&_ret_closure_zid, zid_handler, NULL, NULL); - _ret_int8 = z_info_routers_zid(z_loan(s1), z_move(_ret_closure_zid)); - assert_eq(_ret_int8, 0); + _ret_res = z_info_routers_zid(z_loan(s1), z_move(_ret_closure_zid)); + assert_eq(_ret_res, 0); z_sleep_s(SLEEP); assert_eq(zids, 1); @@ -232,8 +234,8 @@ int main(int argc, char **argv) { z_config_default(&_ret_config); #ifdef ZENOH_PICO - _ret_int8 = zp_config_insert(z_loan_mut(_ret_config), Z_CONFIG_CONNECT_KEY, argv[1]); - assert_eq(_ret_int8, 0); + _ret_res = zp_config_insert(z_loan_mut(_ret_config), Z_CONFIG_CONNECT_KEY, argv[1]); + assert_eq(_ret_res, 0); _ret_cstr = zp_config_get(z_loan(_ret_config), Z_CONFIG_CONNECT_KEY); assert_eq(strlen(_ret_cstr), strlen(argv[1])); assert_eq(strncmp(_ret_cstr, argv[1], strlen(_ret_cstr)), 0); @@ -266,8 +268,8 @@ int main(int argc, char **argv) { z_view_keyexpr_t ke; z_view_keyexpr_from_str(&ke, keyexpr_str); z_owned_subscriber_t _ret_sub; - _ret_int8 = z_declare_subscriber(&_ret_sub, z_loan(s2), z_loan(ke), z_move(_ret_closure_sample), &_ret_sub_opt); - assert(_ret_int8 == _Z_RES_OK); + _ret_res = z_declare_subscriber(&_ret_sub, z_loan(s2), z_loan(ke), z_move(_ret_closure_sample), &_ret_sub_opt); + assert(_ret_res == _Z_RES_OK); printf("Ok\n"); z_sleep_s(SLEEP); @@ -293,8 +295,8 @@ int main(int argc, char **argv) { z_owned_bytes_t payload; z_bytes_from_str(&payload, (char *)value, NULL, NULL); - _ret_int8 = z_put(z_loan(s1), z_loan(_ret_expr), z_move(payload), &_ret_put_opt); - assert_eq(_ret_int8, 0); + _ret_res = z_put(z_loan(s1), z_loan(_ret_expr), z_move(payload), &_ret_put_opt); + assert_eq(_ret_res, 0); assert(!z_internal_check(encoding)); printf("Ok\n"); @@ -305,17 +307,17 @@ int main(int argc, char **argv) { z_delete_options_t _ret_delete_opt; z_delete_options_default(&_ret_delete_opt); _ret_delete_opt.congestion_control = Z_CONGESTION_CONTROL_BLOCK; - _ret_int8 = z_delete(z_loan(s1), z_loan(_ret_expr), &_ret_delete_opt); - assert_eq(_ret_int8, 0); + _ret_res = z_delete(z_loan(s1), z_loan(_ret_expr), &_ret_delete_opt); + assert_eq(_ret_res, 0); printf("Ok\n"); z_sleep_s(SLEEP); assert_eq(datas, 2); printf("Undeclaring Keyexpr..."); - _ret_int8 = z_undeclare_keyexpr(z_move(_ret_expr), z_loan(s1)); - printf(" %02x\n", _ret_int8); - assert_eq(_ret_int8, 0); + _ret_res = z_undeclare_keyexpr(z_move(_ret_expr), z_loan(s1)); + printf(" %02x\n", _ret_res); + assert_eq(_ret_res, 0); assert(!z_internal_check(_ret_expr)); printf("Ok\n"); @@ -326,8 +328,8 @@ int main(int argc, char **argv) { _ret_pub_opt.encoding = z_move(encoding); _ret_pub_opt.congestion_control = Z_CONGESTION_CONTROL_BLOCK; z_owned_publisher_t _ret_pub; - _ret_int8 = z_declare_publisher(&_ret_pub, z_loan(s1), z_loan(s1_key), &_ret_pub_opt); - assert(_ret_int8 == _Z_RES_OK); + _ret_res = z_declare_publisher(&_ret_pub, z_loan(s1), z_loan(s1_key), &_ret_pub_opt); + assert(_ret_res == _Z_RES_OK); assert(!z_internal_check(encoding)); printf("Ok\n"); @@ -339,8 +341,8 @@ int main(int argc, char **argv) { z_publisher_put_options_t _ret_pput_opt; z_publisher_put_options_default(&_ret_pput_opt); - _ret_int8 = z_publisher_put(z_loan(_ret_pub), z_move(payload), &_ret_pput_opt); - assert_eq(_ret_int8, 0); + _ret_res = z_publisher_put(z_loan(_ret_pub), z_move(payload), &_ret_pput_opt); + assert_eq(_ret_res, 0); printf("Ok\n"); z_sleep_s(SLEEP); @@ -349,24 +351,24 @@ int main(int argc, char **argv) { printf("Publisher Delete..."); z_publisher_delete_options_t _ret_pdelete_opt; z_publisher_delete_options_default(&_ret_pdelete_opt); - _ret_int8 = z_publisher_delete(z_loan(_ret_pub), &_ret_pdelete_opt); - assert_eq(_ret_int8, 0); + _ret_res = z_publisher_delete(z_loan(_ret_pub), &_ret_pdelete_opt); + assert_eq(_ret_res, 0); printf("Ok\n"); z_sleep_s(SLEEP); assert_eq(datas, 4); printf("Undeclaring Publisher..."); - _ret_int8 = z_undeclare_publisher(z_move(_ret_pub)); - assert_eq(_ret_int8, 0); + _ret_res = z_undeclare_publisher(z_move(_ret_pub)); + assert_eq(_ret_res, 0); assert(!z_internal_check(_ret_pub)); printf("Ok\n"); z_sleep_s(SLEEP); printf("Undeclaring Subscriber..."); - _ret_int8 = z_undeclare_subscriber(z_move(_ret_sub)); - assert_eq(_ret_int8, 0); + _ret_res = z_undeclare_subscriber(z_move(_ret_sub)); + assert_eq(_ret_res, 0); assert(!z_internal_check(_ret_sub)); printf("Ok\n"); @@ -404,8 +406,8 @@ int main(int argc, char **argv) { printf("Ok\n"); printf("Testing Get..."); - _ret_int8 = z_get(z_loan(s2), z_loan(s1_key), "", z_move(_ret_closure_reply), &_ret_get_opt); - assert_eq(_ret_int8, 0); + _ret_res = z_get(z_loan(s2), z_loan(s1_key), "", z_move(_ret_closure_reply), &_ret_get_opt); + assert_eq(_ret_res, 0); printf("Ok\n"); z_sleep_s(SLEEP); @@ -413,8 +415,8 @@ int main(int argc, char **argv) { assert_eq(replies, 1); printf("Undeclaring Queryable..."); - _ret_int8 = z_undeclare_queryable(z_move(qle)); - assert_eq(_ret_int8, 0); + _ret_res = z_undeclare_queryable(z_move(qle)); + assert_eq(_ret_res, 0); printf("Ok\n"); #ifdef ZENOH_PICO @@ -423,15 +425,15 @@ int main(int argc, char **argv) { #endif printf("Close sessions..."); - _ret_int8 = z_close(z_move(s1), NULL); - assert_eq(_ret_int8, 0); + _ret_res = z_close(z_move(s1), NULL); + assert_eq(_ret_res, 0); #ifdef ZENOH_PICO zp_stop_read_task(z_loan_mut(s2)); zp_stop_lease_task(z_loan_mut(s2)); #endif - _ret_int8 = z_close(z_move(s2), NULL); - assert_eq(_ret_int8, 0); + _ret_res = z_close(z_move(s2), NULL); + assert_eq(_ret_res, 0); printf("Ok\n"); z_sleep_s(SLEEP * 5); diff --git a/tests/z_channels_test.c b/tests/z_channels_test.c index 76574ff8d..6af2e7a96 100644 --- a/tests/z_channels_test.c +++ b/tests/z_channels_test.c @@ -42,7 +42,7 @@ #define _RECV(handler, method, buf) \ do { \ z_owned_sample_t sample; \ - int8_t res = method(z_loan(handler), &sample); \ + z_result_t res = method(z_loan(handler), &sample); \ if (res == Z_CHANNEL_DISCONNECTED) { \ strcpy(buf, "closed"); \ } else if (res == Z_OK) { \ diff --git a/tests/z_client_test.c b/tests/z_client_test.c index fa75dda86..12a399053 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -196,7 +196,7 @@ int main(int argc, char **argv) { z_owned_closure_sample_t callback; z_closure(&callback, data_handler, NULL, &idx[i]); z_owned_subscriber_t *sub = (z_owned_subscriber_t *)z_malloc(sizeof(z_owned_subscriber_t)); - int8_t res = z_declare_subscriber(sub, z_loan(s2), z_loan(rids2[i]), z_move(callback), NULL); + z_result_t res = z_declare_subscriber(sub, z_loan(s2), z_loan(rids2[i]), z_move(callback), NULL); assert(res == _Z_RES_OK); printf("Declared subscription on session 2: %ju %u %s\n", (uintmax_t)z_subscriber_loan(sub)->_entity_id, z_loan(rids2[i])->_id, ""); diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index 1a7cefcc4..81f16f50c 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -363,7 +363,7 @@ void zint(void) { _z_zint_t e_z = gen_zint(); // Encode - int8_t res = _z_zsize_encode(&wbf, e_z); + z_result_t res = _z_zsize_encode(&wbf, e_z); assert(res == _Z_RES_OK); (void)(res); @@ -401,7 +401,7 @@ void unit_extension(void) { _z_msg_ext_unit_t e_u = ext._body._unit; // Encode - int8_t res = _z_msg_ext_encode_unit(&wbf, &e_u); + z_result_t res = _z_msg_ext_encode_unit(&wbf, &e_u); assert(res == _Z_RES_OK); (void)(res); @@ -442,7 +442,7 @@ void zint_extension(void) { _z_msg_ext_zint_t e_u = ext._body._zint; // Encode - int8_t res = _z_msg_ext_encode_zint(&wbf, &e_u); + z_result_t res = _z_msg_ext_encode_zint(&wbf, &e_u); assert(res == _Z_RES_OK); (void)(res); @@ -484,7 +484,7 @@ void zbuf_extension(void) { _z_msg_ext_zbuf_t e_u = ext._body._zbuf; // Encode - int8_t res = _z_msg_ext_encode_zbuf(&wbf, &e_u); + z_result_t res = _z_msg_ext_encode_zbuf(&wbf, &e_u); assert(res == _Z_RES_OK); (void)(res); @@ -547,7 +547,7 @@ void payload_field(void) { _z_bytes_t e_pld = gen_payload(64); // Encode - int8_t res = _z_bytes_encode(&wbf, &e_pld); + z_result_t res = _z_bytes_encode(&wbf, &e_pld); assert(res == _Z_RES_OK); (void)(res); @@ -618,7 +618,7 @@ void timestamp_field(void) { _z_timestamp_t e_ts = gen_timestamp(); // Encode - int8_t res = _z_timestamp_encode(&wbf, &e_ts); + z_result_t res = _z_timestamp_encode(&wbf, &e_ts); assert(res == _Z_RES_OK); (void)(res); @@ -686,7 +686,7 @@ void keyexpr_field(void) { // Encode uint8_t header = (_z_keyexpr_has_suffix(&e_rk)) ? _Z_FLAG_Z_K : 0; - int8_t res = _z_keyexpr_encode(&wbf, _Z_HAS_FLAG(header, _Z_FLAG_Z_K), &e_rk); + z_result_t res = _z_keyexpr_encode(&wbf, _Z_HAS_FLAG(header, _Z_FLAG_Z_K), &e_rk); assert(res == _Z_RES_OK); (void)(res); @@ -729,7 +729,7 @@ void resource_declaration(void) { _z_decl_kexpr_t e_rd = gen_resource_declaration(); // Encode - int8_t res = _z_decl_kexpr_encode(&wbf, &e_rd); + z_result_t res = _z_decl_kexpr_encode(&wbf, &e_rd); assert(res == _Z_RES_OK); (void)(res); @@ -770,7 +770,7 @@ void subscriber_declaration(void) { // Initialize _z_decl_subscriber_t e_sd = gen_subscriber_declaration(); // Encode - int8_t res = _z_decl_subscriber_encode(&wbf, &e_sd); + z_result_t res = _z_decl_subscriber_encode(&wbf, &e_sd); assert(res == _Z_RES_OK); (void)(res); @@ -819,7 +819,7 @@ void queryable_declaration(void) { _z_decl_queryable_t e_qd = gen_queryable_declaration(); // Encode - int8_t res = _z_decl_queryable_encode(&wbf, &e_qd); + z_result_t res = _z_decl_queryable_encode(&wbf, &e_qd); assert(res == _Z_RES_OK); (void)(res); @@ -864,7 +864,7 @@ void forget_resource_declaration(void) { _z_undecl_kexpr_t e_frd = gen_forget_resource_declaration(); // Encode - int8_t res = _z_undecl_kexpr_encode(&wbf, &e_frd); + z_result_t res = _z_undecl_kexpr_encode(&wbf, &e_frd); assert(res == _Z_RES_OK); (void)(res); @@ -905,7 +905,7 @@ void forget_subscriber_declaration(void) { _z_undecl_subscriber_t e_fsd = gen_forget_subscriber_declaration(); // Encode - int8_t res = _z_undecl_subscriber_encode(&wbf, &e_fsd); + z_result_t res = _z_undecl_subscriber_encode(&wbf, &e_fsd); assert(res == _Z_RES_OK); (void)(res); @@ -946,7 +946,7 @@ void forget_queryable_declaration(void) { _z_undecl_queryable_t e_fqd = gen_forget_queryable_declaration(); // Encode - int8_t res = _z_undecl_queryable_encode(&wbf, &e_fqd); + z_result_t res = _z_undecl_queryable_encode(&wbf, &e_fqd); assert(res == _Z_RES_OK); (void)(res); @@ -1060,7 +1060,7 @@ void declare_message(void) { _z_network_message_t n_msg = gen_declare_message(); // Encode - int8_t res = _z_network_message_encode(&wbf, &n_msg); + z_result_t res = _z_network_message_encode(&wbf, &n_msg); assert(res == _Z_RES_OK); (void)(res); @@ -1194,7 +1194,7 @@ void push_body_message(void) { _z_push_body_t e_da = gen_push_body(); // Encode - int8_t res = _z_push_body_encode(&wbf, &e_da); + z_result_t res = _z_push_body_encode(&wbf, &e_da); assert(res == _Z_RES_OK); (void)(res); @@ -1238,7 +1238,7 @@ void query_message(void) { _z_msg_query_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); uint8_t header = _z_zbuf_read(&zbf); - int8_t res = _z_query_decode(&decoded, &zbf, header); + z_result_t res = _z_query_decode(&decoded, &zbf, header); assert(_Z_RES_OK == res); assert_eq_query(&expected, &decoded); _z_msg_query_clear(&decoded); @@ -1400,7 +1400,7 @@ void request_message(void) { _z_n_msg_request_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); uint8_t header = _z_zbuf_read(&zbf); - int8_t ret = _z_request_decode(&decoded, &zbf, header); + z_result_t ret = _z_request_decode(&decoded, &zbf, header); assert(_Z_RES_OK == ret); assert_eq_request(&expected, &decoded); _z_n_msg_request_clear(&decoded); @@ -1458,7 +1458,7 @@ void response_message(void) { _z_n_msg_response_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); uint8_t header = _z_zbuf_read(&zbf); - int8_t ret = _z_response_decode(&decoded, &zbf, header); + z_result_t ret = _z_response_decode(&decoded, &zbf, header); assert(_Z_RES_OK == ret); assert_eq_response(&expected, &decoded); _z_n_msg_response_clear(&decoded); @@ -1479,7 +1479,7 @@ void response_final_message(void) { _z_n_msg_response_final_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); uint8_t header = _z_zbuf_read(&zbf); - int8_t ret = _z_response_final_decode(&decoded, &zbf, header); + z_result_t ret = _z_response_final_decode(&decoded, &zbf, header); assert(_Z_RES_OK == ret); assert_eq_response_final(&expected, &decoded); _z_n_msg_response_final_clear(&decoded); @@ -1527,7 +1527,7 @@ void join_message(void) { assert(_z_join_encode(&wbf, expected._header, &expected._body._join) == _Z_RES_OK); _z_t_msg_join_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); - int8_t ret = _z_join_decode(&decoded, &zbf, expected._header); + z_result_t ret = _z_join_decode(&decoded, &zbf, expected._header); assert(_Z_RES_OK == ret); assert_eq_join(&expected._body._join, &decoded); _z_t_msg_join_clear(&decoded); @@ -1559,7 +1559,7 @@ void init_message(void) { assert(_z_init_encode(&wbf, expected._header, &expected._body._init) == _Z_RES_OK); _z_t_msg_init_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); - int8_t ret = _z_init_decode(&decoded, &zbf, expected._header); + z_result_t ret = _z_init_decode(&decoded, &zbf, expected._header); assert(_Z_RES_OK == ret); assert_eq_init(&expected._body._init, &decoded); _z_t_msg_init_clear(&decoded); @@ -1587,7 +1587,7 @@ void open_message(void) { assert(_z_open_encode(&wbf, expected._header, &expected._body._open) == _Z_RES_OK); _z_t_msg_open_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); - int8_t ret = _z_open_decode(&decoded, &zbf, expected._header); + z_result_t ret = _z_open_decode(&decoded, &zbf, expected._header); assert(_Z_RES_OK == ret); assert_eq_open(&expected._body._open, &decoded); _z_t_msg_open_clear(&decoded); @@ -1607,7 +1607,7 @@ void close_message(void) { assert(_z_close_encode(&wbf, expected._header, &expected._body._close) == _Z_RES_OK); _z_t_msg_close_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); - int8_t ret = _z_close_decode(&decoded, &zbf, expected._header); + z_result_t ret = _z_close_decode(&decoded, &zbf, expected._header); assert(_Z_RES_OK == ret); assert_eq_close(&expected._body._close, &decoded); _z_t_msg_close_clear(&decoded); @@ -1628,7 +1628,7 @@ void keep_alive_message(void) { assert(_z_keep_alive_encode(&wbf, expected._header, &expected._body._keep_alive) == _Z_RES_OK); _z_t_msg_keep_alive_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); - int8_t ret = _z_keep_alive_decode(&decoded, &zbf, expected._header); + z_result_t ret = _z_keep_alive_decode(&decoded, &zbf, expected._header); assert(_Z_RES_OK == ret); assert_eq_keep_alive(&expected._body._keep_alive, &decoded); _z_t_msg_keep_alive_clear(&decoded); @@ -1715,7 +1715,7 @@ void frame_message(void) { assert(_z_frame_encode(&wbf, expected._header, &expected._body._frame) == _Z_RES_OK); _z_t_msg_frame_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); - int8_t ret = _z_frame_decode(&decoded, &zbf, expected._header); + z_result_t ret = _z_frame_decode(&decoded, &zbf, expected._header); assert(_Z_RES_OK == ret); assert_eq_frame(&expected._body._frame, &decoded); _z_t_msg_frame_clear(&decoded); @@ -1738,7 +1738,7 @@ void fragment_message(void) { assert(_z_fragment_encode(&wbf, expected._header, &expected._body._fragment) == _Z_RES_OK); _z_t_msg_fragment_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); - int8_t ret = _z_fragment_decode(&decoded, &zbf, expected._header); + z_result_t ret = _z_fragment_decode(&decoded, &zbf, expected._header); assert(_Z_RES_OK == ret); assert_eq_fragment(&expected._body._fragment, &decoded); _z_t_msg_fragment_clear(&decoded); @@ -1808,7 +1808,7 @@ void transport_message(void) { assert(_z_transport_message_encode(&wbf, &expected) == _Z_RES_OK); _z_transport_message_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); - int8_t ret = _z_transport_message_decode(&decoded, &zbf); + z_result_t ret = _z_transport_message_decode(&decoded, &zbf); assert(_Z_RES_OK == ret); assert_eq_transport(&expected, &decoded); _z_t_msg_clear(&decoded); @@ -1850,7 +1850,7 @@ void scouting_message(void) { assert(_z_scouting_message_encode(&wbf, &expected) == _Z_RES_OK); _z_scouting_message_t decoded; _z_zbuf_t zbf = _z_wbuf_to_zbuf(&wbf); - int8_t ret = _z_scouting_message_decode(&decoded, &zbf); + z_result_t ret = _z_scouting_message_decode(&decoded, &zbf); assert(_Z_RES_OK == ret); assert_eq_scouting(&expected, &decoded); _z_s_msg_clear(&decoded); diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index 9548c5b9f..31fe89e50 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -117,7 +117,7 @@ int main(int argc, char **argv) { z_owned_subscriber_t *sub = (z_owned_subscriber_t *)z_malloc(sizeof(z_owned_subscriber_t)); z_view_keyexpr_t ke; z_view_keyexpr_from_str(&ke, s1_res); - int8_t res = z_declare_subscriber(sub, z_loan(s2), z_loan(ke), z_move(callback), NULL); + z_result_t res = z_declare_subscriber(sub, z_loan(s2), z_loan(ke), z_move(callback), NULL); assert(res == _Z_RES_OK); printf("Declared subscription on session 2: %ju %zu %s\n", (uintmax_t)z_subscriber_loan(sub)->_entity_id, (z_zint_t)0, s1_res); diff --git a/zenohpico.pc b/zenohpico.pc index d3ac867e5..5a3196e15 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -3,6 +3,6 @@ prefix=/usr/local Name: zenohpico Description: URL: -Version: 1.0.20240917dev +Version: 1.0.20240918dev Cflags: -I${prefix}/include Libs: -L${prefix}/lib -lzenohpico