• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use std::error::Error;
6 use std::os::unix::io::RawFd;
7 
8 pub trait PowerMonitor {
poll_fd(&self) -> RawFd9     fn poll_fd(&self) -> RawFd;
read_message(&mut self) -> std::result::Result<Option<PowerData>, Box<dyn Error>>10     fn read_message(&mut self) -> std::result::Result<Option<PowerData>, Box<dyn Error>>;
11 }
12 
13 pub struct PowerData {
14     pub ac_online: bool,
15     pub battery: Option<BatteryData>,
16 }
17 
18 pub struct BatteryData {
19     pub status: BatteryStatus,
20     pub percent: u32,
21     /// Battery voltage in microvolts.
22     pub voltage: u32,
23     /// Battery current in microamps.
24     pub current: u32,
25     /// Battery charge counter in microampere hours.
26     pub charge_counter: u32,
27     /// Battery full charge counter in microampere hours.
28     pub charge_full: u32,
29 }
30 
31 pub enum BatteryStatus {
32     Unknown,
33     Charging,
34     Discharging,
35     NotCharging,
36 }
37 
38 pub trait CreatePowerMonitorFn:
39     Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
40 {
41 }
42 
43 impl<T> CreatePowerMonitorFn for T where
44     T: Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
45 {
46 }
47 
48 #[cfg(feature = "powerd")]
49 pub mod powerd;
50