1 # Copyright 2014 The Chromium 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.
5 import telemetry.core.platform.power_monitor as power_monitor
8 class PowerMonitorController(power_monitor.PowerMonitor):
10 PowerMonitor that acts as facade for a list of PowerMonitor objects and uses
11 the first available one.
13 def __init__(self, power_monitors):
14 super(PowerMonitorController, self).__init__()
15 self._cascading_power_monitors = power_monitors
16 self._active_monitor = None
18 def _AsyncPowerMonitor(self):
20 (x for x in self._cascading_power_monitors if x.CanMonitorPowerAsync()),
23 def CanMonitorPowerAsync(self):
24 return bool(self._AsyncPowerMonitor())
26 def StartMonitoringPowerAsync(self):
27 self._active_monitor = self._AsyncPowerMonitor()
28 assert self._active_monitor, 'No available monitor.'
29 self._active_monitor.StartMonitoringPowerAsync()
31 def StopMonitoringPowerAsync(self):
32 assert self._active_monitor, 'StartMonitoringPowerAsync() not called.'
34 return self._active_monitor.StopMonitoringPowerAsync()
36 self._active_monitor = None