extern crate rustc_serialize; mod sensors; mod comm; mod config; mod events; mod store; mod music; use comm::{Channel, Message}; use config::Config; use std::env; use std::sync::Arc; use std::sync::mpsc; use std::thread; fn main() { let config_path = env::args().nth(1).unwrap_or("./panel.toml".to_string()); let cfg = config::load(&config_path); let cfg = Arc::new(cfg); let (tx, rx) = mpsc::channel::(); make_thread(&tx, &cfg, events::handle); make_thread(&tx, &cfg, sensors::sensors); make_thread(&tx, &cfg, music::music); let mut data = store::Store::new(); // i3bar header println!("{{\"version\": 1,\"click_events\":true}}"); println!("["); loop { let msg = rx.recv().unwrap(); data.save(msg); println!("[{},{}],", data.get("mpd"), data.get("sensors") ); } } fn make_thread(tx: &Channel, cfg: &Arc, func: fn(&Channel, &Config) -> ()) { let thread_tx = tx.clone(); let thread_cfg = cfg.clone(); thread::spawn(move || { func(&thread_tx, &thread_cfg); }); }