Skip to content

Commit

Permalink
Merge pull request #86 from elfenpiff/iox2-15-same-default-config-file
Browse files Browse the repository at this point in the history
[#15] Use only one config file for every platform
  • Loading branch information
elfenpiff authored Jan 16, 2024
2 parents 891ae9b + 135251b commit 4fae122
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 58 deletions.
2 changes: 1 addition & 1 deletion config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion config/iceoryx2.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[global]
root_path = '/tmp/iceoryx2/'
root_path_unix = '/tmp/iceoryx2/'
root_path_windows = 'c:\Temp\iceoryx2\'
prefix = 'iox2_'

[global.service]
Expand Down
26 changes: 0 additions & 26 deletions config/iceoryx2_win.toml

This file was deleted.

2 changes: 1 addition & 1 deletion doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<!-- NOTE: Add new entries sorted by issue number to minimize the possibility of conflicts when merging. -->

* 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

Expand Down
36 changes: 23 additions & 13 deletions iceoryx2/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -148,23 +143,40 @@ 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
pub service: Service,
}

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
Expand Down Expand Up @@ -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(),
Expand Down
33 changes: 17 additions & 16 deletions iceoryx2/src/service/config_scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +21,7 @@ fn generate_default_config<T: NamedConceptConfiguration>(
origin: &str,
prefix: &str,
suffix: &str,
path_hint: &str,
path_hint: &Path,
) -> T {
let prefix = match FileName::new(prefix.as_bytes()) {
Err(_) => {
Expand All @@ -39,18 +39,10 @@ fn generate_default_config<T: NamedConceptConfiguration>(
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>>(
Expand All @@ -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,
) -> <Service::StaticStorage as NamedConceptMgmt>::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::<<Service::StaticStorage as NamedConceptMgmt>::Configuration>(
"static_config_storage_config",
Expand All @@ -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(),
)
}

Expand All @@ -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(),
)
}

0 comments on commit 4fae122

Please sign in to comment.