Skip to content

Commit

Permalink
Read event path for RFID from config file, dependent thread creation
Browse files Browse the repository at this point in the history
  • Loading branch information
manio committed Jun 5, 2020
1 parent d76e646 commit 42609e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/main.rs
Expand Up @@ -40,6 +40,13 @@ fn ethlcd_hostname() -> Option<String> {
.and_then(|x| x.get("ethlcd_host").cloned())
}

fn rfid_filepath() -> Option<String> {
let conf = Ini::load_from_file("hard.conf").expect("Cannot open config file");
conf.section(Some("general".to_owned()))
.and_then(|x| x.get("rfid_event_path").cloned())
}
//fixme: refactor 3 above functions

fn logging_init() {
let mut conf = Config::default();
conf.time_format = Some("%F, %H:%M:%S%.3f");
Expand Down Expand Up @@ -196,18 +203,24 @@ fn main() {
.unwrap();
threads.push(thread_handler);

//creating rfid thread
let rfid = rfid::Rfid {
name: "rfid".to_string(),
//rfid thread
match rfid_filepath() {
Some(event_path) => {
let rfid = rfid::Rfid {
name: "rfid".to_string(),
event_path,
};
let worker_cancel_flag = cancel_flag.clone();
let thread_builder = thread::Builder::new().name("rfid".into()); //thread name
let thread_handler = thread_builder
.spawn(move || {
rfid.worker(worker_cancel_flag);
})
.unwrap();
threads.push(thread_handler);
}
_ => {}
};
let worker_cancel_flag = cancel_flag.clone();
let thread_builder = thread::Builder::new().name("rfid".into()); //thread name
let thread_handler = thread_builder
.spawn(move || {
rfid.worker(worker_cancel_flag);
})
.unwrap();
threads.push(thread_handler);

debug!("Entering main loop...");
loop {
Expand Down
1 change: 1 addition & 0 deletions src/rfid.rs
Expand Up @@ -5,6 +5,7 @@ use std::time::Duration;

pub struct Rfid {
pub name: String,
pub event_path: String,
}

impl Rfid {
Expand Down

0 comments on commit 42609e3

Please sign in to comment.