Skip to content

Commit

Permalink
Merge commit '78a078d8b2a5268064360d7783a066b1b775c75b'
Browse files Browse the repository at this point in the history
Conflicts:
	include/zenoh_commons.h
	include/zenoh_macros.h
  • Loading branch information
yellowhatter committed May 25, 2024
2 parents 5e1941e + 78a078d commit 453f58a
Show file tree
Hide file tree
Showing 35 changed files with 820 additions and 301 deletions.
8 changes: 4 additions & 4 deletions build-resources/opaque-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ get_opaque_type_data!(Option<HashMap<usize, usize>>, z_owned_slice_map_t);
/// A loaned slice map.
get_opaque_type_data!(HashMap<usize, usize>, z_loaned_slice_map_t);

/// An array of maybe-owned slices.
/// An array of maybe-owned non-null terminated strings.
///
get_opaque_type_data!(Option<Vec<CSlice>>, z_owned_slice_array_t);
/// A loaned slice array.
get_opaque_type_data!(Vec<CSlice>, z_loaned_slice_array_t);
get_opaque_type_data!(Option<Vec<CSlice>>, z_owned_str_array_t);
/// A loaned string array.
get_opaque_type_data!(Vec<CSlice>, z_loaned_str_array_t);

/// An owned Zenoh sample.
///
Expand Down
15 changes: 11 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fs2::FileExt;
use regex::Regex;
use std::collections::HashSet;
use std::env;
use std::io::{Read, Write};
use std::process::{Command, Stdio};
Expand Down Expand Up @@ -880,7 +881,7 @@ 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(&type_name_to_loan_func);
let out = generate_generic_loan_to_owned_type_cpp(&vec![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 @@ -1071,7 +1072,7 @@ pub fn generate_generic_check_c(macro_func: &[FunctionSignature]) -> String {
}

pub fn generate_generic_call_c(macro_func: &[FunctionSignature]) -> String {
generate_generic_c(macro_func, "z_call", true)
generate_generic_c(macro_func, "z_call", false)
}

pub fn generate_generic_closure_c(_macro_func: &[FunctionSignature]) -> String {
Expand Down Expand Up @@ -1126,11 +1127,17 @@ pub fn generate_generic_loan_cpp(macro_func: &[FunctionSignature]) -> String {
}

pub fn generate_generic_loan_to_owned_type_cpp(macro_func: &[FunctionSignature]) -> String {
let mut processed_loaned_types = HashSet::<String>::new();
let mut out = "template<class T> struct z_loaned_to_owned_type_t {};
template<class T> struct z_owned_to_loaned_type_t {};"
.to_owned();
for f in macro_func {
let loaned = f.return_type.clone().without_cv().without_ptr().typename;
if processed_loaned_types.contains(&loaned) {
continue;
} else {
processed_loaned_types.insert(loaned.clone());
}
let owned = f.args[0]
.typename
.clone()
Expand Down Expand Up @@ -1178,7 +1185,7 @@ pub fn generate_generic_check_cpp(macro_func: &[FunctionSignature]) -> String {
}

pub fn generate_generic_call_cpp(macro_func: &[FunctionSignature]) -> String {
generate_generic_cpp(macro_func, "z_call", true)
generate_generic_cpp(macro_func, "z_call", false)
}

pub fn generate_generic_closure_cpp(macro_func: &[FunctionSignature]) -> String {
Expand All @@ -1187,7 +1194,7 @@ 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;
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
28 changes: 16 additions & 12 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,25 @@ Functions
.. doxygenfunction:: z_slice_map_insert_by_copy
.. doxygenfunction:: z_slice_map_iterate

Slice array
string array
-----------
Types
^^^^^
.. doxygenstruct:: z_owned_slice_array_t
.. doxygenstruct:: z_loaned_slice_array_t
.. doxygenstruct:: z_owned_str_array_t
.. doxygenstruct:: z_loaned_str_array_t

Functions
^^^^^^^^^
.. doxygenfunction:: z_slice_array_check
.. doxygenfunction:: z_slice_array_null
.. doxygenfunction:: z_slice_array_drop
.. doxygenfunction:: z_slice_array_loan
.. doxygenfunction:: z_slice_array_loan_mut
.. doxygenfunction:: z_str_array_check
.. doxygenfunction:: z_str_array_null
.. doxygenfunction:: z_str_array_drop
.. doxygenfunction:: z_str_array_loan
.. doxygenfunction:: z_str_array_loan_mut

.. doxygenfunction:: z_slice_array_new
.. doxygenfunction:: z_slice_array_get
.. doxygenfunction:: z_slice_array_len
.. doxygenfunction:: z_slice_array_is_empty
.. doxygenfunction:: z_str_array_new
.. doxygenfunction:: z_str_array_get
.. doxygenfunction:: z_str_array_len
.. doxygenfunction:: z_str_array_is_empty

Common
======
Expand Down Expand Up @@ -529,6 +529,8 @@ Types
:members:
.. doxygenstruct:: z_query_reply_options_t
:members:
.. doxygenstruct:: z_query_reply_err_options_t
:members:

.. doxygenstruct:: z_owned_query_channel_t
:members:
Expand All @@ -542,6 +544,7 @@ Functions

.. doxygenfunction:: z_queryable_options_default
.. doxygenfunction:: z_query_reply_options_default
.. doxygenfunction:: z_query_reply_err_options_default

.. doxygenfunction:: z_queryable_null
.. doxygenfunction:: z_queryable_check
Expand All @@ -559,6 +562,7 @@ Functions
.. doxygenfunction:: z_query_value
.. doxygenfunction:: z_query_attachment
.. doxygenfunction:: z_query_reply
.. doxygenfunction:: z_query_reply_err

.. doxygenfunction:: z_closure_query_null
.. doxygenfunction:: z_closure_query_check
Expand Down
2 changes: 1 addition & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Query
z_get(z_loan(s), z_loan(key_expr), "", z_move(channel.send), NULL);
z_owned_reply_t reply;
for (z_call(channel.recv, &reply); z_check(reply); z_call(channel.recv, &reply)) {
for (z_call(z_loan(channel.recv), &reply); z_check(reply); z_call(z_loan(channel.recv), &reply)) {
if (z_reply_is_ok(&reply)) {
const z_loaned_sample_t* sample = z_reply_ok(&reply);
z_view_str_t key_string;
Expand Down
2 changes: 1 addition & 1 deletion examples/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main(int argc, char **argv) {
z_move(opts)); // here, the send is moved and will be dropped by zenoh when adequate
z_owned_reply_t reply;

for (z_call(channel.recv, &reply); z_check(reply); z_call(channel.recv, &reply)) {
for (z_call(z_loan(channel.recv), &reply); z_check(reply); z_call(z_loan(channel.recv), &reply)) {
if (z_reply_is_ok(z_loan(reply))) {
const z_loaned_sample_t* sample = z_reply_ok(z_loan(reply));

Expand Down
2 changes: 1 addition & 1 deletion examples/z_get_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char **argv) {
zc_reply_fifo_new(&channel, 16);
zc_liveliness_get(z_loan(s), z_loan(keyexpr), z_move(channel.send), NULL);
z_owned_reply_t reply;
for (z_call(channel.recv, &reply); z_check(reply); z_call(channel.recv, &reply)) {
for (z_call(z_loan(channel.recv), &reply); z_check(reply); z_call(z_loan(channel.recv), &reply)) {
if (z_reply_is_ok(z_loan(reply))) {
const z_loaned_sample_t* sample = z_reply_ok(z_loan(reply));
z_view_str_t key_str;
Expand Down
4 changes: 2 additions & 2 deletions examples/z_non_blocking_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ int main(int argc, char **argv) {
z_get(z_loan(s), z_loan(keyexpr), "", z_move(channel.send),
z_move(opts)); // here, the send is moved and will be dropped by zenoh when adequate
z_owned_reply_t reply;
for (bool call_success = z_call(channel.recv, &reply); !call_success || z_check(reply);
call_success = z_call(channel.recv, &reply)) {
for (bool call_success = z_call(z_loan(channel.recv), &reply); !call_success || z_check(reply);
call_success = z_call(z_loan(channel.recv), &reply)) {
if (!call_success) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/z_queryable_with_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void query_handler(const z_loaned_query_t *query, void *context) {
z_owned_closure_owned_query_t *channel = (z_owned_closure_owned_query_t *)context;
z_owned_query_t oquery;
z_query_clone(query, &oquery);
z_call(*channel, &oquery);
z_call(z_loan(*channel), &oquery);
}

int main(int argc, char **argv) {
Expand Down Expand Up @@ -69,7 +69,7 @@ int main(int argc, char **argv) {

printf("^C to quit...\n");
z_owned_query_t oquery;
for (z_call(channel.recv, &oquery); z_check(oquery); z_call(channel.recv, &oquery)) {
for (z_call(z_loan(channel.recv), &oquery); z_check(oquery); z_call(z_loan(channel.recv), &oquery)) {
const z_loaned_query_t* query = z_loan(oquery);
z_view_str_t key_string;
z_keyexpr_to_string(z_query_keyexpr(query), &key_string);
Expand Down
14 changes: 7 additions & 7 deletions examples/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ void fprintwhatami(FILE *stream, z_whatami_t whatami) {
fprintf(stream, "%.*s", (int)z_str_len(z_loan(whatami_str)), z_str_data(z_loan(whatami_str)));
}

void fprintlocators(FILE *stream, const z_loaned_slice_array_t *locs) {
void fprintlocators(FILE *stream, const z_loaned_str_array_t *locs) {
fprintf(stream, "[");
for (unsigned int i = 0; i < z_slice_array_len(locs); i++) {
for (unsigned int i = 0; i < z_str_array_len(locs); i++) {
fprintf(stream, "\"");
const z_loaned_slice_t *loc = z_slice_array_get(locs, i);
fprintf(stream, "%.*s", (int)z_slice_len(loc), (const char*)z_slice_data(loc));
const z_loaned_str_t *loc = z_str_array_get(locs, i);
fprintf(stream, "%.*s", (int)z_str_len(loc), z_str_data(loc));
fprintf(stream, "\"");
if (i < z_slice_array_len(locs) - 1) {
if (i < z_str_array_len(locs) - 1) {
fprintf(stream, ", ");
}
}
Expand All @@ -59,10 +59,10 @@ void fprinthello(FILE *stream, const z_loaned_hello_t* hello) {
fprintwhatami(stream, z_hello_whatami(hello));

fprintf(stream, ", locators: ");
z_owned_slice_array_t locators;
z_owned_str_array_t locators;
z_hello_locators(hello, &locators);
fprintlocators(stream, z_loan(locators));
z_slice_array_drop(z_move(locators));
z_str_array_drop(z_move(locators));

fprintf(stream, " }");
}
Expand Down
Loading

0 comments on commit 453f58a

Please sign in to comment.