Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zc_config_from_env function #527

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ Functions
.. 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
.. doxygenfunction:: zc_config_insert_json
Expand Down
6 changes: 6 additions & 0 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -3548,6 +3548,12 @@ z_error_t z_view_string_wrap(struct z_view_string_t *this_,
ZENOHC_API
z_error_t z_whatami_to_view_string(enum z_whatami_t whatami,
struct z_view_string_t *str_out);
/**
* Constructs a configuration by parsing a file path stored in ZENOH_CONFIG environmental variable.
*
* Returns 0 in case of success, negative error code otherwise.
*/
ZENOHC_API z_error_t zc_config_from_env(struct z_owned_config_t *this_);
/**
* Constructs a configuration by parsing a file at `path`. Currently supported format is JSON5, a superset of JSON.
*
Expand Down
20 changes: 20 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,26 @@ pub unsafe extern "C" fn zc_config_from_file(
res
}

/// Constructs a configuration by parsing a file path stored in ZENOH_CONFIG environmental variable.
///
/// Returns 0 in case of success, negative error code otherwise.
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn zc_config_from_env(
this: &mut MaybeUninit<z_owned_config_t>,
) -> errors::z_error_t {
match Config::from_env() {
Ok(c) => {
this.as_rust_type_mut_uninit().write(Some(c));
errors::Z_OK
}
Err(e) => {
tracing::error!("{}", e);
errors::Z_EIO
}
}
}

/// Constructs a default peer mode configuration.
#[allow(clippy::missing_safety_doc)]
#[no_mangle]
Expand Down