daemon: Start bringing up contexts and state loading/saving

This commit is contained in:
Vicki Pfau 2024-05-24 17:06:43 -07:00 committed by Jeremy Whiting
parent 23267c65e0
commit c6113ee739
6 changed files with 275 additions and 19 deletions

View file

@ -6,17 +6,74 @@
*/
use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use tracing::error;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, Registry};
use zbus::connection::Connection;
use zbus::ConnectionBuilder;
use crate::daemon::Daemon;
use crate::daemon::{Daemon, DaemonContext};
use crate::ds_inhibit::Inhibitor;
use crate::manager::root::SteamOSManager;
use crate::path;
use crate::sls::ftrace::Ftrace;
#[derive(Copy, Clone, Default, Deserialize, Serialize, Debug)]
pub(crate) struct RootConfig {
pub services: RootServicesConfig,
}
#[derive(Copy, Clone, Default, Deserialize, Serialize, Debug)]
pub(crate) struct RootServicesConfig {}
#[derive(Copy, Clone, Default, Deserialize, Serialize, Debug)]
pub(crate) struct RootState {
pub services: RootServicesState,
}
#[derive(Copy, Clone, Default, Deserialize, Serialize, Debug)]
pub(crate) struct RootServicesState {}
struct RootContext {}
impl DaemonContext for RootContext {
type State = RootState;
type Config = RootConfig;
fn user_config_path(&self) -> Result<PathBuf> {
Ok(path("/etc/steamos-manager"))
}
fn system_config_path(&self) -> Result<PathBuf> {
Ok(path("/usr/lib/steamos-manager/system.d"))
}
fn state(&self) -> RootState {
RootState::default()
}
async fn start(
&mut self,
_state: RootState,
_config: RootConfig,
_daemon: &mut Daemon<RootContext>,
) -> Result<()> {
// Nothing to do yet
Ok(())
}
async fn reload(
&mut self,
_config: RootConfig,
_daemon: &mut Daemon<RootContext>,
) -> Result<()> {
// Nothing to do yet
Ok(())
}
}
async fn create_connection() -> Result<Connection> {
let connection = ConnectionBuilder::system()?
.name("com.steampowered.SteamOSManager1")?
@ -45,6 +102,8 @@ pub async fn daemon() -> Result<()> {
bail!(e);
}
};
let context = RootContext {};
let mut daemon = Daemon::new(subscriber, connection.clone()).await?;
let ftrace = Ftrace::init(connection.clone()).await?;
@ -53,5 +112,5 @@ pub async fn daemon() -> Result<()> {
let inhibitor = Inhibitor::init().await?;
daemon.add_service(inhibitor);
daemon.run().await
daemon.run(context).await
}