From 6acffb59cc0c84ddb12f57e53ac08a5494cd5de3 Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Sat, 24 Feb 2018 19:13:09 -0600 Subject: [PATCH] stub out config reloader thread, not currently functional --- src/main.rs | 32 ++++++++++++++++++++++---------- src/modules/lua.rs | 4 ++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 03b2d6f..18e40ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,8 @@ extern crate env_logger; extern crate time; +extern crate crossbeam; + fn init_logger () { let mut builder = env_logger::Builder::new(); builder.format(|buf, record: &log::Record| { @@ -31,26 +33,36 @@ fn main () { init_logger(); let config_file_name = env::args().nth(1).unwrap_or("tenquestionmarks.toml".into()); + match Tenquestionmarks::from_configuration(read_config_from_file(&config_file_name)) { + Ok(tqm) => { + info!("tenquestionmarks initialized successfully"); + crossbeam::scope(|scope| { + //scope.spawn(|| { + // tqm.reconfigure(&read_config_from_file(&config_file_name)); + //}); + + tqm.run(); + }) + }, + Err(e) => error!("Failed to initialize tenquestionmarks: {:?}", e) + } +} + +fn read_config_from_file (config_file_name: &str) -> toml::value::Table { if let Ok(mut file) = File::open(&config_file_name) { let mut contents = String::new(); if let Err(e) = file.read_to_string(&mut contents) { - error!("Failed to open config file {}: {:?}", config_file_name, e); + panic!("Failed to open config file {}: {:?}", config_file_name, e); } else { match toml::from_str(&contents) { Ok(configuration) => { info!("Loaded configuration from: {}", config_file_name); - match Tenquestionmarks::from_configuration(configuration) { - Ok(tqm) => { - info!("tenquestionmarks initialized successfully"); - tqm.run(); - }, - Err(e) => error!("Failed to initialize tenquestionmarks: {:?}", e) - } + configuration }, - Err(error) => error!("Failed to parse config file {}: {:?}. Config file must be a valid TOML file.", config_file_name, error) + Err(error) => panic!("Failed to parse config file {}: {:?}. Config file must be a valid TOML file.", config_file_name, error) } } } else { - error!("Failed to open config file! Please specify path to a config file."); + panic!("Failed to open config file! Please specify path to a config file."); } } diff --git a/src/modules/lua.rs b/src/modules/lua.rs index 14d445d..75b629d 100644 --- a/src/modules/lua.rs +++ b/src/modules/lua.rs @@ -50,6 +50,10 @@ implement_lua_push!(Message, |mut metatable| { }); impl EventLoop for LuaModule { + fn reconfigure (&mut self, configuration: &Table) { + self.variables = configuration.clone(); + } + fn run (&self, _: Box>, receiver: Receiver>) { let mut lua = Lua::new(); lua.openlibs();