提交 2d5f8a53 authored 作者: Serhij S's avatar Serhij S

eapi allow override host name

上级 8c3a9efb
...@@ -80,6 +80,7 @@ where ...@@ -80,6 +80,7 @@ where
action_handlers: BTreeMap<OID, ActionHandlerFn<D, V>>, action_handlers: BTreeMap<OID, ActionHandlerFn<D, V>>,
#[serde(skip)] #[serde(skip)]
bulk_action_handlers: Vec<(OIDMask, ActionHandlerFn<D, V>)>, bulk_action_handlers: Vec<(OIDMask, ActionHandlerFn<D, V>)>,
name: Option<String>,
} }
impl<D, V> EAPIConfig<D, V> impl<D, V> EAPIConfig<D, V>
...@@ -114,8 +115,14 @@ where ...@@ -114,8 +115,14 @@ where
reconnect_delay: 2.0, reconnect_delay: 2.0,
action_handlers: <_>::default(), action_handlers: <_>::default(),
bulk_action_handlers: <_>::default(), bulk_action_handlers: <_>::default(),
name: None,
} }
} }
/// Override the client host name
pub fn name(mut self, name: impl AsRef<str>) -> Self {
self.name = Some(name.as_ref().to_owned());
self
}
/// Set timeout in seconds /// Set timeout in seconds
pub fn timeout(mut self, timeout: f64) -> Self { pub fn timeout(mut self, timeout: f64) -> Self {
self.timeout = Some(timeout); self.timeout = Some(timeout);
...@@ -330,13 +337,11 @@ where ...@@ -330,13 +337,11 @@ where
/// ///
/// Will panic if failed to get the hostname /// Will panic if failed to get the hostname
pub fn new_program(config: EAPIConfig<D, V>) -> Self { pub fn new_program(config: EAPIConfig<D, V>) -> Self {
Self::new( let host_name = config.name.as_ref().map_or_else(
format!( || hostname::get().unwrap().to_string_lossy().to_string(),
"fieldbus.{}.program", Clone::clone,
hostname::get().unwrap().to_string_lossy() );
), Self::new(format!("fieldbus.{}.program", host_name,), config)
config,
)
} }
/// creates a new EAPI connector instance with the given name /// creates a new EAPI connector instance with the given name
pub fn new<N: fmt::Display>(name: N, mut config: EAPIConfig<D, V>) -> Self { pub fn new<N: fmt::Display>(name: N, mut config: EAPIConfig<D, V>) -> Self {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论