diff --git a/crates/shturman-ipc/src/lib.rs b/crates/shturman-ipc/src/lib.rs index f1053d6..2c8243f 100644 --- a/crates/shturman-ipc/src/lib.rs +++ b/crates/shturman-ipc/src/lib.rs @@ -4,7 +4,9 @@ pub mod error; pub mod names; +pub mod proxy; pub mod types; pub use error::Error; +pub use proxy::{Power1Proxy, Settings1Proxy}; pub use types::{IgnitionState, PowerSource, PowerState, ShutdownReason}; diff --git a/crates/shturman-ipc/src/proxy.rs b/crates/shturman-ipc/src/proxy.rs new file mode 100644 index 0000000..b80ef09 --- /dev/null +++ b/crates/shturman-ipc/src/proxy.rs @@ -0,0 +1,52 @@ +//! Клиентские `#[proxy]`-трейты (ipc §3). zbus генерит `Power1Proxy` / `Settings1Proxy`. +//! Enum-значения передаются строками (`types`); `Settings` — D-Bus variant (`zvariant::Value`/`OwnedValue`). + +use zbus::proxy; +use zbus::zvariant::{OwnedValue, Value}; + +/// `ru.shturman.Power1` — питание/жизненный цикл (домен B). +#[proxy( + interface = "ru.shturman.Power1", + default_service = "ru.shturman.Power", + default_path = "/ru/shturman/Power" +)] +pub trait Power1 { + /// Текущее состояние (enum-строка `PowerState`). + fn get_power_state(&self) -> zbus::Result; + /// Внутренний запрос сна (в v0-стабе — no-op). + fn request_sleep(&self) -> zbus::Result<()>; + + #[zbus(property)] + fn ignition_state(&self) -> zbus::Result; + #[zbus(property)] + fn uptime(&self) -> zbus::Result; + #[zbus(property)] + fn power_source(&self) -> zbus::Result; + + #[zbus(signal)] + fn acc_changed(&self, on: bool) -> zbus::Result<()>; + #[zbus(signal)] + fn shutdown_imminent(&self, seconds: u32, reason: String) -> zbus::Result<()>; + #[zbus(signal)] + fn shutdown_aborted(&self) -> zbus::Result<()>; + #[zbus(signal)] + fn sleep(&self) -> zbus::Result<()>; + #[zbus(signal)] + fn wake(&self) -> zbus::Result<()>; +} + +/// `ru.shturman.Settings1` — конфигурация и состояние. +#[proxy( + interface = "ru.shturman.Settings1", + default_service = "ru.shturman.Settings", + default_path = "/ru/shturman/Settings" +)] +pub trait Settings1 { + fn get(&self, key: &str) -> zbus::Result; + fn set(&self, key: &str, value: &Value<'_>) -> zbus::Result<()>; + fn list(&self, prefix: &str) -> zbus::Result>; + fn reset(&self, key: &str) -> zbus::Result<()>; + + #[zbus(signal)] + fn changed(&self, key: String, value: OwnedValue) -> zbus::Result<()>; +}