Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store value instead of ptr for z_owned_config_t, z_owned_value_t, z_owned_hello_t, z_owned_encoding_t, z_owned_keyexpr_t #483

Merged
merged 11 commits into from
Jul 2, 2024
Merged
18 changes: 0 additions & 18 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,16 +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
.. autocfunction:: primitives.h::z_encoding_loan_mut
.. autocfunction:: primitives.h::z_encoding_move
.. autocfunction:: primitives.h::z_encoding_null
.. autocfunction:: primitives.h::z_encoding_from_str
.. autocfunction:: primitives.h::z_encoding_to_string
.. autocfunction:: primitives.h::z_reply_err_payload
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
6 changes: 3 additions & 3 deletions examples/mbed/z_scout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,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;
}
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 @@ -132,7 +129,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 @@ -194,7 +190,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 @@ -260,7 +255,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 @@ -310,7 +304,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 @@ -331,7 +324,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 @@ -352,7 +344,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 @@ -383,7 +374,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 @@ -404,7 +394,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
24 changes: 24 additions & 0 deletions include/zenoh-pico/api/olv_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
type _val; \
} z_owned_##name##_t;

// For value types
#define _Z_OWNED_TYPE_VALUE(type, name) \
typedef struct { \
type _val; \
} z_owned_##name##_t;

// For refcounted types
#define _Z_OWNED_TYPE_RC(type, name) \
typedef struct { \
Expand All @@ -52,6 +58,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 +106,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
Loading
Loading