omni_director/core/
server.rs1use std::sync::Arc;
6use tokio::sync::RwLock;
7
8#[derive(Debug)]
10pub struct ServerState {
11 config: Arc<RwLock<ServerConfig>>,
13 running: Arc<RwLock<bool>>,
15}
16
17#[derive(Debug, Clone)]
19pub struct ServerConfig {
20 pub port: u16,
22 pub host: String,
24 pub debug: bool,
26}
27
28impl Default for ServerConfig {
29 fn default() -> Self {
30 Self {
31 port: 8080,
32 host: "127.0.0.1".to_string(),
33 debug: false,
34 }
35 }
36}
37
38impl ServerState {
39 pub fn new(config: ServerConfig) -> Self {
41 Self {
42 config: Arc::new(RwLock::new(config)),
43 running: Arc::new(RwLock::new(false)),
44 }
45 }
46
47 pub async fn is_running(&self) -> bool {
49 *self.running.read().await
50 }
51
52 pub async fn set_running(&self, running: bool) {
54 *self.running.write().await = running;
55 }
56
57 pub async fn get_config(&self) -> ServerConfig {
59 self.config.read().await.clone()
60 }
61
62 pub async fn update_config(&self, config: ServerConfig) {
64 *self.config.write().await = config;
65 }
66}