Skip to content

Commit

Permalink
store value instead of ptr for z_owned_config, value, hello, encoding;
Browse files Browse the repository at this point in the history
remove z_scouting_config_t (since it corresponds exactly to z_config_t, and is also absent from zenoh-c)
  • Loading branch information
DenisBiryukov91 committed Jul 1, 2024
1 parent 71f4e2f commit 90c94ac
Show file tree
Hide file tree
Showing 27 changed files with 136 additions and 270 deletions.
12 changes: 0 additions & 12 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ TODO: owned type description
Represents a Zenoh configuration, used to configure Zenoh sessions upon opening.

.. c:type:: z_owned_scouting_config_t
Represents a scouting configuration, used to configure a scouting procedure.

.. c:type:: z_owned_session_t
Represents a Zenoh Session.
Expand Down Expand Up @@ -160,10 +156,6 @@ TODO: loaned type description
Represents a Zenoh configuration, used to configure Zenoh sessions upon opening.

.. c:type:: z_loaned_scouting_config_t
Represents a scouting configuration, used to configure a scouting procedure.

.. c:type:: z_loaned_session_t
Represents a Zenoh Session.
Expand Down Expand Up @@ -288,10 +280,6 @@ Primitives
.. autocfunction:: primitives.h::z_config_default
.. autocfunction:: primitives.h::zp_config_get
.. autocfunction:: primitives.h::zp_config_insert
.. autocfunction:: primitives.h::z_scouting_config_default
.. autocfunction:: primitives.h::z_scouting_config_from
.. autocfunction:: primitives.h::zp_scouting_config_get
.. autocfunction:: primitives.h::zp_scouting_config_insert
.. autocfunction:: primitives.h::z_encoding_check
.. autocfunction:: primitives.h::z_encoding_drop
.. autocfunction:: primitives.h::z_encoding_loan
Expand Down
6 changes: 3 additions & 3 deletions examples/arduino/z_scout.ino
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ void setup() {
void loop() {
int *context = (int *)malloc(sizeof(int));
*context = 0;
z_owned_scouting_config_t config;
z_scouting_config_default(&config);
z_owned_config_t config;
z_config_default(&config);
z_owned_closure_hello_t closure;
z_closure_hello(&closure, callback, drop, context);
printf("Scouting...\n");
z_scout(z_scouting_config_move(&config), z_closure_hello_move(&closure));
z_scout(z_config_move(&config), z_closure_hello_move(&closure));
}
6 changes: 3 additions & 3 deletions examples/espidf/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ void app_main() {

int *context = (int *)malloc(sizeof(int));
*context = 0;
z_owned_scouting_config_t config;
z_scouting_config_default(&config);
z_owned_config_t config;
z_config_default(&config);
z_owned_closure_hello_t closure;
z_closure_hello(&closure, callback, drop, context);
printf("Scouting...\n");
z_scout(z_scouting_config_move(&config), z_closure_hello_move(&closure));
z_scout(z_config_move(&config), z_closure_hello_move(&closure));
}
4 changes: 2 additions & 2 deletions examples/freertos_plus_tcp/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ void drop(void *context) {
void app_main(void) {
int *context = (int *)pvPortMalloc(sizeof(int));
*context = 0;
z_owned_scouting_config_t config;
z_scouting_config_default(&config);
z_owned_config_t config;
z_config_default(&config);
z_owned_closure_hello_t closure;
z_closure(&closure, callback, drop, context);
printf("Scouting...\n");
Expand Down
4 changes: 2 additions & 2 deletions examples/unix/c11/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ int main(int argc, char **argv) {

int *context = (int *)malloc(sizeof(int));
*context = 0;
z_owned_scouting_config_t config;
z_scouting_config_default(&config);
z_owned_config_t config;
z_config_default(&config);
z_owned_closure_hello_t closure;
z_closure(&closure, callback, drop, context);
printf("Scouting...\n");
Expand Down
1 change: 1 addition & 0 deletions examples/unix/c11/z_sub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void parse_attachment(kv_pairs_t *kvp, const z_loaned_bytes_t *attachment) {
z_bytes_deserialize_into_string(z_loan(second), &kvp->data[kvp->current_idx].value);
z_bytes_drop(&first);
z_bytes_drop(&second);
z_bytes_drop(&kv);
kvp->current_idx++;
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/unix/c99/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ int main(int argc, char **argv) {

int *context = (int *)malloc(sizeof(int));
*context = 0;
z_owned_scouting_config_t config;
z_scouting_config_default(&config);
z_owned_config_t config;
z_config_default(&config);
z_owned_closure_hello_t closure;
z_closure_hello(&closure, callback, drop, context);
printf("Scouting...\n");
z_scout(z_scouting_config_move(&config), z_closure_hello_move(&closure));
z_scout(z_config_move(&config), z_closure_hello_move(&closure));
sleep(1);
return 0;
}
4 changes: 2 additions & 2 deletions examples/windows/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ int main(int argc, char **argv) {

int *context = (int *)malloc(sizeof(int));
*context = 0;
z_owned_scouting_config_t config;
z_scouting_config_default(&config);
z_owned_config_t config;
z_config_default(&config);
z_owned_closure_hello_t closure;
z_closure(&closure, callback, drop, context);
printf("Scouting...\n");
Expand Down
6 changes: 3 additions & 3 deletions examples/zephyr/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ int main(void) {

int *context = (int *)malloc(sizeof(int));
*context = 0;
z_owned_scouting_config_t config;
z_scouting_config_default(&config);
z_owned_config_t config;
z_config_default(&config);
z_owned_closure_hello_t closure;
z_closure_hello(&closure, callback, drop, context);
printf("Scouting...\n");
z_scout(z_scouting_config_move(&config), z_closure_hello_move(&closure));
z_scout(z_config_move(&config), z_closure_hello_move(&closure));

return 0;
}
11 changes: 0 additions & 11 deletions include/zenoh-pico/api/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
z_owned_keyexpr_t : z_keyexpr_loan, \
z_view_keyexpr_t : z_view_keyexpr_loan, \
z_owned_config_t : z_config_loan, \
z_owned_scouting_config_t : z_scouting_config_loan, \
z_owned_session_t : z_session_loan, \
z_owned_subscriber_t : z_subscriber_loan, \
z_owned_publisher_t : z_publisher_loan, \
Expand All @@ -65,7 +64,6 @@
#define z_loan_mut(x) _Generic((x), \
z_owned_keyexpr_t : z_keyexpr_loan_mut, \
z_owned_config_t : z_config_loan_mut, \
z_owned_scouting_config_t : z_scouting_config_loan_mut, \
z_owned_session_t : z_session_loan_mut, \
z_owned_publisher_t : z_publisher_loan_mut, \
z_owned_queryable_t : z_queryable_loan_mut, \
Expand All @@ -89,7 +87,6 @@
#define z_drop(x) _Generic((x), \
z_owned_keyexpr_t * : z_keyexpr_drop, \
z_owned_config_t * : z_config_drop, \
z_owned_scouting_config_t * : z_scouting_config_drop, \
z_owned_session_t * : z_session_drop, \
z_owned_subscriber_t * : z_subscriber_drop, \
z_owned_publisher_t * : z_publisher_drop, \
Expand Down Expand Up @@ -133,7 +130,6 @@
z_view_keyexpr_t : z_keyexpr_is_initialized, \
z_owned_reply_err_t : z_reply_err_check, \
z_owned_config_t : z_config_check, \
z_owned_scouting_config_t : z_scouting_config_check, \
z_owned_session_t : z_session_check, \
z_owned_subscriber_t : z_subscriber_check, \
z_owned_publisher_t : z_publisher_check, \
Expand Down Expand Up @@ -198,7 +194,6 @@
#define z_move(x) _Generic((x), \
z_owned_keyexpr_t : z_keyexpr_move, \
z_owned_config_t : z_config_move, \
z_owned_scouting_config_t : z_scouting_config_move, \
z_owned_session_t : z_session_move, \
z_owned_subscriber_t : z_subscriber_move, \
z_owned_publisher_t : z_publisher_move, \
Expand Down Expand Up @@ -266,7 +261,6 @@
z_owned_publisher_t * : z_publisher_null, \
z_owned_keyexpr_t * : z_keyexpr_null, \
z_owned_config_t * : z_config_null, \
z_owned_scouting_config_t * : z_scouting_config_null, \
z_owned_subscriber_t * : z_subscriber_null, \
z_owned_queryable_t * : z_queryable_null, \
z_owned_query_t * : z_query_null, \
Expand Down Expand Up @@ -318,7 +312,6 @@
inline const z_loaned_keyexpr_t* z_loan(const z_owned_keyexpr_t& x) { return z_keyexpr_loan(&x); }
inline const z_loaned_keyexpr_t* z_loan(const z_view_keyexpr_t& x) { return z_view_keyexpr_loan(&x); }
inline const z_loaned_config_t* z_loan(const z_owned_config_t& x) { return z_config_loan(&x); }
inline const z_loaned_scouting_config_t* z_loan(const z_owned_scouting_config_t& x) { return z_scouting_config_loan(&x); }
inline const z_loaned_session_t* z_loan(const z_owned_session_t& x) { return z_session_loan(&x); }
inline const z_loaned_subscriber_t* z_loan(const z_owned_subscriber_t& x) { return z_subscriber_loan(&x); }
inline const z_loaned_publisher_t* z_loan(const z_owned_publisher_t& x) { return z_publisher_loan(&x); }
Expand All @@ -339,7 +332,6 @@ inline const z_loaned_reply_err_t* z_loan(const z_owned_reply_err_t& x) { return
inline z_loaned_keyexpr_t* z_loan_mut(z_owned_keyexpr_t& x) { return z_keyexpr_loan_mut(&x); }
inline z_loaned_keyexpr_t* z_loan_mut(z_view_keyexpr_t& x) { return z_view_keyexpr_loan_mut(&x); }
inline z_loaned_config_t* z_loan_mut(z_owned_config_t& x) { return z_config_loan_mut(&x); }
inline z_loaned_scouting_config_t* z_loan_mut(z_owned_scouting_config_t& x) { return z_scouting_config_loan_mut(&x); }
inline z_loaned_session_t* z_loan_mut(z_owned_session_t& x) { return z_session_loan_mut(&x); }
inline z_loaned_publisher_t* z_loan_mut(z_owned_publisher_t& x) { return z_publisher_loan_mut(&x); }
inline z_loaned_queryable_t* z_loan_mut(z_owned_queryable_t& x) { return z_queryable_loan_mut(&x); }
Expand All @@ -360,7 +352,6 @@ inline int8_t z_drop(z_owned_session_t* v) { return z_close(v); }
inline int8_t z_drop(z_owned_publisher_t* v) { return z_undeclare_publisher(v); }
inline void z_drop(z_owned_keyexpr_t* v) { z_keyexpr_drop(v); }
inline void z_drop(z_owned_config_t* v) { z_config_drop(v); }
inline void z_drop(z_owned_scouting_config_t* v) { z_scouting_config_drop(v); }
inline int8_t z_drop(z_owned_subscriber_t* v) { return z_undeclare_subscriber(v); }
inline int8_t z_drop(z_owned_queryable_t* v) { return z_undeclare_queryable(v); }
inline void z_drop(z_owned_reply_t* v) { z_reply_drop(v); }
Expand Down Expand Up @@ -391,7 +382,6 @@ inline void z_null(z_owned_session_t* v) { z_session_null(v); }
inline void z_null(z_owned_publisher_t* v) { z_publisher_null(v); }
inline void z_null(z_owned_keyexpr_t* v) { z_keyexpr_null(v); }
inline void z_null(z_owned_config_t* v) { z_config_null(v); }
inline void z_null(z_owned_scouting_config_t* v) { z_scouting_config_null(v); }
inline void z_null(z_owned_subscriber_t* v) { z_subscriber_null(v); }
inline void z_null(z_owned_queryable_t* v) { z_queryable_null(v); }
inline void z_null(z_owned_query_t* v) { z_query_null(v); }
Expand All @@ -412,7 +402,6 @@ inline bool z_check(const z_owned_session_t& v) { return z_session_check(&v); }
inline bool z_check(const z_owned_publisher_t& v) { return z_publisher_check(&v); }
inline bool z_check(const z_owned_keyexpr_t& v) { return z_keyexpr_check(&v); }
inline bool z_check(const z_owned_config_t& v) { return z_config_check(&v); }
inline bool z_check(const z_owned_scouting_config_t& v) { return z_scouting_config_check(&v); }
inline bool z_check(const z_owned_subscriber_t& v) { return z_subscriber_check(&v); }
inline bool z_check(const z_owned_queryable_t& v) { return z_queryable_check(&v); }
inline bool z_check(const z_owned_reply_t& v) { return z_reply_check(&v); }
Expand Down
18 changes: 18 additions & 0 deletions include/zenoh-pico/api/olv_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
void z_##name##_drop(ownedtype *obj); \
void z_##name##_null(ownedtype *obj);

#define _Z_OWNED_FUNCTIONS_NO_COPY_DEF(loanedtype, ownedtype, name) \
_Bool z_##name##_check(const ownedtype *obj); \
const loanedtype *z_##name##_loan(const ownedtype *obj); \
loanedtype *z_##name##_loan_mut(ownedtype *obj); \
ownedtype *z_##name##_move(ownedtype *obj); \
void z_##name##_drop(ownedtype *obj); \
void z_##name##_null(ownedtype *obj);

#define _Z_VIEW_FUNCTIONS_DEF(loanedtype, viewtype, name) \
const loanedtype *z_view_##name##_loan(const viewtype *name); \
loanedtype *z_view_##name##_loan_mut(viewtype *name); \
Expand Down Expand Up @@ -92,6 +100,16 @@
if (obj != NULL) f_drop((&obj->_val)); \
}

#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(type, name, f_check, f_null, f_drop) \
_Bool z_##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; } \
void z_##name##_null(z_owned_##name##_t *obj) { obj->_val = f_null(); } \
z_owned_##name##_t *z_##name##_move(z_owned_##name##_t *obj) { return obj; } \
void z_##name##_drop(z_owned_##name##_t *obj) { \
if (obj != NULL) f_drop((&obj->_val)); \
}

#define _Z_OWNED_FUNCTIONS_RC_IMPL(name) \
_Bool z_##name##_check(const z_owned_##name##_t *val) { return val->_rc.in != NULL; } \
const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val) { return &val->_rc; } \
Expand Down
53 changes: 4 additions & 49 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,51 +293,6 @@ const char *zp_config_get(const z_loaned_config_t *config, uint8_t key);
*/
int8_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char *value);

/**
* Builds a new :c:type:`z_owned_scouting_config_t` with a default set of properties for scouting configuration.
*
* Parameters:
* sc: Pointer to an uninitialized :c:type:`z_owned_scouting_config_t`.
*/
void z_scouting_config_default(z_owned_scouting_config_t *sc);

/**
* Builds a new :c:type:`z_owned_scouting_config_t` with values from a :c:type:`z_loaned_config_t`.
*
* Parameters:
* config: Pointer to a :c:type:`z_owned_config_t` to get the values from.
* sc: Pointer to an uninitialized :c:type:`z_owned_scouting_config_t`.
*
* Return:
* ``0`` if build successful, ``negative value`` otherwise.
*/
int8_t z_scouting_config_from(z_owned_scouting_config_t *sc, const z_loaned_config_t *config);

/**
* Gets the property with the given integer key from the configuration.
*
* Parameters:
* config: Pointer to a :c:type:`z_loaned_scouting_config_t` to get the property from.
* key: Integer key for the requested property.
*
* Return:
* The requested property value.
*/
const char *zp_scouting_config_get(const z_loaned_scouting_config_t *config, uint8_t key);

/**
* Inserts or replace the property with the given integer key in the configuration.
*
* Parameters:
* config: Pointer to a :c:type:`z_loaned_scouting_config_t` to modify.
* key: Integer key for the property to be inserted.
* value: Property value to be inserted.
*
* Return:
* ``0`` if insertion successful, ``negative value`` otherwise.
*/
int8_t zp_scouting_config_insert(z_loaned_scouting_config_t *config, uint8_t key, const char *value);

/**
* Checks if a :c:type:`z_owned_encoding_t` has non-default values.
*
Expand Down Expand Up @@ -1181,8 +1136,7 @@ int8_t z_closure_zid(z_owned_closure_zid_t *closure, z_id_handler_t call, z_drop
/**************** Loans ****************/
_Z_OWNED_FUNCTIONS_DEF(z_loaned_string_t, z_owned_string_t, string)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_keyexpr_t, z_owned_keyexpr_t, keyexpr)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_config_t, z_owned_config_t, config)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_scouting_config_t, z_owned_scouting_config_t, scouting_config)
_Z_OWNED_FUNCTIONS_NO_COPY_DEF(z_loaned_config_t, z_owned_config_t, config)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_session_t, z_owned_session_t, session)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_subscriber_t, z_owned_subscriber_t, subscriber)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_publisher_t, z_owned_publisher_t, publisher)
Expand All @@ -1196,6 +1150,7 @@ _Z_OWNED_FUNCTIONS_DEF(z_loaned_slice_t, z_owned_slice_t, slice)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_bytes_t, z_owned_bytes_t, bytes)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_bytes_writer_t, z_owned_bytes_writer_t, bytes_writer)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_reply_err_t, z_owned_reply_err_t, reply_err)
_Z_OWNED_FUNCTIONS_DEF(z_loaned_encoding_t, z_owned_encoding_t, encoding)

_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_sample_t, closure_sample)
_Z_OWNED_FUNCTIONS_CLOSURE_DEF(z_owned_closure_owned_sample_t, closure_owned_sample)
Expand Down Expand Up @@ -1247,13 +1202,13 @@ size_t z_string_len(const z_loaned_string_t *str);
* Scouts for other Zenoh entities like routers and/or peers.
*
* Parameters:
* config: Pointer to a moved :c:type:`z_owned_scouting_config_t` to configure the scouting with.
* config: Pointer to a moved :c:type:`z_owned_config_t` to configure the scouting with.
* callback: Pointer to a moved :c:type:`z_owned_closure_hello_t` callback.
*
* Return:
* ``0`` if scouting successfully triggered, ``negative value`` otherwise.
*/
int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callback);
int8_t z_scout(z_owned_config_t *config, z_owned_closure_hello_t *callback);

/**
* Opens a Zenoh session.
Expand Down
21 changes: 4 additions & 17 deletions include/zenoh-pico/api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,9 @@ _Z_VIEW_TYPE(_z_keyexpr_t, keyexpr)
* - :c:func:`zp_config_get`
* - :c:func:`zp_config_insert`
*/
_Z_OWNED_TYPE_PTR(_z_config_t, config)
_Z_OWNED_TYPE_VALUE(_z_config_t, config)
_Z_LOANED_TYPE(_z_config_t, config)

/**
* Represents a scouting configuration, used to configure a scouting procedure.
*
* Members are private and operations must be done using the provided functions:
*
* - :c:func:`z_scouting_config_default`
* - :c:func:`z_scouting_config_from`
* - :c:func:`zp_scouting_config_get`
* - :c:func:`zp_scouting_config_insert`
*/
_Z_OWNED_TYPE_PTR(_z_scouting_config_t, scouting_config)
_Z_LOANED_TYPE(_z_scouting_config_t, scouting_config)

/**
* Represents a Zenoh Session.
*/
Expand Down Expand Up @@ -194,7 +181,7 @@ _Z_LOANED_TYPE(_z_query_rc_t, query)
* uint16_t prefix: The integer prefix of this encoding.
* z_loaned_slice_t* suffix: The suffix of this encoding. It MUST be a valid UTF-8 string.
*/
_Z_OWNED_TYPE_PTR(_z_encoding_t, encoding)
_Z_OWNED_TYPE_VALUE(_z_encoding_t, encoding)
_Z_LOANED_TYPE(_z_encoding_t, encoding)

/**
Expand All @@ -204,7 +191,7 @@ _Z_LOANED_TYPE(_z_encoding_t, encoding)
* z_loaned_encoding_t encoding: The encoding of the error `payload`.
* z_loaned_bytes_t* payload: The payload of this zenoh reply error.
*/
_Z_OWNED_TYPE_PTR(_z_value_t, reply_err)
_Z_OWNED_TYPE_VALUE(_z_value_t, reply_err)
_Z_LOANED_TYPE(_z_value_t, reply_err)

/**
Expand Down Expand Up @@ -427,7 +414,7 @@ _Z_LOANED_TYPE(_z_sample_rc_t, sample)
* z_loaned_slice_t* zid: The Zenoh ID of the scouted entity (empty if absent).
* z_loaned_string_array_t locators: The locators of the scouted entity.
*/
_Z_OWNED_TYPE_PTR(_z_hello_t, hello)
_Z_OWNED_TYPE_VALUE(_z_hello_t, hello)
_Z_LOANED_TYPE(_z_hello_t, hello)

/**
Expand Down
Loading

0 comments on commit 90c94ac

Please sign in to comment.