1 // Copyright (c) 2012 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 #ifndef CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/time/time.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/dbus_client.h"
15 #include "chromeos/dbus/dbus_client_implementation_type.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
18 namespace power_manager
{
19 class PowerManagementPolicy
;
20 class PowerSupplyProperties
;
25 // Callback used for getting the current screen brightness. The param is in the
26 // range [0.0, 100.0].
27 typedef base::Callback
<void(double)> GetScreenBrightnessPercentCallback
;
29 // PowerManagerClient is used to communicate with the power manager.
30 class CHROMEOS_EXPORT PowerManagerClient
: public DBusClient
{
32 // Interface for observing changes from the power manager.
35 virtual ~Observer() {}
37 // Called if the power manager process restarts.
38 virtual void PowerManagerRestarted() {}
40 // Called when the brightness is changed.
41 // |level| is of the range [0, 100].
42 // |user_initiated| is true if the action is initiated by the user.
43 virtual void BrightnessChanged(int level
, bool user_initiated
) {}
45 // Called when peripheral device battery status is received.
46 // |path| is the sysfs path for the battery of the peripheral device.
47 // |name| is the human readble name of the device.
48 // |level| within [0, 100] represents the device battery level and -1
49 // means an unknown level or device is disconnected.
50 virtual void PeripheralBatteryStatusReceived(const std::string
& path
,
51 const std::string
& name
,
54 // Called when updated information about the power supply is available.
55 // The status is automatically updated periodically, but
56 // RequestStatusUpdate() can be used to trigger an immediate update.
57 virtual void PowerChanged(
58 const power_manager::PowerSupplyProperties
& proto
) {}
60 // Called when the system is about to suspend. Suspend is deferred until
61 // all observers' implementations of this method have finished running.
63 // If an observer wishes to asynchronously delay suspend,
64 // PowerManagerClient::GetSuspendReadinessCallback() may be called from
65 // within SuspendImminent(). The returned callback must be called once
66 // the observer is ready for suspend.
67 virtual void SuspendImminent() {}
69 // Called when a suspend attempt (previously announced via
70 // SuspendImminent()) has completed. The system may not have actually
71 // suspended (if e.g. the user canceled the suspend attempt).
72 virtual void SuspendDone(const base::TimeDelta
& sleep_duration
) {}
74 // Called when the system is about to resuspend from a dark resume. Like
75 // SuspendImminent(), the suspend will be deferred until all observers have
76 // finished running and those observers that wish to asynchronously delay
77 // the suspend should call PowerManagerClient::GetSuspendReadinessCallback()
78 // from within this method. The returned callback should be run once the
79 // observer is ready for suspend.
80 virtual void DarkSuspendImminent() {}
82 // Called when the power button is pressed or released.
83 virtual void PowerButtonEventReceived(bool down
,
84 const base::TimeTicks
& timestamp
) {}
86 // Called when the device's lid is opened or closed.
87 virtual void LidEventReceived(bool open
,
88 const base::TimeTicks
& timestamp
) {}
90 // Called when the idle action will be performed after
91 // |time_until_idle_action|.
92 virtual void IdleActionImminent(
93 const base::TimeDelta
& time_until_idle_action
) {}
95 // Called after IdleActionImminent() when the inactivity timer is reset
96 // before the idle action has been performed.
97 virtual void IdleActionDeferred() {}
100 // Adds and removes the observer.
101 virtual void AddObserver(Observer
* observer
) = 0;
102 virtual void RemoveObserver(Observer
* observer
) = 0;
103 virtual bool HasObserver(Observer
* observer
) = 0;
105 // Decreases the screen brightness. |allow_off| controls whether or not
106 // it's allowed to turn off the back light.
107 virtual void DecreaseScreenBrightness(bool allow_off
) = 0;
109 // Increases the screen brightness.
110 virtual void IncreaseScreenBrightness() = 0;
112 // Set the screen brightness to |percent|, in the range [0.0, 100.0].
113 // If |gradual| is true, the transition will be animated.
114 virtual void SetScreenBrightnessPercent(double percent
, bool gradual
) = 0;
116 // Asynchronously gets the current screen brightness, in the range
118 virtual void GetScreenBrightnessPercent(
119 const GetScreenBrightnessPercentCallback
& callback
) = 0;
121 // Decreases the keyboard brightness.
122 virtual void DecreaseKeyboardBrightness() = 0;
124 // Increases the keyboard brightness.
125 virtual void IncreaseKeyboardBrightness() = 0;
127 // Requests an updated copy of the power status. Observer::PowerChanged()
128 // will be called asynchronously.
129 virtual void RequestStatusUpdate() = 0;
131 // Requests restart of the system.
132 virtual void RequestRestart() = 0;
134 // Requests shutdown of the system.
135 virtual void RequestShutdown() = 0;
137 // Notifies the power manager that the user is active (i.e. generating input
139 virtual void NotifyUserActivity(power_manager::UserActivityType type
) = 0;
141 // Notifies the power manager that a video is currently playing. It also
142 // includes whether or not the containing window for the video is fullscreen.
143 virtual void NotifyVideoActivity(bool is_fullscreen
) = 0;
145 // Tells the power manager to begin using |policy|.
146 virtual void SetPolicy(
147 const power_manager::PowerManagementPolicy
& policy
) = 0;
149 // Tells powerd whether or not we are in a projecting mode. This is used to
150 // adjust idleness thresholds and derived, on this side, from the number of
151 // video outputs attached.
152 virtual void SetIsProjecting(bool is_projecting
) = 0;
154 // Returns a callback that can be called by an observer to report
155 // readiness for suspend. See Observer::SuspendImminent().
156 virtual base::Closure
GetSuspendReadinessCallback() = 0;
158 // Returns the number of callbacks returned by GetSuspendReadinessCallback()
159 // for the current suspend attempt but not yet called. Used by tests.
160 virtual int GetNumPendingSuspendReadinessCallbacks() = 0;
162 // Creates the instance.
163 static PowerManagerClient
* Create(DBusClientImplementationType type
);
165 virtual ~PowerManagerClient();
168 // Create() should be used instead.
169 PowerManagerClient();
172 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient
);
175 } // namespace chromeos
177 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_