Skip to content

Commit

Permalink
Align naming style of zenoh_config::defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzypixelz committed Sep 16, 2024
1 parent 744f9de commit de28458
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
17 changes: 5 additions & 12 deletions commons/zenoh-config/src/connection_retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ use serde::{Deserialize, Serialize};
use zenoh_core::zparse_default;
use zenoh_protocol::core::{EndPoint, WhatAmI};

use crate::{
defaults::{
self, DEFAULT_CONNECT_EXIT_ON_FAIL, DEFAULT_CONNECT_TIMEOUT_MS,
DEFAULT_LISTEN_EXIT_ON_FAIL, DEFAULT_LISTEN_TIMEOUT_MS,
},
mode_dependent::*,
Config,
};
use crate::{defaults, mode_dependent::*, Config};

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ConnectionRetryModeDependentConf {
Expand Down Expand Up @@ -128,7 +121,7 @@ pub fn get_global_listener_timeout(config: &Config) -> std::time::Duration {
.listen()
.timeout_ms()
.get(whatami)
.unwrap_or(DEFAULT_LISTEN_TIMEOUT_MS.get(whatami).unwrap()),
.unwrap_or(defaults::listen::timeout_ms.get(whatami).unwrap()),
)
}

Expand All @@ -139,7 +132,7 @@ pub fn get_global_connect_timeout(config: &Config) -> std::time::Duration {
.connect()
.timeout_ms()
.get(whatami)
.unwrap_or(DEFAULT_CONNECT_TIMEOUT_MS.get(whatami).unwrap()),
.unwrap_or(defaults::connect::timeout_ms.get(whatami).unwrap()),
)
}

Expand All @@ -164,7 +157,7 @@ pub fn get_retry_config(
.listen()
.exit_on_failure()
.get(whatami)
.unwrap_or(DEFAULT_LISTEN_EXIT_ON_FAIL.get(whatami).unwrap());
.unwrap_or(defaults::listen::exit_on_failure.get(whatami).unwrap());
} else {
retry = config
.connect()
Expand All @@ -176,7 +169,7 @@ pub fn get_retry_config(
.connect()
.exit_on_failure()
.get(whatami)
.unwrap_or(DEFAULT_CONNECT_EXIT_ON_FAIL.get(whatami).unwrap());
.unwrap_or(defaults::connect::exit_on_failure.get(whatami).unwrap());
}

let mut res = ConnectionRetryConf::new(whatami, exit_on_failure, retry, default_retry);
Expand Down
44 changes: 27 additions & 17 deletions commons/zenoh-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ macro_rules! mode_accessor {
#[allow(dead_code)]
pub const mode: WhatAmI = WhatAmI::Peer;

#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub mod connect {
use super::{ModeDependentValue, ModeValues};

pub const timeout_ms: ModeDependentValue<i64> = ModeDependentValue::Dependent(ModeValues {
router: Some(-1),
peer: Some(-1),
client: Some(0),
});
pub const exit_on_failure: ModeDependentValue<bool> =
ModeDependentValue::Dependent(ModeValues {
router: Some(false),
peer: Some(false),
client: Some(true),
});
}

#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub mod listen {
use super::ModeDependentValue;

pub const timeout_ms: ModeDependentValue<i64> = ModeDependentValue::Unique(0);
pub const exit_on_failure: ModeDependentValue<bool> = ModeDependentValue::Unique(true);
}

#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub mod scouting {
Expand Down Expand Up @@ -261,23 +288,6 @@ impl Default for AclConfig {
}
}

pub const DEFAULT_CONNECT_TIMEOUT_MS: ModeDependentValue<i64> =
ModeDependentValue::Dependent(ModeValues {
client: Some(0),
peer: Some(-1),
router: Some(-1),
});

pub const DEFAULT_CONNECT_EXIT_ON_FAIL: ModeDependentValue<bool> =
ModeDependentValue::Dependent(ModeValues {
client: Some(true),
peer: Some(false),
router: Some(false),
});

pub const DEFAULT_LISTEN_TIMEOUT_MS: ModeDependentValue<i64> = ModeDependentValue::Unique(0);
pub const DEFAULT_LISTEN_EXIT_ON_FAIL: ModeDependentValue<bool> = ModeDependentValue::Unique(true);

impl Default for ConnectionRetryModeDependentConf {
fn default() -> Self {
Self {
Expand Down

0 comments on commit de28458

Please sign in to comment.