OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ | 5 #ifndef CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ |
6 #define CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ | 6 #define CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
15 #include "chromeos/dbus/dbus_client.h" | 15 #include "chromeos/dbus/dbus_client.h" |
16 #include "chromeos/dbus/dbus_client_implementation_type.h" | 16 #include "chromeos/dbus/dbus_client_implementation_type.h" |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
18 | 18 |
19 namespace power_manager { | 19 namespace power_manager { |
20 class PowerManagementPolicy; | 20 class PowerManagementPolicy; |
21 class PowerSupplyProperties; | 21 class PowerSupplyProperties; |
22 } | 22 } |
23 | 23 |
24 namespace chromeos { | 24 namespace chromeos { |
25 | 25 |
26 // Callback used for getting the current screen brightness. The param is in the | |
27 // range [0.0, 100.0]. | |
28 typedef base::Callback<void(double)> GetScreenBrightnessPercentCallback; | |
29 | |
30 // Callback used for getting the current backlights forced off state. | |
31 typedef base::Callback<void(bool)> GetBacklightsForcedOffCallback; | |
32 | |
33 // PowerManagerClient is used to communicate with the power manager. | 26 // PowerManagerClient is used to communicate with the power manager. |
34 class CHROMEOS_EXPORT PowerManagerClient : public DBusClient { | 27 class CHROMEOS_EXPORT PowerManagerClient : public DBusClient { |
35 public: | 28 public: |
| 29 enum class LidState { |
| 30 OPEN, |
| 31 CLOSED, |
| 32 NOT_PRESENT, |
| 33 }; |
| 34 |
| 35 enum class TabletMode { |
| 36 ON, |
| 37 OFF, |
| 38 UNSUPPORTED, |
| 39 }; |
| 40 |
| 41 // Callback used for getting the current screen brightness. The param is in |
| 42 // the range [0.0, 100.0]. |
| 43 typedef base::Callback<void(double)> GetScreenBrightnessPercentCallback; |
| 44 |
| 45 // Callback passed to GetBacklightsForcedOff(). |
| 46 typedef base::Callback<void(bool forced_off)> GetBacklightsForcedOffCallback; |
| 47 |
| 48 // Callback passed to GetSwitchStates(). |
| 49 typedef base::Callback<void(LidState, TabletMode)> GetSwitchStatesCallback; |
| 50 |
36 // Interface for observing changes from the power manager. | 51 // Interface for observing changes from the power manager. |
37 class Observer { | 52 class Observer { |
38 public: | 53 public: |
39 virtual ~Observer() {} | 54 virtual ~Observer() {} |
40 | 55 |
41 // Called if the power manager process restarts. | 56 // Called if the power manager process restarts. |
42 virtual void PowerManagerRestarted() {} | 57 virtual void PowerManagerRestarted() {} |
43 | 58 |
44 // Called when the brightness is changed. | 59 // Called when the brightness is changed. |
45 // |level| is of the range [0, 100]. | 60 // |level| is of the range [0, 100]. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // finished running and those observers that wish to asynchronously delay | 95 // finished running and those observers that wish to asynchronously delay |
81 // the suspend should call PowerManagerClient::GetSuspendReadinessCallback() | 96 // the suspend should call PowerManagerClient::GetSuspendReadinessCallback() |
82 // from within this method. The returned callback should be run once the | 97 // from within this method. The returned callback should be run once the |
83 // observer is ready for suspend. | 98 // observer is ready for suspend. |
84 virtual void DarkSuspendImminent() {} | 99 virtual void DarkSuspendImminent() {} |
85 | 100 |
86 // Called when the power button is pressed or released. | 101 // Called when the power button is pressed or released. |
87 virtual void PowerButtonEventReceived(bool down, | 102 virtual void PowerButtonEventReceived(bool down, |
88 const base::TimeTicks& timestamp) {} | 103 const base::TimeTicks& timestamp) {} |
89 | 104 |
90 // Called when the device's lid is opened or closed. | 105 // Called when the device's lid is opened or closed. LidState::NOT_PRESENT |
91 virtual void LidEventReceived(bool open, | 106 // is never passed. |
| 107 virtual void LidEventReceived(LidState state, |
92 const base::TimeTicks& timestamp) {} | 108 const base::TimeTicks& timestamp) {} |
93 | 109 |
94 // Called when the device's tablet mode switch is on or off. | 110 // Called when the device's tablet mode switch is on or off. |
95 virtual void TabletModeEventReceived(bool on, | 111 // TabletMode::UNSUPPORTED is never passed. |
| 112 virtual void TabletModeEventReceived(TabletMode mode, |
96 const base::TimeTicks& timestamp) {} | 113 const base::TimeTicks& timestamp) {} |
97 | 114 |
98 // Called when the idle action will be performed after | 115 // Called when the idle action will be performed after |
99 // |time_until_idle_action|. | 116 // |time_until_idle_action|. |
100 virtual void IdleActionImminent( | 117 virtual void IdleActionImminent( |
101 const base::TimeDelta& time_until_idle_action) {} | 118 const base::TimeDelta& time_until_idle_action) {} |
102 | 119 |
103 // Called after IdleActionImminent() when the inactivity timer is reset | 120 // Called after IdleActionImminent() when the inactivity timer is reset |
104 // before the idle action has been performed. | 121 // before the idle action has been performed. |
105 virtual void IdleActionDeferred() {} | 122 virtual void IdleActionDeferred() {} |
(...skipping 30 matching lines...) Expand all Loading... |
136 virtual void DecreaseScreenBrightness(bool allow_off) = 0; | 153 virtual void DecreaseScreenBrightness(bool allow_off) = 0; |
137 | 154 |
138 // Increases the screen brightness. | 155 // Increases the screen brightness. |
139 virtual void IncreaseScreenBrightness() = 0; | 156 virtual void IncreaseScreenBrightness() = 0; |
140 | 157 |
141 // Set the screen brightness to |percent|, in the range [0.0, 100.0]. | 158 // Set the screen brightness to |percent|, in the range [0.0, 100.0]. |
142 // If |gradual| is true, the transition will be animated. | 159 // If |gradual| is true, the transition will be animated. |
143 virtual void SetScreenBrightnessPercent(double percent, bool gradual) = 0; | 160 virtual void SetScreenBrightnessPercent(double percent, bool gradual) = 0; |
144 | 161 |
145 // Asynchronously gets the current screen brightness, in the range | 162 // Asynchronously gets the current screen brightness, in the range |
146 // [0.0, 100.0]. | 163 // [0.0, 100.0]. On error (e.g. powerd not running), |callback| will not be |
| 164 // run. |
147 virtual void GetScreenBrightnessPercent( | 165 virtual void GetScreenBrightnessPercent( |
148 const GetScreenBrightnessPercentCallback& callback) = 0; | 166 const GetScreenBrightnessPercentCallback& callback) = 0; |
149 | 167 |
150 // Decreases the keyboard brightness. | 168 // Decreases the keyboard brightness. |
151 virtual void DecreaseKeyboardBrightness() = 0; | 169 virtual void DecreaseKeyboardBrightness() = 0; |
152 | 170 |
153 // Increases the keyboard brightness. | 171 // Increases the keyboard brightness. |
154 virtual void IncreaseKeyboardBrightness() = 0; | 172 virtual void IncreaseKeyboardBrightness() = 0; |
155 | 173 |
156 // Requests an updated copy of the power status. Observer::PowerChanged() | 174 // Requests an updated copy of the power status. Observer::PowerChanged() |
(...skipping 23 matching lines...) Expand all Loading... |
180 | 198 |
181 // Tells powerd whether or not we are in a projecting mode. This is used to | 199 // Tells powerd whether or not we are in a projecting mode. This is used to |
182 // adjust idleness thresholds and derived, on this side, from the number of | 200 // adjust idleness thresholds and derived, on this side, from the number of |
183 // video outputs attached. | 201 // video outputs attached. |
184 virtual void SetIsProjecting(bool is_projecting) = 0; | 202 virtual void SetIsProjecting(bool is_projecting) = 0; |
185 | 203 |
186 // Tells powerd to change the power source to the given ID. An empty string | 204 // Tells powerd to change the power source to the given ID. An empty string |
187 // causes powerd to switch to using the battery on devices with type-C ports. | 205 // causes powerd to switch to using the battery on devices with type-C ports. |
188 virtual void SetPowerSource(const std::string& id) = 0; | 206 virtual void SetPowerSource(const std::string& id) = 0; |
189 | 207 |
190 // Forces the display and keyboard backlights (if present) to |forced_off|. | 208 // Forces the display and (if present) keyboard backlights to |forced_off|. |
191 virtual void SetBacklightsForcedOff(bool forced_off) = 0; | 209 virtual void SetBacklightsForcedOff(bool forced_off) = 0; |
192 | 210 |
193 // Gets the display and keyboard backlights (if present) forced off state. | 211 // Gets the display and (if present) keyboard backlights' forced-off state. On |
| 212 // error (e.g. powerd not running), |callback| will not be run. |
194 virtual void GetBacklightsForcedOff( | 213 virtual void GetBacklightsForcedOff( |
195 const GetBacklightsForcedOffCallback& callback) = 0; | 214 const GetBacklightsForcedOffCallback& callback) = 0; |
196 | 215 |
| 216 // Asynchronously fetches the current state of various hardware switches (e.g. |
| 217 // the lid switch and the tablet-mode switch). On error (e.g. powerd not |
| 218 // running), |callback| will not be run. |
| 219 virtual void GetSwitchStates(const GetSwitchStatesCallback& callback) = 0; |
| 220 |
197 // Returns a callback that can be called by an observer to report | 221 // Returns a callback that can be called by an observer to report |
198 // readiness for suspend. See Observer::SuspendImminent(). | 222 // readiness for suspend. See Observer::SuspendImminent(). |
199 virtual base::Closure GetSuspendReadinessCallback() = 0; | 223 virtual base::Closure GetSuspendReadinessCallback() = 0; |
200 | 224 |
201 // Returns the number of callbacks returned by GetSuspendReadinessCallback() | 225 // Returns the number of callbacks returned by GetSuspendReadinessCallback() |
202 // for the current suspend attempt but not yet called. Used by tests. | 226 // for the current suspend attempt but not yet called. Used by tests. |
203 virtual int GetNumPendingSuspendReadinessCallbacks() = 0; | 227 virtual int GetNumPendingSuspendReadinessCallbacks() = 0; |
204 | 228 |
205 // Creates the instance. | 229 // Creates the instance. |
206 static PowerManagerClient* Create(DBusClientImplementationType type); | 230 static PowerManagerClient* Create(DBusClientImplementationType type); |
207 | 231 |
208 ~PowerManagerClient() override; | 232 ~PowerManagerClient() override; |
209 | 233 |
210 protected: | 234 protected: |
211 // Needs to call DBusClient::Init(). | 235 // Needs to call DBusClient::Init(). |
212 friend class PowerManagerClientTest; | 236 friend class PowerManagerClientTest; |
213 | 237 |
214 // Create() should be used instead. | 238 // Create() should be used instead. |
215 PowerManagerClient(); | 239 PowerManagerClient(); |
216 | 240 |
217 private: | 241 private: |
218 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient); | 242 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient); |
219 }; | 243 }; |
220 | 244 |
221 } // namespace chromeos | 245 } // namespace chromeos |
222 | 246 |
223 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ | 247 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ |
OLD | NEW |