From 135251bfc3a13dd1128458502ce59b5ff9c7d3a5 Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Mon, 15 Jan 2024 03:14:29 +0100 Subject: [PATCH] [#15] Use only one config file for every platform --- config/README.md | 2 +- config/iceoryx2.toml | 3 +- config/iceoryx2_win.toml | 26 ----------------- doc/release-notes/iceoryx2-unreleased.md | 2 +- iceoryx2/src/config.rs | 36 +++++++++++++++--------- iceoryx2/src/service/config_scheme.rs | 33 +++++++++++----------- 6 files changed, 44 insertions(+), 58 deletions(-) delete mode 100644 config/iceoryx2_win.toml diff --git a/config/README.md b/config/README.md index 6cb495777..098fc2eb9 100644 --- a/config/README.md +++ b/config/README.md @@ -18,7 +18,7 @@ Adjusting `global` settings ensures a non-interfering setup. ### Global - * `global.root_path` - [string]: Defines the path for all Iceoryx2 files and directories. + * `global.root_path_{unix|windows}` - [string]: Defines the path for all Iceoryx2 files and directories. * `global.prefix` - [string]: Prefix that is used for every file Iceoryx2 creates. * `global.service.directory` - [string]: Specifies the path for service-related files under `global.root_path`. * `global.service.publisher_data_segment_suffix` - [string]: Suffix added to the publisher's data segment. diff --git a/config/iceoryx2.toml b/config/iceoryx2.toml index 05fd5f3da..082c342b7 100644 --- a/config/iceoryx2.toml +++ b/config/iceoryx2.toml @@ -1,5 +1,6 @@ [global] -root_path = '/tmp/iceoryx2/' +root_path_unix = '/tmp/iceoryx2/' +root_path_windows = 'c:\Temp\iceoryx2\' prefix = 'iox2_' [global.service] diff --git a/config/iceoryx2_win.toml b/config/iceoryx2_win.toml deleted file mode 100644 index 7ca6af6a5..000000000 --- a/config/iceoryx2_win.toml +++ /dev/null @@ -1,26 +0,0 @@ -[global] -root_path = 'c:\Temp\iceoryx2\' -prefix = 'iox2_' - -[global.service] -directory = 'services' -publisher_data_segment_suffix = '.publisher_data' -static_config_storage_suffix = '.service' -dynamic_config_storage_suffix = '.dynamic' -connection_suffix = '.connection' -creation_timeout.secs = 0 -creation_timeout.nanos = 500000000 - -[defaults.publish_subscribe] -max_subscribers = 8 -max_publishers = 2 -publisher_history_size = 1 -subscriber_max_buffer_size = 2 -subscriber_max_borrowed_samples = 2 -publisher_max_loaned_samples = 2 -enable_safe_overflow = true -unable_to_deliver_strategy = 'block' # or 'discard_sample' - -[defaults.event] -max_listeners = 2 -max_notifiers = 16 diff --git a/doc/release-notes/iceoryx2-unreleased.md b/doc/release-notes/iceoryx2-unreleased.md index cbcf1cec8..2442d5f3e 100644 --- a/doc/release-notes/iceoryx2-unreleased.md +++ b/doc/release-notes/iceoryx2-unreleased.md @@ -21,7 +21,7 @@ - * Example text [#1](https://github.com/eclipse-iceoryx/iceoryx2/issues/1) + * Use only one config file for every platform [#15](https://github.com/eclipse-iceoryx/iceoryx2/issues/15) ### Workflow diff --git a/iceoryx2/src/config.rs b/iceoryx2/src/config.rs index 60c793f75..c5a8f3665 100644 --- a/iceoryx2/src/config.rs +++ b/iceoryx2/src/config.rs @@ -96,16 +96,11 @@ use iceoryx2_bb_system_types::path::Path; use serde::{Deserialize, Serialize}; use std::time::Duration; -use iceoryx2_bb_log::{fail, trace, warn}; +use iceoryx2_bb_log::{fail, fatal_panic, trace, warn}; use crate::service::port_factory::publisher::UnableToDeliverStrategy; /// Path to the default config file -#[cfg(target_os = "windows")] -pub const DEFAULT_CONFIG_FILE: &[u8] = b"config\\iceoryx2_win.toml"; - -/// Path to the default config file -#[cfg(not(target_os = "windows"))] pub const DEFAULT_CONFIG_FILE: &[u8] = b"config/iceoryx2.toml"; /// Failures occurring while creating a new [`Config`] object with [`Config::from_file()`] or @@ -148,8 +143,8 @@ pub struct Service { #[non_exhaustive] #[derive(Serialize, Deserialize, Default, Debug, Clone)] pub struct Global { - /// The path under which all other directories or files will be created - pub root_path: String, + root_path_unix: String, + root_path_windows: String, /// Prefix used for all files created during runtime pub prefix: String, /// [`crate::service::Service`] settings @@ -157,14 +152,31 @@ pub struct Global { } impl Global { + /// The absolute path to the service directory where all static service infos are stored pub fn get_absolute_service_dir(&self) -> Path { - let mut path = Path::new(self.root_path.as_bytes()).unwrap(); + let mut path = self.root_path(); path.add_path_entry( &FixedSizeByteString::from_bytes(self.service.directory.as_bytes()).unwrap(), ) .unwrap(); path } + + /// The path under which all other directories or files will be created + pub fn root_path(&self) -> Path { + #[cfg(target_os = "windows")] + { + fatal_panic!(from "Global::root_path_windows", + when Path::new(self.root_path_windows.as_bytes()), + "Unable to initialize config since the internal root_path_windows \"{}\" is not a valid directory.", self.root_path_windows) + } + #[cfg(not(target_os = "windows"))] + { + fatal_panic!(from "Global::root_path_unix", + when Path::new(self.root_path_unix.as_bytes()), + "Unable to initialize config since the internal root_path_unix \"{}\" is not a valid directory.", self.root_path_unix) + } + } } /// Default settings. These values are used when the user in the code does not specify anything @@ -238,11 +250,9 @@ impl Default for Config { fn default() -> Self { Self { global: Global { - #[cfg(not(target_os = "windows"))] - root_path: "/tmp/iceoryx2/".to_string(), + root_path_unix: "/tmp/iceoryx2/".to_string(), prefix: "iox2_".to_string(), - #[cfg(target_os = "windows")] - root_path: "C:\\Windows\\Temp\\iceoryx2\\".to_string(), + root_path_windows: "C:\\Windows\\Temp\\iceoryx2\\".to_string(), service: Service { directory: "services".to_string(), publisher_data_segment_suffix: ".publisher_data".to_string(), diff --git a/iceoryx2/src/service/config_scheme.rs b/iceoryx2/src/service/config_scheme.rs index 0d516ff05..095f461e6 100644 --- a/iceoryx2/src/service/config_scheme.rs +++ b/iceoryx2/src/service/config_scheme.rs @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT use crate::config; -use iceoryx2_bb_container::semantic_string::SemanticString; +use iceoryx2_bb_container::{byte_string::FixedSizeByteString, semantic_string::SemanticString}; use iceoryx2_bb_log::fatal_panic; use iceoryx2_bb_system_types::file_name::FileName; use iceoryx2_bb_system_types::path::Path; @@ -21,7 +21,7 @@ fn generate_default_config( origin: &str, prefix: &str, suffix: &str, - path_hint: &str, + path_hint: &Path, ) -> T { let prefix = match FileName::new(prefix.as_bytes()) { Err(_) => { @@ -39,18 +39,10 @@ fn generate_default_config( Ok(v) => v, }; - let path_hint = match Path::new(path_hint.as_bytes()) { - Err(_) => { - fatal_panic!(from origin, "The root_path \"{}\" provided by the config contains either invalid file name characters or is too long.", - path_hint); - } - Ok(v) => v, - }; - T::default() .prefix(prefix) .suffix(suffix) - .path_hint(path_hint) + .path_hint(*path_hint) } pub(crate) fn dynamic_config_storage_config<'config, Service: crate::service::Details<'config>>( @@ -60,15 +52,24 @@ pub(crate) fn dynamic_config_storage_config<'config, Service: crate::service::De "dynamic_config_storage_config", &global_config.global.prefix, &global_config.global.service.dynamic_config_storage_suffix, - &global_config.global.root_path, + &global_config.global.root_path(), ) } pub(crate) fn static_config_storage_config<'config, Service: crate::service::Details<'config>>( global_config: &config::Config, ) -> ::Configuration { - let mut path_hint = global_config.global.root_path.clone(); - path_hint.push_str(&global_config.global.service.directory); + let origin = "static_config_storage_config"; + let msg = "Unable to generate static config storage directory"; + let mut path_hint = global_config.global.root_path(); + let service_directory: FixedSizeByteString<{ FileName::max_len() }> = fatal_panic!(from origin, + when FixedSizeByteString::from_bytes(global_config.global.service.directory.as_bytes()), + "{} since the directory entry \"{}\" is invalid.", + msg, global_config.global.service.directory); + + fatal_panic!(from origin, when path_hint.add_path_entry(&service_directory), + "{} since the combination of root directory and service directory entry result in an invalid directory \"{}{}\".", + msg, path_hint, service_directory); generate_default_config::<::Configuration>( "static_config_storage_config", @@ -85,7 +86,7 @@ pub(crate) fn connection_config<'config, Service: crate::service::Details<'confi "connection_config", &global_config.global.prefix, &global_config.global.service.connection_suffix, - &global_config.global.root_path, + &global_config.global.root_path(), ) } @@ -96,6 +97,6 @@ pub(crate) fn data_segment_config<'config, Service: crate::service::Details<'con "data_segment_config", &global_config.global.prefix, &global_config.global.service.publisher_data_segment_suffix, - &global_config.global.root_path, + &global_config.global.root_path(), ) }