stub out config reloader thread, not currently functional
This commit is contained in:
parent
a01ad46efa
commit
6acffb59cc
32
src/main.rs
32
src/main.rs
@ -13,6 +13,8 @@ extern crate env_logger;
|
|||||||
|
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
|
extern crate crossbeam;
|
||||||
|
|
||||||
fn init_logger () {
|
fn init_logger () {
|
||||||
let mut builder = env_logger::Builder::new();
|
let mut builder = env_logger::Builder::new();
|
||||||
builder.format(|buf, record: &log::Record| {
|
builder.format(|buf, record: &log::Record| {
|
||||||
@ -31,26 +33,36 @@ fn main () {
|
|||||||
init_logger();
|
init_logger();
|
||||||
|
|
||||||
let config_file_name = env::args().nth(1).unwrap_or("tenquestionmarks.toml".into());
|
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) {
|
if let Ok(mut file) = File::open(&config_file_name) {
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
if let Err(e) = file.read_to_string(&mut contents) {
|
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 {
|
} else {
|
||||||
match toml::from_str(&contents) {
|
match toml::from_str(&contents) {
|
||||||
Ok(configuration) => {
|
Ok(configuration) => {
|
||||||
info!("Loaded configuration from: {}", config_file_name);
|
info!("Loaded configuration from: {}", config_file_name);
|
||||||
match Tenquestionmarks::from_configuration(configuration) {
|
configuration
|
||||||
Ok(tqm) => {
|
|
||||||
info!("tenquestionmarks initialized successfully");
|
|
||||||
tqm.run();
|
|
||||||
},
|
|
||||||
Err(e) => error!("Failed to initialize tenquestionmarks: {:?}", e)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
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 {
|
} 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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,10 @@ implement_lua_push!(Message, |mut metatable| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
impl EventLoop for LuaModule {
|
impl EventLoop for LuaModule {
|
||||||
|
fn reconfigure (&mut self, configuration: &Table) {
|
||||||
|
self.variables = configuration.clone();
|
||||||
|
}
|
||||||
|
|
||||||
fn run (&self, _: Box<ExtSender<Event>>, receiver: Receiver<Arc<Envelope>>) {
|
fn run (&self, _: Box<ExtSender<Event>>, receiver: Receiver<Arc<Envelope>>) {
|
||||||
let mut lua = Lua::new();
|
let mut lua = Lua::new();
|
||||||
lua.openlibs();
|
lua.openlibs();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user