pub struct AppState {
pub store: Mutex<Store>,
pub config: RwLock<Config>,
pub config_path: PathBuf,
pub readings_tx: Sender<ReadingEvent>,
pub collector: CollectorState,
}Expand description
Shared application state.
Fields§
§store: Mutex<Store>The data store (wrapped in Mutex for thread-safe access).
config: RwLock<Config>Configuration (RwLock for runtime updates).
config_path: PathBufPath to the configuration file (for saving changes).
readings_tx: Sender<ReadingEvent>Broadcast channel for real-time reading updates.
collector: CollectorStateCollector control state.
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new(store: Store, config: Config) -> Arc<Self>
pub fn new(store: Store, config: Config) -> Arc<Self>
Create new application state.
The broadcast channel buffer size is determined by config.server.broadcast_buffer.
If the buffer fills (slow subscribers), old messages are dropped without blocking.
Sourcepub fn with_config_path(
store: Store,
config: Config,
config_path: PathBuf,
) -> Arc<Self>
pub fn with_config_path( store: Store, config: Config, config_path: PathBuf, ) -> Arc<Self>
Create new application state with a custom config path.
Sourcepub async fn save_config(&self) -> Result<(), ConfigError>
pub async fn save_config(&self) -> Result<(), ConfigError>
Save the current configuration to disk.
This should be called after any configuration changes made via the API.
Sourcepub async fn save_config_or_log(&self)
pub async fn save_config_or_log(&self)
Save the configuration to disk, logging any errors.
This is a convenience method for fire-and-forget saves.
Sourcepub async fn on_devices_changed(&self)
pub async fn on_devices_changed(&self)
Signal that the device configuration has changed.
This saves the config to disk and signals the collector to reload if it is currently running.