This commit is contained in:
+44
-11
@@ -55,25 +55,58 @@ pub fn run_daemon(config_path: Option<PathBuf>) -> Result<()> {
|
|||||||
let config_path_clone = config_path.clone();
|
let config_path_clone = config_path.clone();
|
||||||
let config = Arc::new(RwLock::new(crate::config::load_config(config_path)));
|
let config = Arc::new(RwLock::new(crate::config::load_config(config_path)));
|
||||||
|
|
||||||
|
// 1. Network Thread
|
||||||
let poll_state = Arc::clone(&state);
|
let poll_state = Arc::clone(&state);
|
||||||
let poll_running = Arc::clone(&running);
|
let poll_running = Arc::clone(&running);
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
info!("Starting background polling thread");
|
info!("Starting Network polling thread");
|
||||||
let mut network_daemon = NetworkDaemon::new();
|
let mut daemon = NetworkDaemon::new();
|
||||||
let mut hardware_daemon = HardwareDaemon::new();
|
|
||||||
let mut bt_daemon = BtDaemon::new();
|
|
||||||
|
|
||||||
let audio_daemon = AudioDaemon::new();
|
|
||||||
audio_daemon.start(Arc::clone(&poll_state));
|
|
||||||
|
|
||||||
while poll_running.load(Ordering::SeqCst) {
|
while poll_running.load(Ordering::SeqCst) {
|
||||||
network_daemon.poll(Arc::clone(&poll_state));
|
daemon.poll(Arc::clone(&poll_state));
|
||||||
hardware_daemon.poll(Arc::clone(&poll_state));
|
|
||||||
bt_daemon.poll(Arc::clone(&poll_state));
|
|
||||||
thread::sleep(Duration::from_secs(1));
|
thread::sleep(Duration::from_secs(1));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 2. Fast Hardware Thread (CPU, Mem, Load)
|
||||||
|
let poll_state = Arc::clone(&state);
|
||||||
|
let poll_running = Arc::clone(&running);
|
||||||
|
thread::spawn(move || {
|
||||||
|
info!("Starting Fast Hardware polling thread");
|
||||||
|
let mut daemon = HardwareDaemon::new();
|
||||||
|
while poll_running.load(Ordering::SeqCst) {
|
||||||
|
daemon.poll_fast(Arc::clone(&poll_state));
|
||||||
|
thread::sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 3. Slow Hardware Thread (GPU, Disks)
|
||||||
|
let poll_state = Arc::clone(&state);
|
||||||
|
let poll_running = Arc::clone(&running);
|
||||||
|
thread::spawn(move || {
|
||||||
|
info!("Starting Slow Hardware polling thread");
|
||||||
|
let mut daemon = HardwareDaemon::new();
|
||||||
|
while poll_running.load(Ordering::SeqCst) {
|
||||||
|
daemon.poll_slow(Arc::clone(&poll_state));
|
||||||
|
thread::sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 4. Bluetooth Thread
|
||||||
|
let poll_state = Arc::clone(&state);
|
||||||
|
let poll_running = Arc::clone(&running);
|
||||||
|
thread::spawn(move || {
|
||||||
|
info!("Starting Bluetooth polling thread");
|
||||||
|
let mut daemon = BtDaemon::new();
|
||||||
|
while poll_running.load(Ordering::SeqCst) {
|
||||||
|
daemon.poll(Arc::clone(&poll_state));
|
||||||
|
thread::sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 5. Audio Thread (Event driven)
|
||||||
|
let audio_daemon = AudioDaemon::new();
|
||||||
|
audio_daemon.start(Arc::clone(&state));
|
||||||
|
|
||||||
info!("Fluxo daemon successfully bound to socket: {}", sock_path);
|
info!("Fluxo daemon successfully bound to socket: {}", sock_path);
|
||||||
|
|
||||||
// Use non-blocking accept so we can check the running flag
|
// Use non-blocking accept so we can check the running flag
|
||||||
|
|||||||
+19
-15
@@ -24,7 +24,7 @@ impl HardwareDaemon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn poll(&mut self, state: SharedState) {
|
pub fn poll_fast(&mut self, state: SharedState) {
|
||||||
self.sys.refresh_cpu_usage();
|
self.sys.refresh_cpu_usage();
|
||||||
self.sys.refresh_memory();
|
self.sys.refresh_memory();
|
||||||
self.components.refresh(true);
|
self.components.refresh(true);
|
||||||
@@ -70,6 +70,23 @@ impl HardwareDaemon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Ok(mut state_lock) = state.write() {
|
||||||
|
state_lock.cpu.usage = cpu_usage as f64;
|
||||||
|
state_lock.cpu.temp = cpu_temp;
|
||||||
|
state_lock.cpu.model = cpu_model;
|
||||||
|
|
||||||
|
state_lock.memory.total_gb = total_mem;
|
||||||
|
state_lock.memory.used_gb = used_mem;
|
||||||
|
|
||||||
|
state_lock.sys.load_1 = load_avg.one;
|
||||||
|
state_lock.sys.load_5 = load_avg.five;
|
||||||
|
state_lock.sys.load_15 = load_avg.fifteen;
|
||||||
|
state_lock.sys.uptime = uptime;
|
||||||
|
state_lock.sys.process_count = process_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn poll_slow(&mut self, state: SharedState) {
|
||||||
// 1. Gather GPU data outside of lock
|
// 1. Gather GPU data outside of lock
|
||||||
let mut gpu_state = crate::state::GpuState::default();
|
let mut gpu_state = crate::state::GpuState::default();
|
||||||
self.gpu_poll_counter = (self.gpu_poll_counter + 1) % 5;
|
self.gpu_poll_counter = (self.gpu_poll_counter + 1) % 5;
|
||||||
@@ -95,21 +112,8 @@ impl HardwareDaemon {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Apply everything to state in one short lock
|
// 3. Apply to state
|
||||||
if let Ok(mut state_lock) = state.write() {
|
if let Ok(mut state_lock) = state.write() {
|
||||||
state_lock.cpu.usage = cpu_usage as f64;
|
|
||||||
state_lock.cpu.temp = cpu_temp;
|
|
||||||
state_lock.cpu.model = cpu_model;
|
|
||||||
|
|
||||||
state_lock.memory.total_gb = total_mem;
|
|
||||||
state_lock.memory.used_gb = used_mem;
|
|
||||||
|
|
||||||
state_lock.sys.load_1 = load_avg.one;
|
|
||||||
state_lock.sys.load_5 = load_avg.five;
|
|
||||||
state_lock.sys.load_15 = load_avg.fifteen;
|
|
||||||
state_lock.sys.uptime = uptime;
|
|
||||||
state_lock.sys.process_count = process_count;
|
|
||||||
|
|
||||||
if should_poll_gpu {
|
if should_poll_gpu {
|
||||||
state_lock.gpu = gpu_state;
|
state_lock.gpu = gpu_state;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user