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
pub use self::clock::{Clock, Delay, Rate};
pub use self::master::{Master, SystemState, Topic};
pub use self::ros::{Parameter, Ros};
use std::sync::atomic::{AtomicBool, Ordering};

mod clock;
pub mod error;
pub mod handlers;
mod master;
mod naming;
pub mod raii;
pub mod resolve;
mod ros;
mod slave;

pub struct ShutdownManager {
    handler: Box<dyn Fn() + Send + Sync>,
    should_shutdown: AtomicBool,
}

impl ShutdownManager {
    pub fn new(handler: impl Fn() + Send + Sync + 'static) -> Self {
        Self {
            handler: Box::new(handler),
            should_shutdown: AtomicBool::new(false),
        }
    }

    pub fn awaiting_shutdown(&self) -> bool {
        self.should_shutdown.load(Ordering::Relaxed)
    }

    pub fn shutdown(&self) {
        (*self.handler)();
        self.should_shutdown.store(true, Ordering::Relaxed)
    }
}