From a2df4b14dab8e08718fa38e0d95bebb6eca59f21 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 10 Sep 2024 19:13:29 +0200 Subject: [PATCH] remove z_config_client and z_config_peer --- docs/api.rst | 2 -- include/zenoh_commons.h | 16 ------------ src/config.rs | 55 ++------------------------------------- tests/z_api_config_test.c | 20 ++++++-------- 4 files changed, 10 insertions(+), 83 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index fd2b72f44..4cc00ab8e 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -447,8 +447,6 @@ Functions .. doxygenfunction:: z_config_drop .. doxygenfunction:: z_config_default -.. doxygenfunction:: z_config_client -.. doxygenfunction:: z_config_peer .. doxygenfunction:: zc_config_from_env .. doxygenfunction:: zc_config_from_file .. doxygenfunction:: zc_config_from_str diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 1f59bfa0a..a603984ac 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -1964,18 +1964,6 @@ ZENOHC_API z_result_t z_condvar_signal(const struct z_loaned_condvar_t *this_); ZENOHC_API z_result_t z_condvar_wait(const struct z_loaned_condvar_t *this_, struct z_loaned_mutex_t *m); -/** - * Constructs a default, zenoh-allocated, client mode configuration. - * - * @param peers: Array with `size >= n_peers`, containing peer locators to add to the config. - * @param n_peers: Number of peers to add to the config. - * - * @return 0 in case of success, negative error code otherwise. - */ -ZENOHC_API -z_result_t z_config_client(struct z_owned_config_t *this_, - const char *const *peers, - size_t n_peers); /** * Clones the config into provided uninitialized memory location. */ @@ -1996,10 +1984,6 @@ ZENOHC_API const struct z_loaned_config_t *z_config_loan(const struct z_owned_co * Mutably borrows config. */ ZENOHC_API struct z_loaned_config_t *z_config_loan_mut(struct z_owned_config_t *this_); -/** - * Constructs a default peer mode configuration. - */ -ZENOHC_API z_result_t z_config_peer(struct z_owned_config_t *this_); /** * Constructs and declares a key expression on the network. This reduces key key expression to a numerical id, * which allows to save the bandwith, when passing key expression between Zenoh entities. diff --git a/src/config.rs b/src/config.rs index a4d5d4a60..5cbc5e2d8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,10 +14,10 @@ use std::{ffi::CStr, mem::MaybeUninit, slice::from_raw_parts, str::from_utf8}; use libc::{c_char, c_uint}; -use zenoh::config::{Config, Locator, ValidatedMap, WhatAmI}; +use zenoh::config::{Config, ValidatedMap, WhatAmI}; use crate::{ - result::{self, z_result_t, Z_OK}, + result::{self, Z_OK}, transmute::{LoanedCTypeRef, RustTypeRef, RustTypeRefUninit, TakeRustType}, z_internal_string_null, z_owned_string_t, z_string_copy_from_substr, }; @@ -336,54 +336,3 @@ pub unsafe extern "C" fn zc_config_from_env( } } } - -/// Constructs a default peer mode configuration. -#[allow(clippy::missing_safety_doc)] -#[no_mangle] -pub extern "C" fn z_config_peer(this_: &mut MaybeUninit) -> result::z_result_t { - this_ - .as_rust_type_mut_uninit() - .write(Some(zenoh::config::peer())); - Z_OK -} - -/// Constructs a default, zenoh-allocated, client mode configuration. -/// -/// @param peers: Array with `size >= n_peers`, containing peer locators to add to the config. -/// @param n_peers: Number of peers to add to the config. -/// -/// @return 0 in case of success, negative error code otherwise. -#[allow(clippy::missing_safety_doc)] -#[no_mangle] -pub unsafe extern "C" fn z_config_client( - this: &mut MaybeUninit, - peers: *const *const c_char, - n_peers: usize, -) -> z_result_t { - let mut res = result::Z_OK; - let locators = if peers.is_null() { - Vec::new() - } else if let Ok(locators) = std::slice::from_raw_parts(peers, n_peers) - .iter() - .map(|&s| CStr::from_ptr(s).to_string_lossy().parse()) - .try_fold(Vec::::new(), |mut acc, it| match it { - Err(e) => { - tracing::error!("Error parsing peer address: {}", e); - res = result::Z_EPARSE; - Err(()) - } - Ok(loc) => { - acc.push(loc); - Ok(acc) - } - }) - { - locators - } else { - z_internal_config_null(this); - return res; - }; - this.as_rust_type_mut_uninit() - .write(Some(zenoh::config::client(locators))); - res -} diff --git a/tests/z_api_config_test.c b/tests/z_api_config_test.c index 633a65de9..3d39c8546 100644 --- a/tests/z_api_config_test.c +++ b/tests/z_api_config_test.c @@ -18,29 +18,25 @@ #undef NDEBUG #include -void config_client() { - const char *peers[] = {"tcp/127.0.0.1", "tcp/192.168.0.1", "tcp/10.0.0.1"}; +void insert_get() { z_owned_config_t config; - z_config_client(&config, peers, 3); + z_config_default(&config); + zc_config_insert_json(z_loan_mut(config), "mode", "\"client\""); + zc_config_insert_json(z_loan_mut(config), "connect/endpoints", + "[\"tcp/127.0.0.1\", \"tcp/192.168.0.1\", \"tcp/10.0.0.1\"]"); z_owned_string_t endpoints; zc_config_get_from_str(z_loan(config), "connect/endpoints", &endpoints); assert(strncmp(z_string_data(z_loan(endpoints)), "[\"tcp/127.0.0.1\",\"tcp/192.168.0.1\",\"tcp/10.0.0.1\"]", z_string_len(z_loan(endpoints))) == 0); z_drop(z_move(endpoints)); - z_drop(z_move(config)); -} - -void config_peer() { - z_owned_config_t config; - z_config_peer(&config); z_owned_string_t mode; zc_config_get_from_str(z_loan(config), "mode", &mode); - assert(strncmp(z_string_data(z_loan(mode)), "\"peer\"", z_string_len(z_loan(mode))) == 0); + assert(strncmp(z_string_data(z_loan(mode)), "\"client\"", z_string_len(z_loan(mode))) == 0); z_drop(z_move(mode)); + z_drop(z_move(config)); } int main(int argc, char **argv) { zc_init_logging(); - config_client(); - config_peer(); + insert_get(); }