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. 4 5 #ifndef CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ 6 #define CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ 7 8 #include <string> 9 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" 17 18 namespace power_manager { 19 class PowerManagementPolicy; 20 class PowerSupplyProperties; 21 } 22 23 namespace chromeos { 24 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; 28 29 // PowerManagerClient is used to communicate with the power manager. 30 class CHROMEOS_EXPORT PowerManagerClient : public DBusClient { 31 public: 32 // Interface for observing changes from the power manager. 33 class Observer { 34 public: 35 virtual ~Observer() {} 36 37 // Called if the power manager process restarts. 38 virtual void PowerManagerRestarted() {} 39 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) {} 44 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, 52 int level) {} 53 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) {} 59 60 // Called when the system is about to suspend. Suspend is deferred until 61 // all observers' implementations of this method have finished running. 62 // 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() {} 68 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) {} 73 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() {} 81 82 // Called when the power button is pressed or released. 83 virtual void PowerButtonEventReceived(bool down, 84 const base::TimeTicks& timestamp) {} 85 86 // Called when the device's lid is opened or closed. 87 virtual void LidEventReceived(bool open, 88 const base::TimeTicks& timestamp) {} 89 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) {} 94 95 // Called after IdleActionImminent() when the inactivity timer is reset 96 // before the idle action has been performed. 97 virtual void IdleActionDeferred() {} 98 }; 99 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; 104 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; 108 109 // Increases the screen brightness. 110 virtual void IncreaseScreenBrightness() = 0; 111 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; 115 116 // Asynchronously gets the current screen brightness, in the range 117 // [0.0, 100.0]. 118 virtual void GetScreenBrightnessPercent( 119 const GetScreenBrightnessPercentCallback& callback) = 0; 120 121 // Decreases the keyboard brightness. 122 virtual void DecreaseKeyboardBrightness() = 0; 123 124 // Increases the keyboard brightness. 125 virtual void IncreaseKeyboardBrightness() = 0; 126 127 // Requests an updated copy of the power status. Observer::PowerChanged() 128 // will be called asynchronously. 129 virtual void RequestStatusUpdate() = 0; 130 131 // Requests suspend of the system. 132 virtual void RequestSuspend() = 0; 133 134 // Requests restart of the system. 135 virtual void RequestRestart() = 0; 136 137 // Requests shutdown of the system. 138 virtual void RequestShutdown() = 0; 139 140 // Notifies the power manager that the user is active (i.e. generating input 141 // events). 142 virtual void NotifyUserActivity(power_manager::UserActivityType type) = 0; 143 144 // Notifies the power manager that a video is currently playing. It also 145 // includes whether or not the containing window for the video is fullscreen. 146 virtual void NotifyVideoActivity(bool is_fullscreen) = 0; 147 148 // Tells the power manager to begin using |policy|. 149 virtual void SetPolicy( 150 const power_manager::PowerManagementPolicy& policy) = 0; 151 152 // Tells powerd whether or not we are in a projecting mode. This is used to 153 // adjust idleness thresholds and derived, on this side, from the number of 154 // video outputs attached. 155 virtual void SetIsProjecting(bool is_projecting) = 0; 156 157 // Returns a callback that can be called by an observer to report 158 // readiness for suspend. See Observer::SuspendImminent(). 159 virtual base::Closure GetSuspendReadinessCallback() = 0; 160 161 // Returns the number of callbacks returned by GetSuspendReadinessCallback() 162 // for the current suspend attempt but not yet called. Used by tests. 163 virtual int GetNumPendingSuspendReadinessCallbacks() = 0; 164 165 // Creates the instance. 166 static PowerManagerClient* Create(DBusClientImplementationType type); 167 168 virtual ~PowerManagerClient(); 169 170 protected: 171 // Create() should be used instead. 172 PowerManagerClient(); 173 174 private: 175 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient); 176 }; 177 178 } // namespace chromeos 179 180 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ 181