From e552035142b36fa1da78faed5cf83ff89f4506c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 19 Oct 2020 01:32:50 +0200 Subject: initial reading of config file --- mumd/Cargo.toml | 1 - mumd/src/state.rs | 13 ++++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'mumd') diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index 9101b43..ffb463a 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -27,6 +27,5 @@ tokio = { version = "0.2", features = ["full"] } tokio-tls = "0.3" tokio-util = { version = "0.3", features = ["codec", "udp"] } -#clap = "2.33" #compressor = "0.3" #daemonize = "0.4" diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 55fd8ae..e2892fc 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -6,6 +6,7 @@ use mumble_protocol::control::msgs; use mumble_protocol::control::ControlPacket; use mumble_protocol::voice::Serverbound; use mumlib::command::{Command, CommandResponse}; +use mumlib::config::Config; use mumlib::error::{ChannelIdentifierError, Error}; use serde::{Deserialize, Serialize}; use std::collections::hash_map::Entry; @@ -21,6 +22,7 @@ pub enum StatePhase { } pub struct State { + config: Config, server: Option, audio: Audio, @@ -28,6 +30,7 @@ pub struct State { connection_info_sender: watch::Sender>, phase_watcher: (watch::Sender, watch::Receiver), + } impl State { @@ -35,9 +38,17 @@ impl State { packet_sender: mpsc::UnboundedSender>, connection_info_sender: watch::Sender>, ) -> Self { + let config = mumlib::config::read_default_cfg(); + let audio = Audio::new(); + if let Some(ref audio_config) = config.audio { + if let Some(input_volume) = audio_config.input_volume { + audio.set_input_volume(input_volume); + } + } Self { + config, server: None, - audio: Audio::new(), + audio, packet_sender, connection_info_sender, phase_watcher: watch::channel(StatePhase::Disconnected), -- cgit v1.2.1 From 3e61f2d4a48b621c4cef820e24cd2515cbc1c919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 19 Oct 2020 02:40:43 +0200 Subject: convert config to string --- mumd/src/main.rs | 1 + mumd/src/state.rs | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'mumd') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 75726f8..5307a09 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -35,6 +35,7 @@ async fn main() { watch::channel::>(None); let state = State::new(packet_sender, connection_info_sender); + state.config().write_default_cfg(); let state = Arc::new(Mutex::new(state)); let (_, _, _, e) = join!( diff --git a/mumd/src/state.rs b/mumd/src/state.rs index e2892fc..e199552 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -215,6 +215,10 @@ impl State { .unwrap(); } + pub fn config(&self) -> &Config { + &self.config + } + pub fn audio(&self) -> &Audio { &self.audio } -- cgit v1.2.1 From d7a35eaf7900659d54419ae356fec1f658caac48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 19 Oct 2020 17:44:17 +0200 Subject: minor --- mumd/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mumd') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index e199552..5e1908c 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -40,7 +40,7 @@ impl State { ) -> Self { let config = mumlib::config::read_default_cfg(); let audio = Audio::new(); - if let Some(ref audio_config) = config.audio { + if let Some(audio_config) = &config.audio { if let Some(input_volume) = audio_config.input_volume { audio.set_input_volume(input_volume); } -- cgit v1.2.1 From f5f14327f7038159541f9f569170268fd64a8fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 19 Oct 2020 23:33:06 +0200 Subject: dont write config after loading state --- mumd/src/main.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'mumd') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 5307a09..75726f8 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -35,7 +35,6 @@ async fn main() { watch::channel::>(None); let state = State::new(packet_sender, connection_info_sender); - state.config().write_default_cfg(); let state = Arc::new(Mutex::new(state)); let (_, _, _, e) = join!( -- cgit v1.2.1 From fa4a2c53705c978c9c3410b4988f53d6db249b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 19 Oct 2020 23:33:56 +0200 Subject: mumd: add method to reload config --- mumd/src/state.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'mumd') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 5e1908c..e436d3d 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -30,7 +30,6 @@ pub struct State { connection_info_sender: watch::Sender>, phase_watcher: (watch::Sender, watch::Receiver), - } impl State { @@ -38,21 +37,17 @@ impl State { packet_sender: mpsc::UnboundedSender>, connection_info_sender: watch::Sender>, ) -> Self { - let config = mumlib::config::read_default_cfg(); let audio = Audio::new(); - if let Some(audio_config) = &config.audio { - if let Some(input_volume) = audio_config.input_volume { - audio.set_input_volume(input_volume); - } - } - Self { - config, + let mut state = Self { + config: mumlib::config::read_default_cfg().expect("format error in config file"), server: None, audio, packet_sender, connection_info_sender, phase_watcher: watch::channel(StatePhase::Disconnected), - } + }; + state.reload_config(); + state } //TODO? move bool inside Result @@ -208,6 +203,16 @@ impl State { self.server.as_mut().unwrap().parse_user_state(msg); } + pub fn reload_config(&mut self) { + self.config = mumlib::config::read_default_cfg() + .expect("format error in config file"); + if let Some(audio_config) = &self.config.audio { + if let Some(input_volume) = audio_config.input_volume { + self.audio.set_input_volume(input_volume); + } + } + } + pub fn initialized(&self) { self.phase_watcher .0 -- cgit v1.2.1 From d75bc24bdd176786a1340e16f7aa3db6e3e6a093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 19 Oct 2020 23:34:39 +0200 Subject: send config-reload-command --- mumd/src/state.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mumd') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index e436d3d..08724dd 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -171,6 +171,10 @@ impl State { self.audio.set_input_volume(volume); (false, Ok(None)) } + Command::ConfigReload => { + self.reload_config(); + (false, Ok(None)) + } } } -- cgit v1.2.1 From 6a136ac842dd601ce7f68566c27b5262d221872c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 21 Oct 2020 00:57:37 +0200 Subject: default cfg is option None if the file doesn't exist --- mumd/src/state.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'mumd') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 08724dd..0dbf9c5 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -22,7 +22,7 @@ pub enum StatePhase { } pub struct State { - config: Config, + config: Option, server: Option, audio: Audio, @@ -39,7 +39,7 @@ impl State { ) -> Self { let audio = Audio::new(); let mut state = Self { - config: mumlib::config::read_default_cfg().expect("format error in config file"), + config: mumlib::config::read_default_cfg(), server: None, audio, packet_sender, @@ -208,12 +208,16 @@ impl State { } pub fn reload_config(&mut self) { - self.config = mumlib::config::read_default_cfg() - .expect("format error in config file"); - if let Some(audio_config) = &self.config.audio { - if let Some(input_volume) = audio_config.input_volume { - self.audio.set_input_volume(input_volume); + if let Some(config) = mumlib::config::read_default_cfg() { + self.config = Some(config); + let config = &self.config.as_ref().unwrap(); + if let Some(audio_config) = &config.audio { + if let Some(input_volume) = audio_config.input_volume { + self.audio.set_input_volume(input_volume); + } } + } else { + warn!("config file not found"); } } @@ -224,10 +228,6 @@ impl State { .unwrap(); } - pub fn config(&self) -> &Config { - &self.config - } - pub fn audio(&self) -> &Audio { &self.audio } -- cgit v1.2.1