Skip to content

Commit

Permalink
option added to some decl_c_type
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Jul 3, 2024
1 parent 2755e80 commit 9be5468
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 40 deletions.
2 changes: 1 addition & 1 deletion include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -4007,7 +4007,7 @@ void zc_session_clone(const struct z_loaned_session_t *this_,
#if (defined(SHARED_MEMORY) && defined(UNSTABLE))
ZENOHC_API
z_error_t zc_shm_client_list_add_client(z_protocol_id_t id,
struct z_owned_shm_client_t *client,
struct z_moved_shm_client_t client,
struct zc_loaned_shm_client_list_t *list);
#endif
/**
Expand Down
18 changes: 6 additions & 12 deletions src/closures/response_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ pub use crate::opaque_types::z_loaned_fifo_handler_reply_t;
pub use crate::opaque_types::z_moved_fifo_handler_reply_t;
pub use crate::opaque_types::z_owned_fifo_handler_reply_t;
decl_c_type!(
owned(
z_owned_fifo_handler_reply_t,
Option<flume::Receiver<Reply>>,
),
loaned(z_loaned_fifo_handler_reply_t, flume::Receiver<Reply>),
moved(z_moved_fifo_handler_reply_t)
owned(z_owned_fifo_handler_reply_t, option flume::Receiver<Reply>),
loaned(z_loaned_fifo_handler_reply_t),
moved(z_moved_fifo_handler_reply_t)
);

/// Drops the handler and resets it to a gravestone state.
Expand Down Expand Up @@ -145,12 +142,9 @@ pub use crate::opaque_types::z_loaned_ring_handler_reply_t;
pub use crate::opaque_types::z_moved_ring_handler_reply_t;
pub use crate::opaque_types::z_owned_ring_handler_reply_t;
decl_c_type!(
owned(
z_owned_ring_handler_reply_t,
Option<RingChannelHandler<Reply>>,
),
loaned(z_loaned_ring_handler_reply_t, RingChannelHandler<Reply>),
moved(z_moved_ring_handler_reply_t)
owned(z_owned_ring_handler_reply_t, option RingChannelHandler<Reply>),
loaned(z_loaned_ring_handler_reply_t),
moved(z_moved_ring_handler_reply_t)
);

/// Drops the handler and resets it to a gravestone state.
Expand Down
40 changes: 16 additions & 24 deletions src/shm/client_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@
use super::common::types::z_protocol_id_t;
use crate::{
errors::{z_error_t, Z_EINVAL, Z_OK},
transmute::{LoanedCTypeRef, RustTypeRef, RustTypeRefUninit},
z_loaned_shm_client_storage_t, z_moved_shm_client_storage_t, z_owned_shm_client_storage_t,
z_owned_shm_client_t, zc_loaned_shm_client_list_t, zc_moved_shm_client_list_t,
zc_owned_shm_client_list_t,
transmute::{IntoRustType, LoanedCTypeRef, RustTypeRef, RustTypeRefUninit},
z_loaned_shm_client_storage_t, z_moved_shm_client_storage_t, z_moved_shm_client_t,
z_owned_shm_client_storage_t, z_owned_shm_client_t, zc_loaned_shm_client_list_t,
zc_moved_shm_client_list_t, zc_owned_shm_client_list_t,
};
use std::{mem::MaybeUninit, sync::Arc};
use zenoh::shm::{ProtocolID, ShmClient, ShmClientStorage, GLOBAL_CLIENT_STORAGE};

decl_c_type!(
owned(
zc_owned_shm_client_list_t,
Option<Vec<(ProtocolID, Arc<dyn ShmClient>)>>,
),
loaned(zc_loaned_shm_client_list_t, Vec<(ProtocolID, Arc<dyn ShmClient>)>),
moved(zc_moved_shm_client_list_t)
owned(zc_owned_shm_client_list_t, option Vec<(ProtocolID, Arc<dyn ShmClient>)>),
loaned(zc_loaned_shm_client_list_t),
moved(zc_moved_shm_client_list_t)
);

/// Creates a new empty list of SHM Clients
Expand Down Expand Up @@ -86,25 +83,20 @@ pub unsafe extern "C" fn zc_shm_client_list_loan_mut(
#[no_mangle]
pub extern "C" fn zc_shm_client_list_add_client(
id: z_protocol_id_t,
client: &mut z_owned_shm_client_t,
client: z_moved_shm_client_t,
list: &mut zc_loaned_shm_client_list_t,
) -> z_error_t {
match client.as_rust_type_mut().take() {
Some(client) => {
list.as_rust_type_mut().push((id, client));
Z_OK
}
None => Z_EINVAL,
}
let Some(client) = client.into_rust_type() else {
return Z_EINVAL;
};
list.as_rust_type_mut().push((id, client));
Z_OK
}

decl_c_type!(
owned(
z_owned_shm_client_storage_t,
Option<Arc<ShmClientStorage>>,
),
loaned(z_loaned_shm_client_storage_t, Arc<ShmClientStorage>),
moved(z_moved_shm_client_storage_t)
owned(z_owned_shm_client_storage_t, option Arc<ShmClientStorage> ),
loaned(z_loaned_shm_client_storage_t),
moved(z_moved_shm_client_storage_t)
);

#[no_mangle]
Expand Down
6 changes: 3 additions & 3 deletions src/shm/provider/shm_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ pub enum CSHMProvider {
}

decl_c_type!(
owned(z_owned_shm_provider_t, Option<CSHMProvider>),
loaned(z_loaned_shm_provider_t, CSHMProvider),
moved(z_moved_shm_provider_t)
owned(z_owned_shm_provider_t, option CSHMProvider),
loaned(z_loaned_shm_provider_t),
moved(z_moved_shm_provider_t)
);

/// Creates a new SHM Provider
Expand Down

0 comments on commit 9be5468

Please sign in to comment.