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

make closure fields private #757

Merged
merged 1 commit into from
Oct 11, 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
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ pub fn generate_generic_closure_cpp(macro_func: &[FunctionSignature]) -> String
.typename
.typename
.replace(&format!(" (*{})", &processed_f.args[1].name), "");
let callback_typename = f.func_name.clone() + "_callabck_t";
let callback_typename = f.func_name.clone() + "_callback_t";
out += &format!(
"extern \"C\" using {} = {};\n",
callback_typename, prototype
Expand Down
6 changes: 0 additions & 6 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ Types

.. doxygenstruct:: z_loaned_closure_zid_t
.. doxygenstruct:: z_owned_closure_zid_t
:members:

Functions
^^^^^^^^^
Expand Down Expand Up @@ -557,7 +556,6 @@ Types

.. doxygenstruct:: zc_owned_matching_listener_t
.. doxygenstruct:: zc_owned_closure_matching_status_t
:members:

Functions
---------
Expand Down Expand Up @@ -602,7 +600,6 @@ Types

.. doxygenstruct:: z_loaned_closure_sample_t
.. doxygenstruct:: z_owned_closure_sample_t
:members:

.. doxygenstruct:: z_subscriber_options_t
:members:
Expand Down Expand Up @@ -655,7 +652,6 @@ Types

.. doxygenstruct:: z_loaned_closure_query_t
.. doxygenstruct:: z_owned_closure_query_t
:members:

.. doxygenstruct:: z_queryable_options_t
:members:
Expand Down Expand Up @@ -725,7 +721,6 @@ Types

.. doxygenstruct:: z_loaned_closure_reply_t
.. doxygenstruct:: z_owned_closure_reply_t
:members:

.. doxygenstruct:: z_get_options_t
:members:
Expand Down Expand Up @@ -788,7 +783,6 @@ Types
:members:
.. doxygenstruct:: z_loaned_closure_hello_t
.. doxygenstruct:: z_owned_closure_hello_t
:members:

Functions
---------
Expand Down
220 changes: 86 additions & 134 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,29 +282,14 @@ typedef struct z_close_options_t {
uint8_t _dummy;
} z_close_options_t;
/**
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* @brief A hello message-processing closure.
*
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*/
typedef struct z_owned_closure_hello_t {
/**
* An optional pointer to a closure state.
*/
void *context;
/**
* A closure body.
*/
void (*call)(struct z_loaned_hello_t *hello, void *context);
/**
* An optional drop function that will be called when the closure is dropped.
*/
void (*drop)(void *context);
void *_context;
void (*_call)(struct z_loaned_hello_t *hello, void *context);
void (*_drop)(void *context);
} z_owned_closure_hello_t;
/**
* Moved closure.
Expand All @@ -313,28 +298,14 @@ typedef struct z_moved_closure_hello_t {
struct z_owned_closure_hello_t _this;
} z_moved_closure_hello_t;
/**
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
*
* Closures are not guaranteed not to be called concurrently.
* @brief A query-processing closure.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*/
typedef struct z_owned_closure_query_t {
/**
* An optional pointer to a context representing a closure state.
*/
void *context;
/**
* A closure body.
*/
void (*call)(struct z_loaned_query_t *reply, void *context);
/**
* An optional drop function that will be called when the closure is dropped.
*/
void (*drop)(void *context);
void *_context;
void (*_call)(struct z_loaned_query_t *reply, void *context);
void (*_drop)(void *context);
} z_owned_closure_query_t;
/**
* Moved closure.
Expand All @@ -343,28 +314,14 @@ typedef struct z_moved_closure_query_t {
struct z_owned_closure_query_t _this;
} z_moved_closure_query_t;
/**
* A structure that contains all the elements for stateful, memory-leak-free callbacks.
*
* Closures are not guaranteed not to be called concurrently.
* @brief A reply-processing closure.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*/
typedef struct z_owned_closure_reply_t {
/**
* An optional pointer to a context representing a closure state.
*/
void *context;
/**
* A closure body.
*/
void (*call)(struct z_loaned_reply_t *reply, void *context);
/**
* An optional drop function that will be called when the closure is dropped.
*/
void (*drop)(void *context);
void *_context;
void (*_call)(struct z_loaned_reply_t *reply, void *context);
void (*_drop)(void *context);
} z_owned_closure_reply_t;
/**
* Moved closure.
Expand All @@ -373,28 +330,14 @@ typedef struct z_moved_closure_reply_t {
struct z_owned_closure_reply_t _this;
} z_moved_closure_reply_t;
/**
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*
* Closures are not guaranteed not to be called concurrently.
* @brief A sample-processing closure.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*/
typedef struct z_owned_closure_sample_t {
/**
* An optional pointer to a context representing a closure state.
*/
void *context;
/**
* A closure body.
*/
void (*call)(struct z_loaned_sample_t *sample, void *context);
/**
* An optional drop function that will be called when the closure is dropped.
*/
void (*drop)(void *context);
void *_context;
void (*_call)(struct z_loaned_sample_t *sample, void *context);
void (*_drop)(void *context);
} z_owned_closure_sample_t;
/**
* Moved closure.
Expand All @@ -404,29 +347,15 @@ typedef struct z_moved_closure_sample_t {
} z_moved_closure_sample_t;
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
* @brief A zenoh id-processing closure.
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
*/
#if defined(Z_FEATURE_UNSTABLE_API)
typedef struct z_owned_closure_zid_t {
/**
* An optional pointer to a closure state.
*/
void *context;
/**
* A callback function.
*/
void (*call)(const struct z_id_t *z_id, void *context);
/**
* An optional function that will be called upon closure drop.
*/
void (*drop)(void *context);
void *_context;
void (*_call)(const struct z_id_t *z_id, void *context);
void (*_drop)(void *context);
} z_owned_closure_zid_t;
#endif
/**
Expand Down Expand Up @@ -890,28 +819,14 @@ typedef struct z_time_t {
uint64_t t;
} z_time_t;
/**
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
* @brief A log-processing closure.
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*/
typedef struct zc_owned_closure_log_t {
/**
* An optional pointer to a closure state.
*/
void *context;
/**
* A closure body.
*/
void (*call)(enum zc_log_severity_t severity, const struct z_loaned_string_t *msg, void *context);
/**
* An optional drop function that will be called when the closure is dropped.
*/
void (*drop)(void *context);
void *_context;
void (*_call)(enum zc_log_severity_t severity, const struct z_loaned_string_t *msg, void *context);
void (*_drop)(void *context);
} zc_owned_closure_log_t;
/**
* Moved closure.
Expand All @@ -933,29 +848,15 @@ typedef struct zc_matching_status_t {
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
* @brief A matching status-processing closure.
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
*/
#if defined(Z_FEATURE_UNSTABLE_API)
typedef struct zc_owned_closure_matching_status_t {
/**
* An optional pointer to a closure state.
*/
void *context;
/**
* A closure body.
*/
void (*call)(const struct zc_matching_status_t *matching_status, void *context);
/**
* An optional drop function that will be called when the closure is dropped.
*/
void (*drop)(void *context);
void *_context;
void (*_call)(const struct zc_matching_status_t *matching_status, void *context);
void (*_drop)(void *context);
} zc_owned_closure_matching_status_t;
#endif
/**
Expand Down Expand Up @@ -1516,6 +1417,15 @@ z_result_t z_close(struct z_loaned_session_t *session,
ZENOHC_API void z_close_options_default(struct z_close_options_t *this_);
/**
* @brief Constructs closure.
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
*
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -1543,6 +1453,13 @@ ZENOHC_API
const struct z_loaned_closure_hello_t *z_closure_hello_loan(const struct z_owned_closure_hello_t *closure);
/**
* @brief Constructs closure.
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -1570,6 +1487,13 @@ ZENOHC_API
const struct z_loaned_closure_query_t *z_closure_query_loan(const struct z_owned_closure_query_t *closure);
/**
* @brief Constructs closure.
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -1598,6 +1522,13 @@ ZENOHC_API
const struct z_loaned_closure_reply_t *z_closure_reply_loan(const struct z_owned_closure_reply_t *closure);
/**
* @brief Constructs closure.
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -1625,6 +1556,13 @@ ZENOHC_API
const struct z_loaned_closure_sample_t *z_closure_sample_loan(const struct z_owned_closure_sample_t *closure);
/**
* @brief Constructs closure.
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -4454,6 +4392,13 @@ void zc_cleanup_orphaned_shm_segments(void);
#endif
/**
* @brief Constructs closure.
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -4484,6 +4429,13 @@ ZENOHC_API
const struct zc_loaned_closure_log_t *zc_closure_log_loan(const struct zc_owned_closure_log_t *closure);
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
*
* Closures are not guaranteed not to be called concurrently.
*
* It is guaranteed that:
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
* @brief Constructs closure.
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
Expand Down
Loading
Loading