agentmux_srv\backend\wconfig/
watcher.rs1use std::sync::{Arc, RwLock};
7
8use super::types::{FullConfigType, SettingsType};
9
10pub struct ConfigWatcher {
14 config: RwLock<Arc<FullConfigType>>,
15}
16
17impl ConfigWatcher {
18 pub fn new() -> Self {
20 Self {
21 config: RwLock::new(Arc::new(FullConfigType::default())),
22 }
23 }
24
25 pub fn with_config(config: FullConfigType) -> Self {
27 Self {
28 config: RwLock::new(Arc::new(config)),
29 }
30 }
31
32 pub fn get_full_config(&self) -> Arc<FullConfigType> {
34 self.config.read().unwrap().clone()
35 }
36
37 pub fn get_settings(&self) -> SettingsType {
39 self.config.read().unwrap().settings.clone()
40 }
41
42 #[allow(dead_code)]
44 pub fn set_config(&self, config: FullConfigType) {
45 let mut current = self.config.write().unwrap();
46 *current = Arc::new(config);
47 }
48
49 pub fn update_settings(&self, settings: SettingsType) {
51 let mut current = self.config.write().unwrap();
52 let mut new_config = (**current).clone();
53 new_config.settings = settings;
54 *current = Arc::new(new_config);
55 }
56}
57
58impl Default for ConfigWatcher {
59 fn default() -> Self {
60 Self::new()
61 }
62}