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
use super::{start_rest_server, ControlContextLock};
use crate::config::Config;
use tokio::runtime::Runtime;

pub struct ManagerService {
    control_context: ControlContextLock,
    runtime: Runtime,
}

impl ManagerService {
    pub fn new(control_context: ControlContextLock) -> Self {
        Self {
            runtime: Runtime::new().unwrap(),
            control_context,
        }
    }

    pub fn spawn(&mut self) {
        let server_fut = start_rest_server(self.control_context.clone());

        self.runtime.spawn(async move {
            server_fut.await;
        });
    }

    pub fn request_to_start(&self) -> bool {
        self.control_context.lock().unwrap().request_to_start()
    }

    pub fn request_to_stop(&self) -> bool {
        self.control_context.lock().unwrap().request_to_stop()
    }

    pub fn setup(&self) -> Config {
        self.control_context.lock().unwrap().setup().clone()
    }

    pub fn clear_requests(&mut self) {
        self.control_context.lock().unwrap().clear_requests();
    }
}