• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 //! Power monitoring abstraction layer.
6 
7 use std::error::Error;
8 
9 use base::ReadNotifier;
10 
11 pub trait PowerMonitor: ReadNotifier {
read_message(&mut self) -> std::result::Result<Option<PowerData>, Box<dyn Error>>12     fn read_message(&mut self) -> std::result::Result<Option<PowerData>, Box<dyn Error>>;
13 }
14 
15 pub struct PowerData {
16     pub ac_online: bool,
17     pub battery: Option<BatteryData>,
18 }
19 
20 #[derive(Clone, Copy)]
21 pub struct BatteryData {
22     pub status: BatteryStatus,
23     pub percent: u32,
24     /// Battery voltage in microvolts.
25     pub voltage: u32,
26     /// Battery current in microamps.
27     pub current: u32,
28     /// Battery charge counter in microampere hours.
29     pub charge_counter: u32,
30     /// Battery full charge counter in microampere hours.
31     pub charge_full: u32,
32 }
33 
34 #[derive(Clone, Copy)]
35 pub enum BatteryStatus {
36     Unknown,
37     Charging,
38     Discharging,
39     NotCharging,
40 }
41 
42 pub trait CreatePowerMonitorFn:
43     Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
44 {
45 }
46 
47 impl<T> CreatePowerMonitorFn for T where
48     T: Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
49 {
50 }
51 
52 #[cfg(feature = "powerd")]
53 pub mod powerd;
54 
55 mod protos {
56     // ANDROID: b/259142784 - we remove protos subdir b/c cargo2android
57     include!(concat!(env!("OUT_DIR"), "/generated.rs"));
58 }
59