omni_director/core/
server.rs

1//! # Core Server Module
2//!
3//! Core server functionality for the OmniDirector system.
4
5use std::sync::Arc;
6use tokio::sync::RwLock;
7
8/// Main server state
9#[derive(Debug)]
10pub struct ServerState {
11    /// Server configuration
12    config: Arc<RwLock<ServerConfig>>,
13    /// Running status
14    running: Arc<RwLock<bool>>,
15}
16
17/// Server configuration
18#[derive(Debug, Clone)]
19pub struct ServerConfig {
20    /// Server port
21    pub port: u16,
22    /// Server host
23    pub host: String,
24    /// Enable debug mode
25    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    /// Create a new server state
40    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    /// Check if server is running
48    pub async fn is_running(&self) -> bool {
49        *self.running.read().await
50    }
51
52    /// Set server running status
53    pub async fn set_running(&self, running: bool) {
54        *self.running.write().await = running;
55    }
56
57    /// Get server configuration
58    pub async fn get_config(&self) -> ServerConfig {
59        self.config.read().await.clone()
60    }
61
62    /// Update server configuration
63    pub async fn update_config(&self, config: ServerConfig) {
64        *self.config.write().await = config;
65    }
66}