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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 197 |
181 // Tells powerd whether or not we are in a projecting mode. This is used to | 198 // 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 | 199 // adjust idleness thresholds and derived, on this side, from the number of |
183 // video outputs attached. | 200 // video outputs attached. |
184 virtual void SetIsProjecting(bool is_projecting) = 0; | 201 virtual void SetIsProjecting(bool is_projecting) = 0; |
185 | 202 |
186 // Tells powerd to change the power source to the given ID. An empty string | 203 // 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. | 204 // causes powerd to switch to using the battery on devices with type-C ports. |
188 virtual void SetPowerSource(const std::string& id) = 0; | 205 virtual void SetPowerSource(const std::string& id) = 0; |
189 | 206 |
190 // Forces the display and keyboard backlights (if present) to |forced_off|. | 207 // Forces the display and (if present) keyboard backlights to |forced_off|. |
191 virtual void SetBacklightsForcedOff(bool forced_off) = 0; | 208 virtual void SetBacklightsForcedOff(bool forced_off) = 0; |
192 | 209 |
193 // Gets the display and keyboard backlights (if present) forced off state. | 210 // Gets the display and (if present) keyboard backlights' forced-off state. |
194 virtual void GetBacklightsForcedOff( | 211 virtual void GetBacklightsForcedOff( |
195 const GetBacklightsForcedOffCallback& callback) = 0; | 212 const GetBacklightsForcedOffCallback& callback) = 0; |
196 | 213 |
| 214 // Asynchronously fetches the current state of various hardware switches (e.g. |
| 215 // the lid switch and the tablet-mode switch). |
| 216 virtual void GetSwitchStates(const GetSwitchStatesCallback& callback) = 0; |
| 217 |
197 // Returns a callback that can be called by an observer to report | 218 // Returns a callback that can be called by an observer to report |
198 // readiness for suspend. See Observer::SuspendImminent(). | 219 // readiness for suspend. See Observer::SuspendImminent(). |
199 virtual base::Closure GetSuspendReadinessCallback() = 0; | 220 virtual base::Closure GetSuspendReadinessCallback() = 0; |
200 | 221 |
201 // Returns the number of callbacks returned by GetSuspendReadinessCallback() | 222 // Returns the number of callbacks returned by GetSuspendReadinessCallback() |
202 // for the current suspend attempt but not yet called. Used by tests. | 223 // for the current suspend attempt but not yet called. Used by tests. |
203 virtual int GetNumPendingSuspendReadinessCallbacks() = 0; | 224 virtual int GetNumPendingSuspendReadinessCallbacks() = 0; |
204 | 225 |
205 // Creates the instance. | 226 // Creates the instance. |
206 static PowerManagerClient* Create(DBusClientImplementationType type); | 227 static PowerManagerClient* Create(DBusClientImplementationType type); |
207 | 228 |
208 ~PowerManagerClient() override; | 229 ~PowerManagerClient() override; |
209 | 230 |
210 protected: | 231 protected: |
211 // Needs to call DBusClient::Init(). | 232 // Needs to call DBusClient::Init(). |
212 friend class PowerManagerClientTest; | 233 friend class PowerManagerClientTest; |
213 | 234 |
214 // Create() should be used instead. | 235 // Create() should be used instead. |
215 PowerManagerClient(); | 236 PowerManagerClient(); |
216 | 237 |
217 private: | 238 private: |
218 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient); | 239 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient); |
219 }; | 240 }; |
220 | 241 |
221 } // namespace chromeos | 242 } // namespace chromeos |
222 | 243 |
223 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ | 244 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ |
OLD | NEW |