Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Sep 10, 2024
2 parents 8322703 + 3633de2 commit 9d8ded6
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 521 deletions.
210 changes: 74 additions & 136 deletions Cargo.lock

Large diffs are not rendered by default.

414 changes: 75 additions & 339 deletions build-resources/opaque-types/Cargo.lock

Large diffs are not rendered by default.

29 changes: 18 additions & 11 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ typedef struct zc_liveliness_declaration_options_t {
*/
#if defined(UNSTABLE)
typedef struct zc_liveliness_subscriber_options_t {
uint8_t _dummy;
bool history;
} zc_liveliness_subscriber_options_t;
#endif
/**
Expand Down Expand Up @@ -3324,9 +3324,9 @@ void z_memory_layout_drop(z_moved_memory_layout_t *this_);
*/
#if (defined(SHARED_MEMORY) && defined(UNSTABLE))
ZENOHC_API
void z_memory_layout_get_data(size_t *out_size,
struct z_alloc_alignment_t *out_alignment,
const z_loaned_memory_layout_t *this_);
void z_memory_layout_get_data(const z_loaned_memory_layout_t *this_,
size_t *out_size,
struct z_alloc_alignment_t *out_alignment);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
Expand Down Expand Up @@ -4127,12 +4127,19 @@ z_loaned_shm_mut_t *z_shm_mut_loan_mut(z_owned_shm_mut_t *this_);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
* @brief Tries to construct ZShmMut slice from ZShm slice.
* @brief Tries to obtain mutable SHM buffer instead of immutable one.
* @param this: mutable SHM buffer to be initialized upon success
* @param that: immutable SHM buffer
* @param immut: immutable SHM buffer returned back to caller's side
* ONLY in case of Z_EUNAVAILABLE failure
* @return Z_OK in case of success, Z_EUNAVAILABLE in case of unsuccessful write access,
* Z_EINVAL if moved value is incorrect.
*/
#if (defined(SHARED_MEMORY) && defined(UNSTABLE))
ZENOHC_API
void z_shm_mut_try_from_immut(z_owned_shm_mut_t *this_,
z_moved_shm_t *that);
z_result_t z_shm_mut_try_from_immut(z_owned_shm_mut_t *this_,
z_moved_shm_t *that,
z_owned_shm_t *immut);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
Expand Down Expand Up @@ -4982,7 +4989,7 @@ z_result_t zc_liveliness_declare_subscriber(struct z_owned_subscriber_t *this_,
const struct z_loaned_session_t *session,
const struct z_loaned_keyexpr_t *key_expr,
struct z_moved_closure_sample_t *callback,
struct zc_liveliness_subscriber_options_t *_options);
struct zc_liveliness_subscriber_options_t *options);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
Expand Down Expand Up @@ -5125,9 +5132,9 @@ enum zc_reply_keyexpr_t zc_reply_keyexpr_default(void);
*/
#if (defined(SHARED_MEMORY) && defined(UNSTABLE))
ZENOHC_API
z_result_t zc_shm_client_list_add_client(z_protocol_id_t id,
z_moved_shm_client_t *client,
zc_loaned_shm_client_list_t *list);
z_result_t zc_shm_client_list_add_client(zc_loaned_shm_client_list_t *this_,
z_protocol_id_t id,
z_moved_shm_client_t *client);
#endif
/**
* @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
Expand Down
5 changes: 2 additions & 3 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ use std::{

use libc::c_char;
use zenoh::{
bytes::{Encoding, EncodingBuilderTrait, ZBytes},
qos::{CongestionControl, Priority, QoSBuilderTrait},
bytes::{Encoding, ZBytes},
qos::{CongestionControl, Priority},
query::{ConsolidationMode, QueryConsolidation, QueryTarget, Reply, ReplyError, Selector},
sample::SampleBuilderTrait,
Wait,
};

Expand Down
7 changes: 4 additions & 3 deletions src/liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub extern "C" fn zc_liveliness_undeclare_token(
/// @brief The options for `zc_liveliness_declare_subscriber()`
#[repr(C)]
pub struct zc_liveliness_subscriber_options_t {
_dummy: u8,
history: bool,
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
Expand All @@ -145,7 +145,7 @@ pub struct zc_liveliness_subscriber_options_t {
pub extern "C" fn zc_liveliness_subscriber_options_default(
this: &mut MaybeUninit<zc_liveliness_subscriber_options_t>,
) {
this.write(zc_liveliness_subscriber_options_t { _dummy: 0 });
this.write(zc_liveliness_subscriber_options_t { history: false });
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
Expand All @@ -164,7 +164,7 @@ pub extern "C" fn zc_liveliness_declare_subscriber(
session: &z_loaned_session_t,
key_expr: &z_loaned_keyexpr_t,
callback: &mut z_moved_closure_sample_t,
_options: Option<&mut zc_liveliness_subscriber_options_t>,
options: Option<&mut zc_liveliness_subscriber_options_t>,
) -> result::z_result_t {
let this = this.as_rust_type_mut_uninit();
let session = session.as_rust_type_ref();
Expand All @@ -173,6 +173,7 @@ pub extern "C" fn zc_liveliness_declare_subscriber(
match session
.liveliness()
.declare_subscriber(key_expr)
.history(options.is_some_and(|o| o.history))
.callback(move |sample| {
let sample = sample.as_loaned_c_type_ref();
z_closure_sample_call(z_closure_sample_loan(&callback), sample)
Expand Down
4 changes: 1 addition & 3 deletions src/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
use std::mem::MaybeUninit;

use zenoh::{
bytes::EncodingBuilderTrait,
qos::{CongestionControl, Priority, QoSBuilderTrait},
sample::{SampleBuilderTrait, TimestampBuilderTrait},
qos::{CongestionControl, Priority},
Wait,
};

Expand Down
5 changes: 2 additions & 3 deletions src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
use std::mem::MaybeUninit;

use zenoh::{
bytes::{Encoding, EncodingBuilderTrait},
bytes::Encoding,
prelude::SessionDeclarations,
qos::{CongestionControl, Priority, QoSBuilderTrait},
qos::{CongestionControl, Priority},
query::{Query, Queryable},
sample::{SampleBuilderTrait, TimestampBuilderTrait},
Wait,
};

Expand Down
5 changes: 1 addition & 4 deletions src/querying_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

use std::mem::MaybeUninit;

use zenoh::{
bytes::EncodingBuilderTrait, prelude::SessionDeclarations, pubsub::Reliability,
qos::QoSBuilderTrait, sample::SampleBuilderTrait, session::Session, Wait,
};
use zenoh::{prelude::SessionDeclarations, pubsub::Reliability, session::Session, Wait};
use zenoh_ext::*;

use crate::{
Expand Down
32 changes: 24 additions & 8 deletions src/shm/buffer/zshmmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use std::{
use zenoh::shm::{zshmmut, ZShmMut};

use crate::{
result,
transmute::{LoanedCTypeRef, RustTypeRef, RustTypeRefUninit, TakeRustType},
z_loaned_shm_mut_t, z_moved_shm_mut_t, z_moved_shm_t, z_owned_shm_mut_t,
z_loaned_shm_mut_t, z_moved_shm_mut_t, z_moved_shm_t, z_owned_shm_mut_t, z_owned_shm_t,
};

decl_c_type!(
Expand All @@ -30,17 +31,32 @@ decl_c_type!(
);

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
/// @brief Tries to construct ZShmMut slice from ZShm slice.
/// @brief Tries to obtain mutable SHM buffer instead of immutable one.
/// @param this: mutable SHM buffer to be initialized upon success
/// @param that: immutable SHM buffer
/// @param immut: immutable SHM buffer returned back to caller's side
/// ONLY in case of Z_EUNAVAILABLE failure
/// @return Z_OK in case of success, Z_EUNAVAILABLE in case of unsuccessful write access,
/// Z_EINVAL if moved value is incorrect.
#[no_mangle]
pub extern "C" fn z_shm_mut_try_from_immut(
this: &mut MaybeUninit<z_owned_shm_mut_t>,
that: &mut z_moved_shm_t,
) {
let shm: Option<ZShmMut> = that
.take_rust_type()
.take()
.and_then(|val| val.try_into().ok());
this.as_rust_type_mut_uninit().write(shm);
immut: &mut MaybeUninit<z_owned_shm_t>,
) -> result::z_result_t {
if let Some(shm) = that.take_rust_type() {
return match ZShmMut::try_from(shm) {
Ok(val) => {
this.as_rust_type_mut_uninit().write(Some(val));
result::Z_OK
}
Err(old) => {
immut.as_rust_type_mut_uninit().write(Some(old));
result::Z_EUNAVAILABLE
}
};
}
result::Z_EINVAL
}

/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
Expand Down
4 changes: 2 additions & 2 deletions src/shm/client_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ pub unsafe extern "C" fn zc_shm_client_list_loan_mut(
/// @warning This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
#[no_mangle]
pub extern "C" fn zc_shm_client_list_add_client(
this: &mut zc_loaned_shm_client_list_t,
id: z_protocol_id_t,
client: &mut z_moved_shm_client_t,
list: &mut zc_loaned_shm_client_list_t,
) -> z_result_t {
let Some(client) = client.take_rust_type() else {
return Z_EINVAL;
};
list.as_rust_type_mut().push((id, client));
this.as_rust_type_mut().push((id, client));
Z_OK
}

Expand Down
2 changes: 1 addition & 1 deletion src/shm/provider/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ pub extern "C" fn z_memory_layout_drop(this_: &mut z_moved_memory_layout_t) {
/// @brief Extract data from Memory Layout.
#[no_mangle]
pub extern "C" fn z_memory_layout_get_data(
this: &z_loaned_memory_layout_t,
out_size: &mut MaybeUninit<usize>,
out_alignment: &mut MaybeUninit<z_alloc_alignment_t>,
this: &z_loaned_memory_layout_t,
) {
let layout = this.as_rust_type_ref();
out_size.write(layout.size().into());
Expand Down
18 changes: 10 additions & 8 deletions tests/z_api_shm_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ int test_shm_buffer(z_moved_shm_mut_t* mbuf) {
ASSERT_CHECK(immut2);

z_owned_shm_mut_t mut;
z_shm_mut_try_from_immut(&mut, z_move(immut2));
ASSERT_CHECK_ERR(immut2);
ASSERT_CHECK_ERR(mut);
ASSERT_TRUE(Z_EUNAVAILABLE == z_shm_mut_try_from_immut(&mut, z_move(immut2), &immut2));
ASSERT_CHECK(immut2);

z_drop(z_move(immut2));

z_shm_mut_try_from_immut(&mut, z_move(immut));
ASSERT_TRUE(Z_OK == z_shm_mut_try_from_immut(&mut, z_move(immut), &immut));
ASSERT_CHECK(mut);
ASSERT_CHECK_ERR(immut);

z_drop(z_move(mut));
ASSERT_CHECK_ERR(mut);
Expand Down Expand Up @@ -189,7 +191,7 @@ void alloc_fn(struct z_owned_chunk_alloc_result_t* result, const struct z_loaned
// check size and alignment
size_t size = 0;
z_alloc_alignment_t alignment;
z_memory_layout_get_data(&size, &alignment, layout);
z_memory_layout_get_data(layout, &size, &alignment);
assert(size == 1);
assert(alignment.pow == 0);

Expand Down Expand Up @@ -251,7 +253,7 @@ void layout_for_fn(struct z_owned_memory_layout_t* layout, void* context) {
// check size and alignment
size_t size = 0;
z_alloc_alignment_t alignment;
z_memory_layout_get_data(&size, &alignment, z_loan(*layout));
z_memory_layout_get_data(z_loan(*layout), &size, &alignment);

if (size != 1 || alignment.pow != 0) {
z_memory_layout_drop(z_move(*layout));
Expand Down Expand Up @@ -377,7 +379,7 @@ int run_client_storage() {
ASSERT_CHECK(client);

// add client to the list
ASSERT_OK(zc_shm_client_list_add_client(Z_SHM_POSIX_PROTOCOL_ID, z_move(client), z_loan_mut(list)));
ASSERT_OK(zc_shm_client_list_add_client(z_loan_mut(list), Z_SHM_POSIX_PROTOCOL_ID, z_move(client)));
ASSERT_CHECK_ERR(client);

// create client storage from the list
Expand Down Expand Up @@ -426,7 +428,7 @@ int run_c_client() {
ASSERT_CHECK(client);

// add client to the list
ASSERT_OK(zc_shm_client_list_add_client(100500, z_move(client), z_loan_mut(list)));
ASSERT_OK(zc_shm_client_list_add_client(z_loan_mut(list), 100500, z_move(client)));
ASSERT_CHECK_ERR(client);

// create client storage from the list
Expand Down

0 comments on commit 9d8ded6

Please sign in to comment.