aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 97e28b5cb36d76952d065beee6cce93ba668bd8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::sync::{Arc, Mutex};
use std::{thread::sleep, time::Duration};
use zbus::{connection::Builder, Result};

use crate::config::PomdConfig;
use crate::interface::PomdInterface;
use crate::pomd::Pomd;

mod config;
mod interface;
mod pomd;

#[async_std::main]
async fn main() -> Result<()> {
    let config: PomdConfig = confy::load("pomd", "config").expect("Failed to load config!");
    let pomd = Arc::new(Mutex::new(Pomd::new(config)));
    let mut _connection;
    loop {
        let pomd_interface = PomdInterface::new(pomd.clone());
        match Builder::session()?
            .name("dev.exvacuum.pomd")?
            .serve_at("/dev/exvacuum/pomd", pomd_interface)?
            .build()
            .await
        {
            Ok(connection) => {
                _connection = connection;
                break;
            }
            Err(e) => {
                eprintln!("Failed to start D-Bus session: {e:?}");
                eprintln!("Trying again in 10 seconds...");
                sleep(Duration::from_secs(10));
                continue;
            }
        }
    }
    loop {
        pomd.lock().unwrap().update();
        sleep(Duration::from_millis(100));
    }
}