Skip to content

Commit

Permalink
fix: updating exposed types
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed May 21, 2024
1 parent 827c321 commit 9315dba
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 55 deletions.
10 changes: 5 additions & 5 deletions include/zenoh-pico/api/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ inline bool z_check(const z_owned_hello_t& v) { return z_hello_check(&v); }
inline bool z_check(const z_owned_str_t& v) { return z_str_check(&v); }
inline bool z_check(const z_owned_str_t& v) { return z_sample_check(&v); }

inline void z_call(const z_owned_closure_sample_t &closure, const z_sample_t *sample)
inline void z_call(const z_owned_closure_sample_t &closure, const z_loaned_sample_t *sample)
{ z_closure_sample_call(&closure, sample); }
inline void z_call(const z_owned_closure_owned_sample_t &closure, const z_sample_t *sample)
inline void z_call(const z_owned_closure_owned_sample_t &closure, const z_owned_sample_t *sample)
{ z_closure_owned_sample_call(&closure, sample); }
inline void z_call(const z_owned_closure_query_t &closure, const z_query_t *query)
inline void z_call(const z_owned_closure_query_t &closure, const z_loaned_query_t *query)
{ z_closure_query_call(&closure, query); }
inline void z_call(const z_owned_closure_owned_query_t &closure, const z_query_t *query)
inline void z_call(const z_owned_closure_owned_query_t &closure, const z_owned_query_t *query)
{ z_closure_owned_query_call(&closure, query); }
inline void z_call(const z_owned_closure_reply_t &closure, const z_reply_t *reply)
inline void z_call(const z_owned_closure_reply_t &closure, const z_loaned_reply_t *reply)
{ z_closure_reply_call(&closure, reply); }
inline void z_call(const z_owned_closure_owned_reply_t &closure, z_owned_reply_t *reply)
{ z_closure_owned_reply_call(&closure, reply); }
Expand Down
20 changes: 10 additions & 10 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ const z_loaned_keyexpr_t *z_query_keyexpr(const z_loaned_query_t *query);
* Returns:
* Returns a new sample closure.
*/
int8_t z_closure_sample(z_owned_closure_sample_t *closure, _z_data_handler_t call, _z_dropper_handler_t drop,
int8_t z_closure_sample(z_owned_closure_sample_t *closure, z_data_handler_t call, z_dropper_handler_t drop,
void *context);

/**
Expand All @@ -608,8 +608,8 @@ int8_t z_closure_sample(z_owned_closure_sample_t *closure, _z_data_handler_t cal
* Returns:
* Returns a new sample closure.
*/
int8_t z_closure_owned_sample(z_owned_closure_owned_sample_t *closure, _z_owned_sample_handler_t call,
_z_dropper_handler_t drop, void *context);
int8_t z_closure_owned_sample(z_owned_closure_owned_sample_t *closure, z_owned_sample_handler_t call,
z_dropper_handler_t drop, void *context);

/**
* Return a new query closure.
Expand All @@ -636,7 +636,7 @@ int8_t z_closure_owned_sample(z_owned_closure_owned_sample_t *closure, _z_owned_
* Returns:
* Returns a new query closure.
*/
int8_t z_closure_query(z_owned_closure_query_t *closure, _z_queryable_handler_t call, _z_dropper_handler_t drop,
int8_t z_closure_query(z_owned_closure_query_t *closure, z_queryable_handler_t call, z_dropper_handler_t drop,
void *context);

/**
Expand All @@ -660,8 +660,8 @@ int8_t z_closure_query(z_owned_closure_query_t *closure, _z_queryable_handler_t
* Returns:
* Returns a new query closure.
*/
int8_t z_closure_owned_query(z_owned_closure_owned_query_t *closure, _z_owned_query_handler_t call,
_z_dropper_handler_t drop, void *context);
int8_t z_closure_owned_query(z_owned_closure_owned_query_t *closure, z_owned_query_handler_t call,
z_dropper_handler_t drop, void *context);

/**
* Return a new reply closure.
Expand All @@ -688,7 +688,7 @@ int8_t z_closure_owned_query(z_owned_closure_owned_query_t *closure, _z_owned_qu
* Returns:
* Returns a new reply closure.
*/
int8_t z_closure_reply(z_owned_closure_reply_t *closure, _z_reply_handler_t call, _z_dropper_handler_t drop,
int8_t z_closure_reply(z_owned_closure_reply_t *closure, z_reply_handler_t call, z_dropper_handler_t drop,
void *context);

/**
Expand Down Expand Up @@ -717,7 +717,7 @@ int8_t z_closure_reply(z_owned_closure_reply_t *closure, _z_reply_handler_t call
* Returns a new reply closure.
*/
int8_t z_closure_owned_reply(z_owned_closure_owned_reply_t *closure, z_owned_reply_handler_t call,
_z_dropper_handler_t drop, void *context);
z_dropper_handler_t drop, void *context);

/**
* Return a new hello closure.
Expand All @@ -744,7 +744,7 @@ int8_t z_closure_owned_reply(z_owned_closure_owned_reply_t *closure, z_owned_rep
* Returns:
* Returns a new hello closure.
*/
int8_t z_closure_hello(z_owned_closure_hello_t *closure, z_owned_hello_handler_t call, _z_dropper_handler_t drop,
int8_t z_closure_hello(z_owned_closure_hello_t *closure, z_owned_hello_handler_t call, z_dropper_handler_t drop,
void *context);

/**
Expand Down Expand Up @@ -772,7 +772,7 @@ int8_t z_closure_hello(z_owned_closure_hello_t *closure, z_owned_hello_handler_t
* Returns:
* Returns a new zid closure.
*/
int8_t z_closure_zid(z_owned_closure_zid_t *closure, z_id_handler_t call, _z_dropper_handler_t drop, void *context);
int8_t z_closure_zid(z_owned_closure_zid_t *closure, z_id_handler_t call, z_dropper_handler_t drop, void *context);

/**************** Loans ****************/
#define _OWNED_FUNCTIONS(loanedtype, ownedtype, name) \
Expand Down
60 changes: 32 additions & 28 deletions include/zenoh-pico/api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,24 +480,25 @@ _Bool z_str_array_is_empty(const z_str_array_t *a);
_OWNED_TYPE_PTR(z_str_array_t, str_array)
_LOANED_TYPE(z_str_array_t, str_array)

typedef void (*_z_dropper_handler_t)(void *arg);
typedef void (*_z_owned_sample_handler_t)(z_owned_sample_t *sample, void *arg);
typedef void (*z_dropper_handler_t)(void *arg);
typedef void (*z_owned_sample_handler_t)(z_owned_sample_t *sample, void *arg);
typedef _z_data_handler_t z_data_handler_t;

/**
* Represents the sample closure.
*
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*
* Members:
* _z_data_handler_t call: `void *call(const struct z_sample_t*, const void *context)` is the callback function.
* _z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* z_data_handler_t call: `void *call(const struct z_sample_t*, const void *context)` is the callback function.
* z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* void *context: a pointer to an arbitrary state.
*/
// TODO(sashacmc):
typedef struct {
void *context;
_z_data_handler_t call;
_z_dropper_handler_t drop;
z_data_handler_t call;
z_dropper_handler_t drop;
} z_owned_closure_sample_t;

void z_closure_sample_call(const z_owned_closure_sample_t *closure, const z_loaned_sample_t *sample);
Expand All @@ -508,20 +509,22 @@ void z_closure_sample_call(const z_owned_closure_sample_t *closure, const z_loan
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*
* Members:
* _z_owned_sample_handler_t call: `void *call(const struct z_owned_sample_t*, const void *context)` is the callback
* z_owned_sample_handler_t call: `void *call(const struct z_owned_sample_t*, const void *context)` is the callback
* function.
* _z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed. void *context: a
* z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed. void *context: a
* pointer to an arbitrary state.
*/
// TODO(sashacmc):
typedef struct {
void *context;
_z_owned_sample_handler_t call;
_z_dropper_handler_t drop;
z_owned_sample_handler_t call;
z_dropper_handler_t drop;
} z_owned_closure_owned_sample_t;

void z_closure_owned_sample_call(const z_owned_closure_owned_sample_t *closure, z_owned_sample_t *sample);

typedef _z_queryable_handler_t z_queryable_handler_t;

/**
* Represents the query callback closure.
*
Expand All @@ -530,58 +533,59 @@ void z_closure_owned_sample_call(const z_owned_closure_owned_sample_t *closure,
* Members:
* _z_queryable_handler_t call: `void (*_z_queryable_handler_t)(z_query_t *query, void *arg)` is the
* callback function.
* _z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* void *context: a pointer to an arbitrary state.
*/
// TODO(sashacmc):
typedef struct {
void *context;
_z_queryable_handler_t call;
_z_dropper_handler_t drop;
z_queryable_handler_t call;
z_dropper_handler_t drop;
} z_owned_closure_query_t;

void z_closure_query_call(const z_owned_closure_query_t *closure, const z_loaned_query_t *query);

typedef void (*_z_owned_query_handler_t)(z_owned_query_t *query, void *arg);
typedef void (*z_owned_query_handler_t)(z_owned_query_t *query, void *arg);

/**
* Represents the owned query closure.
*
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*
* Members:
* _z_owned_query_handler_t call: `void *call(const struct z_owned_query_t*, const void *context)` is the callback
* z_owned_query_handler_t call: `void *call(const struct z_owned_query_t*, const void *context)` is the callback
* function.
* _z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed. void *context: a
* z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed. void *context: a
* pointer to an arbitrary state.
*/
// TODO(sashacmc):
typedef struct {
void *context;
_z_owned_query_handler_t call;
_z_dropper_handler_t drop;
z_owned_query_handler_t call;
z_dropper_handler_t drop;
} z_owned_closure_owned_query_t;

void z_closure_owned_query_call(const z_owned_closure_owned_query_t *closure, z_owned_query_t *query);

typedef void (*z_owned_reply_handler_t)(z_owned_reply_t *reply, void *arg);
typedef _z_reply_handler_t z_reply_handler_t;

/**
* Represents the query reply callback closure.
*
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*
* Members:
* _z_reply_handler_t call: `void (*_z_reply_handler_t)(_z_reply_t *reply, void *arg)` is the
* z_reply_handler_t call: `void (*_z_reply_handler_t)(_z_reply_t *reply, void *arg)` is the
* callback function.
* _z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* void *context: a pointer to an arbitrary state.
*/
// TODO(sashacmc):
typedef struct {
void *context;
_z_reply_handler_t call;
_z_dropper_handler_t drop;
z_reply_handler_t call;
z_dropper_handler_t drop;
} z_owned_closure_reply_t;

void z_closure_reply_call(const z_owned_closure_reply_t *closure, const z_loaned_reply_t *reply);
Expand All @@ -594,14 +598,14 @@ void z_closure_reply_call(const z_owned_closure_reply_t *closure, const z_loaned
* Members:
* z_owned_reply_handler_t call: `void (*z_owned_reply_handler_t)(const z_owned_reply_t *reply, void *arg)` is the
* callback function.
* _z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* void *context: a pointer to an arbitrary state.
*/
// TODO(sashacmc):
typedef struct {
void *context;
z_owned_reply_handler_t call;
_z_dropper_handler_t drop;
z_dropper_handler_t drop;
} z_owned_closure_owned_reply_t;

void z_closure_owned_reply_call(const z_owned_closure_owned_reply_t *closure, z_owned_reply_t *reply);
Expand All @@ -616,14 +620,14 @@ typedef void (*z_owned_hello_handler_t)(z_owned_hello_t *hello, void *arg);
* Members:
* z_owned_hello_handler_t call: `void (*z_owned_hello_handler_t)(const z_owned_hello_t *hello, void *arg)` is the
* callback function.
* _z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* void *context: a pointer to an arbitrary state.
*/
// TODO(sashacmc):
typedef struct {
void *context;
z_owned_hello_handler_t call;
_z_dropper_handler_t drop;
z_dropper_handler_t drop;
} z_owned_closure_hello_t;

void z_closure_hello_call(const z_owned_closure_hello_t *closure, z_owned_hello_t *hello);
Expand All @@ -637,14 +641,14 @@ typedef void (*z_id_handler_t)(const z_id_t *id, void *arg);
*
* Members:
* z_id_handler_t call: `void (*z_id_handler_t)(const z_id_t *id, void *arg)` is the callback function.
* _z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* z_dropper_handler_t drop: `void *drop(void*)` allows the callback's state to be freed.
* void *context: a pointer to an arbitrary state.
*/
// TODO(sashacmc):
typedef struct {
void *context;
z_id_handler_t call;
_z_dropper_handler_t drop;
z_dropper_handler_t drop;
} z_owned_closure_zid_t;

void z_closure_zid_call(const z_owned_closure_zid_t *closure, const z_id_t *id);
Expand Down
22 changes: 11 additions & 11 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,17 +443,17 @@ OWNED_FUNCTIONS_RC(session)
return _Z_RES_OK; \
}

OWNED_FUNCTIONS_CLOSURE(z_owned_closure_sample_t, closure_sample, _z_data_handler_t, _z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_sample_t, closure_owned_sample, _z_owned_sample_handler_t,
_z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_query_t, closure_query, _z_queryable_handler_t, _z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_query_t, closure_owned_query, _z_owned_query_handler_t,
_z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_reply_t, closure_reply, _z_reply_handler_t, _z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_sample_t, closure_sample, _z_data_handler_t, z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_sample_t, closure_owned_sample, z_owned_sample_handler_t,
z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_query_t, closure_query, _z_queryable_handler_t, z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_query_t, closure_owned_query, z_owned_query_handler_t,
z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_reply_t, closure_reply, _z_reply_handler_t, z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_owned_reply_t, closure_owned_reply, z_owned_reply_handler_t,
_z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_hello_t, closure_hello, z_owned_hello_handler_t, _z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_zid_t, closure_zid, z_id_handler_t, _z_dropper_handler_t)
z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_hello_t, closure_hello, z_owned_hello_handler_t, z_dropper_handler_t)
OWNED_FUNCTIONS_CLOSURE(z_owned_closure_zid_t, closure_zid, z_id_handler_t, z_dropper_handler_t)

/************* Primitives **************/
typedef struct __z_hello_handler_wrapper_t {
Expand Down Expand Up @@ -807,7 +807,7 @@ 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, z_loaned_keyexpr_t *keyexpr, const char *parameters,
int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const char *parameters,
z_owned_closure_reply_t *callback, const z_get_options_t *options) {
int8_t ret = _Z_RES_OK;

Expand Down
2 changes: 1 addition & 1 deletion src/net/reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
_z_reply_t _z_reply_null(void) {
_z_reply_t r = {._tag = Z_REPLY_TAG_DATA,
.data = {
.replier_id = 0,
.replier_id = {.id = {0}},
.sample = {.in = NULL},
}};
return r;
Expand Down
1 change: 1 addition & 0 deletions tests/z_perf_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ int main(int argc, char **argv) {
}
#else
int main(void) {
(void)test_stats;
printf("ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION but this test requires it.\n");
return -2;
}
Expand Down

0 comments on commit 9315dba

Please sign in to comment.