stub out config reloader thread, not currently functional

This commit is contained in:
Adrian Malacoda 2018-02-24 19:13:09 -06:00
parent a01ad46efa
commit 6acffb59cc
2 changed files with 26 additions and 10 deletions

View File

@ -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.");
}
}

View File

@ -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<ExtSender<Event>>, receiver: Receiver<Arc<Envelope>>) {
let mut lua = Lua::new();
lua.openlibs();