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

add closure typedefs for C #765

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,20 @@ pub fn generate_generic_call_c(macro_func: &[FunctionSignature]) -> String {
}

pub fn generate_generic_closure_c(macro_func: &[FunctionSignature]) -> String {
generate_generic_c(macro_func, "z_closure", false)
let mut out = "typedef void(*z_closure_drop_callback_t)(void *context);\n".to_string();
for f in macro_func {
let callback_typename = f.func_name.clone() + "_callback_t";
let prototype = f.args[1]
.clone()
.typename
.typename
.replace(" (*call)", &format!("(*{})", &callback_typename));

out += &format!("typedef {};\n", prototype);
}
out += "\n";
out += &generate_generic_c(macro_func, "z_closure", false);
out
}

pub fn generate_generic_recv_c(macro_func: &[FunctionSignature]) -> String {
Expand Down
9 changes: 9 additions & 0 deletions include/zenoh_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,15 @@ static inline void ze_serializer_take(ze_owned_serializer_t* this_, ze_moved_ser
const zc_loaned_closure_matching_status_t* : zc_closure_matching_status_call \
)(closure, hello)

typedef void(*z_closure_drop_callback_t)(void *context);
typedef void(*z_closure_hello_callback_t)(z_loaned_hello_t *hello, void *context);
typedef void(*z_closure_query_callback_t)(z_loaned_query_t *query, void *context);
typedef void(*z_closure_reply_callback_t)(z_loaned_reply_t *reply, void *context);
typedef void(*z_closure_sample_callback_t)(z_loaned_sample_t *sample, void *context);
typedef void(*z_closure_zid_callback_t)(const z_id_t *z_id, void *context);
typedef void(*zc_closure_log_callback_t)(zc_log_severity_t severity, const z_loaned_string_t *msg, void *context);
typedef void(*zc_closure_matching_status_callback_t)(const zc_matching_status_t *matching_status, void *context);

#define z_closure(this_, call, drop, context) \
_Generic((this_), \
z_owned_closure_hello_t* : z_closure_hello, \
Expand Down
Loading