Skip to content

Commit

Permalink
default functions added
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Sep 11, 2024
1 parent c0a85c2 commit 8055f30
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
22 changes: 18 additions & 4 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,11 @@ typedef struct z_moved_session_t {
struct z_owned_session_t _this;
} z_moved_session_t;
/**
* Options passed to the `z_open()` function.
* Options passed to the `z_close()` function.
*/
typedef struct z_open_options_t {
typedef struct z_close_options_t {
uint8_t _dummy;
} z_open_options_t;
} z_close_options_t;
/**
* A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
*
Expand Down Expand Up @@ -789,6 +789,12 @@ typedef struct z_moved_keyexpr_t {
typedef struct z_moved_mutex_t {
struct z_owned_mutex_t _this;
} z_moved_mutex_t;
/**
* Options passed to the `z_open()` function.
*/
typedef struct z_open_options_t {
uint8_t _dummy;
} z_open_options_t;
/**
* Represents the set of options that can be applied to the delete operation by a previously declared publisher,
* whenever issued via `z_publisher_delete()`.
Expand Down Expand Up @@ -1850,7 +1856,11 @@ ZENOHC_API struct z_clock_t z_clock_now(void);
*/
ZENOHC_API
z_result_t z_close(struct z_moved_session_t *session,
const struct z_open_options_t *_options);
const struct z_close_options_t *_options);
/**
* Constructs the default value for `z_close_options_t`.
*/
ZENOHC_API void z_close_options_default(struct z_close_options_t *this_);
/**
* Calls the closure. Calling an uninitialized closure is a no-op.
*/
Expand Down Expand Up @@ -3363,6 +3373,10 @@ ZENOHC_API
z_result_t z_open(struct z_owned_session_t *this_,
struct z_moved_config_t *config,
const struct z_open_options_t *_options);
/**
* Constructs the default value for `z_open_options_t`.
*/
ZENOHC_API void z_open_options_default(struct z_open_options_t *this_);
/**
* @attention Unstable feature.
* @brief Constructs and opens a new Zenoh session with specified client storage.
Expand Down
18 changes: 17 additions & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ pub struct z_open_options_t {
_dummy: u8,
}

/// Constructs the default value for `z_open_options_t`.
#[no_mangle]
pub extern "C" fn z_open_options_default(this_: &mut MaybeUninit<z_open_options_t>) {
this_.write(z_open_options_t {
_dummy: 0,
});
}

/// Constructs and opens a new Zenoh session.
///
/// @return 0 in case of success, negative error code otherwise (in this case the session will be in its gravestone state).
Expand Down Expand Up @@ -135,14 +143,22 @@ pub struct z_close_options_t {
_dummy: u8,
}

/// Constructs the default value for `z_close_options_t`.
#[no_mangle]
pub extern "C" fn z_close_options_default(this_: &mut MaybeUninit<z_close_options_t>) {
this_.write(z_close_options_t {
_dummy: 0,
});
}

/// Closes a zenoh session. This alos drops and invalidates `session`.
///
/// @return 0 in case of success, a negative value if an error occured while closing the session,
/// the remaining reference count (number of shallow copies) of the session otherwise, saturating at i8::MAX.
#[no_mangle]
pub extern "C" fn z_close(
session: &mut z_moved_session_t,
_options: Option<&z_open_options_t>,
_options: Option<&z_close_options_t>,
) -> result::z_result_t {
let Some(s) = session.take_rust_type() else {
return result::Z_EINVAL;
Expand Down

0 comments on commit 8055f30

Please sign in to comment.