use std::error::Error;
use base::ReadNotifier;
pub trait PowerMonitor: ReadNotifier {
fn read_message(&mut self) -> std::result::Result<Option<PowerData>, Box<dyn Error>>;
}
pub trait PowerClient {
fn get_power_data(&mut self) -> std::result::Result<PowerData, Box<dyn Error>>;
}
#[derive(Debug)]
pub struct PowerData {
pub ac_online: bool,
pub battery: Option<BatteryData>,
}
#[derive(Clone, Copy, Debug)]
pub struct BatteryData {
pub status: BatteryStatus,
pub percent: u32,
pub voltage: u32,
pub current: u32,
pub charge_counter: u32,
pub charge_full: u32,
}
#[derive(Clone, Copy, Debug)]
pub enum BatteryStatus {
Unknown,
Charging,
Discharging,
NotCharging,
}
pub trait CreatePowerMonitorFn:
Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
{
}
impl<T> CreatePowerMonitorFn for T where
T: Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
{
}
pub trait CreatePowerClientFn:
Send + Fn() -> std::result::Result<Box<dyn PowerClient>, Box<dyn Error>>
{
}
impl<T> CreatePowerClientFn for T where
T: Send + Fn() -> std::result::Result<Box<dyn PowerClient>, Box<dyn Error>>
{
}
#[cfg(feature = "powerd")]
pub mod powerd;
mod protos {
include!(concat!(env!("OUT_DIR"), "/protos/generated.rs"));
}