Skip to content

Commit

Permalink
Merge commit '9561b6e97898e58dabc8ffea438a0283f6e5adbc'
Browse files Browse the repository at this point in the history
Conflicts:
	src/payload.rs
	src/session.rs
  • Loading branch information
yellowhatter committed May 28, 2024
2 parents 1f99ad7 + 9561b6e commit 70eff89
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 90 deletions.
11 changes: 9 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,9 @@ pub fn create_generics_header(path_in: &str, path_out: &str) {
file_out.write_all(out.as_bytes()).unwrap();

file_out.write_all("\n\n".as_bytes()).unwrap();
let out = generate_generic_loan_to_owned_type_cpp(&vec![type_name_to_loan_func, type_name_to_loan_mut_func].concat());
let out = generate_generic_loan_to_owned_type_cpp(
&[type_name_to_loan_func, type_name_to_loan_mut_func].concat(),
);
file_out.write_all(out.as_bytes()).unwrap();

file_out
Expand Down Expand Up @@ -1194,7 +1196,12 @@ pub fn generate_generic_closure_cpp(macro_func: &[FunctionSignature]) -> String
for func in macro_func {
let return_type = &func.return_type.typename;
let closure_name = &func.args[0].name;
let closure_type = func.args[0].typename.clone().without_cv().typename.replace("loaned", "owned");
let closure_type = func.args[0]
.typename
.clone()
.without_cv()
.typename
.replace("loaned", "owned");
let arg_type = &func.args[1].typename.typename;
out += "\n";
out += &format!(
Expand Down
16 changes: 8 additions & 8 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,7 @@ ZENOHC_API void z_put_options_default(struct z_put_options_t *this_);
*
* Returns NULL if query does not contain an attachment.
*/
ZENOHC_API const struct z_loaned_bytes_t *z_query_attachment(const struct z_loaned_query_t *query);
ZENOHC_API const struct z_loaned_bytes_t *z_query_attachment(const struct z_loaned_query_t *this_);
/**
* Returns ``true`` if channel is valid, ``false`` if it is in gravestone state.
*/
Expand Down Expand Up @@ -2514,7 +2514,7 @@ ZENOHC_API void z_query_drop(struct z_owned_query_t *this_);
/**
* Gets query key expression.
*/
ZENOHC_API const struct z_loaned_keyexpr_t *z_query_keyexpr(const struct z_loaned_query_t *query);
ZENOHC_API const struct z_loaned_keyexpr_t *z_query_keyexpr(const struct z_loaned_query_t *this_);
/**
* Borrows the query.
*/
Expand All @@ -2527,7 +2527,7 @@ ZENOHC_API void z_query_null(struct z_owned_query_t *this_);
* Gets query <a href="https://github.com/eclipse-zenoh/roadmap/tree/main/rfcs/ALL/Selectors">value selector</a>.
*/
ZENOHC_API
void z_query_parameters(const struct z_loaned_query_t *query,
void z_query_parameters(const struct z_loaned_query_t *this_,
struct z_view_str_t *parameters);
/**
* Sends a reply to a query.
Expand All @@ -2537,15 +2537,15 @@ void z_query_parameters(const struct z_loaned_query_t *query,
* be called multiple times to send multiple replies to a query. The reply
* will be considered complete when the Queryable callback returns.
*
* @param query: The query to reply to.
* @param this_: The query to reply to.
* @param key_expr: The key of this reply.
* @param payload: The payload of this reply. Will be consumed.
* @param options: The options of this reply. All owned fields will be consumed.
*
* @return 0 in case of success, negative error code otherwise.
*/
ZENOHC_API
z_error_t z_query_reply(const struct z_loaned_query_t *query,
z_error_t z_query_reply(const struct z_loaned_query_t *this_,
const struct z_loaned_keyexpr_t *key_expr,
struct z_owned_bytes_t *payload,
struct z_query_reply_options_t *options);
Expand All @@ -2557,14 +2557,14 @@ z_error_t z_query_reply(const struct z_loaned_query_t *query,
* be called multiple times to send multiple replies to a query. The reply
* will be considered complete when the Queryable callback returns.
*
* @param query: The query to reply to.
* @param this_: The query to reply to.
* @param payload: The payload carrying error message. Will be consumed.
* @param options: The options of this reply. All owned fields will be consumed.
*
* @return 0 in case of success, negative error code otherwise.
*/
ZENOHC_API
z_error_t z_query_reply_err(const struct z_loaned_query_t *query,
z_error_t z_query_reply_err(const struct z_loaned_query_t *this_,
struct z_owned_bytes_t *payload,
struct z_query_reply_err_options_t *options);
/**
Expand All @@ -2585,7 +2585,7 @@ ZENOHC_API enum z_query_target_t z_query_target_default(void);
* Returns NULL if query does not contain a value.
*/
ZENOHC_API
const struct z_loaned_value_t *z_query_value(const struct z_loaned_query_t *query);
const struct z_loaned_value_t *z_query_value(const struct z_loaned_query_t *this_);
/**
* Returns ``true`` if queryable is valid, ``false`` otherwise.
*/
Expand Down
11 changes: 8 additions & 3 deletions src/closures/hello_closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::mem::MaybeUninit;

use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_loaned_hello_t};
use crate::{
transmute::{TransmuteFromHandle, TransmuteIntoHandle},
z_loaned_hello_t,
};
use libc::c_void;

/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
Expand Down Expand Up @@ -106,6 +109,8 @@ pub extern "C" fn z_closure_hello_check(this: &z_owned_closure_hello_t) -> bool

/// Borrows closure.
#[no_mangle]
pub extern "C" fn z_closure_hello_loan(closure: &z_owned_closure_hello_t) -> &z_loaned_closure_hello_t {
pub extern "C" fn z_closure_hello_loan(
closure: &z_owned_closure_hello_t,
) -> &z_loaned_closure_hello_t {
closure.transmute_handle()
}
}
14 changes: 11 additions & 3 deletions src/closures/matching_status_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::mem::MaybeUninit;

use libc::c_void;

use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, zcu_matching_status_t};
use crate::{
transmute::{TransmuteFromHandle, TransmuteIntoHandle},
zcu_matching_status_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.
Expand All @@ -27,7 +30,10 @@ pub struct zcu_loaned_closure_matching_status_t {
_0: [usize; 3],
}

decl_transmute_handle!(zcu_owned_closure_matching_status_t, zcu_loaned_closure_matching_status_t);
decl_transmute_handle!(
zcu_owned_closure_matching_status_t,
zcu_loaned_closure_matching_status_t
);

impl zcu_owned_closure_matching_status_t {
pub fn empty() -> Self {
Expand Down Expand Up @@ -112,6 +118,8 @@ impl<F: Fn(&zcu_matching_status_t)> From<F> for zcu_owned_closure_matching_statu

/// Borrows closure.
#[no_mangle]
pub extern "C" fn zcu_closure_matching_status_loan(closure: &zcu_owned_closure_matching_status_t) -> &zcu_loaned_closure_matching_status_t {
pub extern "C" fn zcu_closure_matching_status_loan(
closure: &zcu_owned_closure_matching_status_t,
) -> &zcu_loaned_closure_matching_status_t {
closure.transmute_handle()
}
15 changes: 11 additions & 4 deletions src/closures/query_channel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_closure_query_drop, z_loaned_query_t, z_owned_closure_query_t, z_owned_query_t, z_query_clone, z_query_null
transmute::{TransmuteFromHandle, TransmuteIntoHandle},
z_closure_query_drop, z_loaned_query_t, z_owned_closure_query_t, z_owned_query_t,
z_query_clone, z_query_null,
};
use libc::c_void;
use std::{
Expand Down Expand Up @@ -33,7 +35,10 @@ pub struct z_loaned_query_channel_closure_t {
_0: [usize; 3],
}

decl_transmute_handle!(z_owned_query_channel_closure_t, z_loaned_query_channel_closure_t);
decl_transmute_handle!(
z_owned_query_channel_closure_t,
z_loaned_query_channel_closure_t
);

/// A pair of send / receive ends of channel.
#[repr(C)]
Expand Down Expand Up @@ -246,6 +251,8 @@ impl<F: Fn(*mut MaybeUninit<z_owned_query_t>) -> bool> From<F> for z_owned_query

/// Borrows closure.
#[no_mangle]
pub extern "C" fn z_query_channel_closure_loan(closure: &z_owned_query_channel_closure_t) -> &z_loaned_query_channel_closure_t {
pub extern "C" fn z_query_channel_closure_loan(
closure: &z_owned_query_channel_closure_t,
) -> &z_loaned_query_channel_closure_t {
closure.transmute_handle()
}
}
21 changes: 15 additions & 6 deletions src/closures/query_closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::mem::MaybeUninit;

use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_loaned_query_t, z_owned_query_t};
use crate::{
transmute::{TransmuteFromHandle, TransmuteIntoHandle},
z_loaned_query_t, z_owned_query_t,
};
use libc::c_void;
/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks:
///
Expand Down Expand Up @@ -126,7 +129,10 @@ pub struct z_owned_closure_owned_query_t {
pub struct z_loaned_closure_owned_query_t {
_0: [usize; 3],
}
decl_transmute_handle!(z_owned_closure_owned_query_t, z_loaned_closure_owned_query_t);
decl_transmute_handle!(
z_owned_closure_owned_query_t,
z_loaned_closure_owned_query_t
);

impl z_owned_closure_owned_query_t {
pub fn empty() -> Self {
Expand Down Expand Up @@ -189,15 +195,18 @@ impl<F: Fn(&mut z_owned_query_t)> From<F> for z_owned_closure_owned_query_t {
}
}


/// Borrows closure.
#[no_mangle]
pub extern "C" fn z_closure_query_loan(closure: &z_owned_closure_query_t) -> &z_loaned_closure_query_t {
pub extern "C" fn z_closure_query_loan(
closure: &z_owned_closure_query_t,
) -> &z_loaned_closure_query_t {
closure.transmute_handle()
}

/// Borrows closure.
#[no_mangle]
pub extern "C" fn z_closure_owned_query_loan(closure: &z_owned_closure_owned_query_t) -> &z_loaned_closure_owned_query_t {
pub extern "C" fn z_closure_owned_query_loan(
closure: &z_owned_closure_owned_query_t,
) -> &z_loaned_closure_owned_query_t {
closure.transmute_handle()
}
}
12 changes: 8 additions & 4 deletions src/closures/reply_closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::mem::MaybeUninit;

use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_loaned_reply_t};
use crate::{
transmute::{TransmuteFromHandle, TransmuteIntoHandle},
z_loaned_reply_t,
};
use libc::c_void;
/// A structure that contains all the elements for stateful, memory-leak-free callbacks.
///
Expand Down Expand Up @@ -102,9 +105,10 @@ impl<F: Fn(&z_loaned_reply_t)> From<F> for z_owned_closure_reply_t {
}
}


/// Borrows closure.
#[no_mangle]
pub extern "C" fn z_closure_reply_loan(closure: &z_owned_closure_reply_t) -> &z_loaned_closure_reply_t {
pub extern "C" fn z_closure_reply_loan(
closure: &z_owned_closure_reply_t,
) -> &z_loaned_closure_reply_t {
closure.transmute_handle()
}
}
15 changes: 11 additions & 4 deletions src/closures/response_channel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_closure_reply_drop, z_loaned_reply_t, z_owned_closure_reply_t, z_owned_reply_t, z_reply_clone, z_reply_null
transmute::{TransmuteFromHandle, TransmuteIntoHandle},
z_closure_reply_drop, z_loaned_reply_t, z_owned_closure_reply_t, z_owned_reply_t,
z_reply_clone, z_reply_null,
};
use libc::c_void;
use std::{
Expand Down Expand Up @@ -31,7 +33,10 @@ pub struct z_owned_reply_channel_closure_t {
pub struct z_loaned_reply_channel_closure_t {
_0: [usize; 3],
}
decl_transmute_handle!(z_owned_reply_channel_closure_t, z_loaned_reply_channel_closure_t);
decl_transmute_handle!(
z_owned_reply_channel_closure_t,
z_loaned_reply_channel_closure_t
);

/// A pair of send / receive ends of channel.
#[repr(C)]
Expand Down Expand Up @@ -245,6 +250,8 @@ impl<F: Fn(*mut MaybeUninit<z_owned_reply_t>) -> bool> From<F> for z_owned_reply

/// Borrows closure.
#[no_mangle]
pub extern "C" fn z_reply_channel_closure_loan(closure: &z_owned_reply_channel_closure_t) -> &z_loaned_reply_channel_closure_t {
pub extern "C" fn z_reply_channel_closure_loan(
closure: &z_owned_reply_channel_closure_t,
) -> &z_loaned_reply_channel_closure_t {
closure.transmute_handle()
}
}
9 changes: 7 additions & 2 deletions src/closures/sample_closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::mem::MaybeUninit;

use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_loaned_sample_t};
use crate::{
transmute::{TransmuteFromHandle, TransmuteIntoHandle},
z_loaned_sample_t,
};
use libc::c_void;
/// A closure is a structure that contains all the elements for stateful, memory-leak-free callbacks.
///
Expand Down Expand Up @@ -104,6 +107,8 @@ impl<F: Fn(&z_loaned_sample_t)> From<F> for z_owned_closure_sample_t {

/// Borrows closure.
#[no_mangle]
pub extern "C" fn z_closure_sample_loan(closure: &z_owned_closure_sample_t) -> &z_loaned_closure_sample_t {
pub extern "C" fn z_closure_sample_loan(
closure: &z_owned_closure_sample_t,
) -> &z_loaned_closure_sample_t {
closure.transmute_handle()
}
5 changes: 4 additions & 1 deletion src/closures/zenohid_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::mem::MaybeUninit;

use libc::c_void;

use crate::{transmute::{TransmuteFromHandle, TransmuteIntoHandle}, z_id_t};
use crate::{
transmute::{TransmuteFromHandle, TransmuteIntoHandle},
z_id_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.
Expand Down
7 changes: 4 additions & 3 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::z_query_target_t;
use crate::{
z_closure_reply_call, z_loaned_keyexpr_t, z_loaned_session_t, z_owned_closure_reply_t,
};
use::zenoh::core::Wait;
use ::zenoh::core::Wait;

pub use crate::opaque_types::z_owned_reply_t;
decl_transmute_owned!(Option<Reply>, z_owned_reply_t);
Expand Down Expand Up @@ -175,8 +175,9 @@ pub unsafe extern "C" fn z_get(
}
}
match get
.callback(move |response|
z_closure_reply_call(z_closure_reply_loan(&closure), response.transmute_handle()))
.callback(move |response| {
z_closure_reply_call(z_closure_reply_loan(&closure), response.transmute_handle())
})
.wait()
{
Ok(()) => errors::Z_OK,
Expand Down
6 changes: 4 additions & 2 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
// ZettaScale Zenoh team, <[email protected]>
//
use crate::transmute::{TransmuteCopy, TransmuteFromHandle};
use crate::{errors, z_closure_zid_call, z_closure_zid_loan, z_loaned_session_t, z_owned_closure_zid_t};
use crate::{
errors, z_closure_zid_call, z_closure_zid_loan, z_loaned_session_t, z_owned_closure_zid_t,
};
use std::mem::MaybeUninit;
use zenoh::config::ZenohId;
use zenoh::session::SessionDeclarations;
use zenoh::core::Wait;
use zenoh::session::SessionDeclarations;

pub use crate::opaque_types::z_id_t;
decl_transmute_copy!(ZenohId, z_id_t);
Expand Down
2 changes: 1 addition & 1 deletion src/keyexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ use crate::z_view_str_from_substring;
use crate::z_view_str_t;
use libc::c_char;
use std::error::Error;
use zenoh::core::Wait;
use zenoh::key_expr::SetIntersectionLevel;
use zenoh::prelude::keyexpr;
use zenoh::prelude::KeyExpr;
use zenoh_protocol::core::key_expr::canon::Canonizable;
use zenoh::core::Wait;

pub use crate::opaque_types::z_owned_keyexpr_t;
pub use crate::opaque_types::z_view_keyexpr_t;
Expand Down
Loading

0 comments on commit 70eff89

Please sign in to comment.