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.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/dbus_client_implementation_type.h"
16 #include "chromeos/dbus/power_supply_status.h"
22 namespace power_manager
{
23 class PowerManagementPolicy
;
28 typedef base::Callback
<void(void)> IdleNotificationCallback
;
30 // Callback used for getting the current screen brightness. The param is in the
31 // range [0.0, 100.0].
32 typedef base::Callback
<void(double)> GetScreenBrightnessPercentCallback
;
34 // PowerManagerClient is used to communicate with the power manager.
35 class CHROMEOS_EXPORT PowerManagerClient
{
37 // Interface for observing changes from the power manager.
40 virtual ~Observer() {}
42 // Called if the power manager process restarts.
43 virtual void PowerManagerRestarted() {}
45 // Called when the brightness is changed.
46 // |level| is of the range [0, 100].
47 // |user_initiated| is true if the action is initiated by the user.
48 virtual void BrightnessChanged(int level
, bool user_initiated
) {}
50 // Called when peripheral device battery status is received.
51 // |path| is the sysfs path for the battery of the peripheral device.
52 // |name| is the human readble name of the device.
53 // |level| within [0, 100] represents the device battery level and -1
54 // means an unknown level or device is disconnected.
55 virtual void PeripheralBatteryStatusReceived(const std::string
& path
,
56 const std::string
& name
,
59 // Called when power supply polling takes place. |status| is a data
60 // structure that contains the current state of the power supply.
61 virtual void PowerChanged(const PowerSupplyStatus
& status
) {}
63 // Called when we go idle for threshold time.
64 virtual void IdleNotify(int64 threshold_secs
) {}
66 // Called when the system is about to suspend. Suspend is deferred until
67 // all observers' implementations of this method have finished running.
69 // If an observer wishes to asynchronously delay suspend,
70 // PowerManagerClient::GetSuspendReadinessCallback() may be called from
71 // within SuspendImminent(). The returned callback must be called once
72 // the observer is ready for suspend.
73 virtual void SuspendImminent() {}
75 // Called when the power button is pressed or released.
76 virtual void PowerButtonEventReceived(bool down
,
77 const base::TimeTicks
& timestamp
) {}
79 // Called when the device's lid is opened or closed.
80 virtual void LidEventReceived(bool open
,
81 const base::TimeTicks
& timestamp
) {}
83 // Called when the system resumes from sleep.
84 virtual void SystemResumed(const base::TimeDelta
& sleep_duration
) {}
86 // Called when the idle action will be performed soon.
87 virtual void IdleActionImminent() {}
89 // Called after IdleActionImminent() when the inactivity timer is reset
90 // before the idle action has been performed.
91 virtual void IdleActionDeferred() {}
94 enum UpdateRequestType
{
95 UPDATE_INITIAL
, // Initial update request.
96 UPDATE_USER
, // User initialted update request.
97 UPDATE_POLL
// Update requested by poll signal.
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 // Request for power supply status update.
128 virtual void RequestStatusUpdate(UpdateRequestType update_type
) = 0;
130 // Requests restart of the system.
131 virtual void RequestRestart() = 0;
133 // Requests shutdown of the system.
134 virtual void RequestShutdown() = 0;
136 // Idle management functions:
138 // Requests notification for Idle at a certain threshold.
139 // NOTE: This notification is one shot, once the machine has been idle for
140 // threshold time, a notification will be sent and then that request will be
141 // removed from the notification queue. If you wish notifications the next
142 // time the machine goes idle for that much time, request again.
143 virtual void RequestIdleNotification(int64 threshold_secs
) = 0;
145 // Notifies the power manager that the user is active (i.e. generating input
147 virtual void NotifyUserActivity() = 0;
149 // Notifies the power manager that a video is currently playing. It also
150 // includes whether or not the containing window for the video is fullscreen.
151 virtual void NotifyVideoActivity(
152 const base::TimeTicks
& last_activity_time
,
153 bool is_fullscreen
) = 0;
155 // Tells the power manager to begin using |policy|.
156 virtual void SetPolicy(
157 const power_manager::PowerManagementPolicy
& policy
) = 0;
159 // Tells powerd whether or not we are in a projecting mode. This is used to
160 // adjust idleness thresholds and derived, on this side, from the number of
161 // video outputs attached.
162 virtual void SetIsProjecting(bool is_projecting
) = 0;
164 // Returns a callback that can be called by an observer to report
165 // readiness for suspend. See Observer::SuspendImminent().
166 virtual base::Closure
GetSuspendReadinessCallback() = 0;
168 // Creates the instance.
169 static PowerManagerClient
* Create(DBusClientImplementationType type
,
172 virtual ~PowerManagerClient();
175 // Create() should be used instead.
176 PowerManagerClient();
179 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient
);
182 } // namespace chromeos
184 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_