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: ~Observer()35 virtual ~Observer() {} 36 37 // Called if the power manager process restarts. PowerManagerRestarted()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. BrightnessChanged(int level,bool user_initiated)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. PeripheralBatteryStatusReceived(const std::string & path,const std::string & name,int level)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. PowerChanged(const power_manager::PowerSupplyProperties & proto)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. SuspendImminent()67 virtual void SuspendImminent() {} 68 69 // Called when the power button is pressed or released. PowerButtonEventReceived(bool down,const base::TimeTicks & timestamp)70 virtual void PowerButtonEventReceived(bool down, 71 const base::TimeTicks& timestamp) {} 72 73 // Called when the device's lid is opened or closed. LidEventReceived(bool open,const base::TimeTicks & timestamp)74 virtual void LidEventReceived(bool open, 75 const base::TimeTicks& timestamp) {} 76 77 // Called when the system resumes from sleep. SystemResumed(const base::TimeDelta & sleep_duration)78 virtual void SystemResumed(const base::TimeDelta& sleep_duration) {} 79 80 // Called when the idle action will be performed soon. IdleActionImminent()81 virtual void IdleActionImminent() {} 82 83 // Called after IdleActionImminent() when the inactivity timer is reset 84 // before the idle action has been performed. IdleActionDeferred()85 virtual void IdleActionDeferred() {} 86 }; 87 88 // Adds and removes the observer. 89 virtual void AddObserver(Observer* observer) = 0; 90 virtual void RemoveObserver(Observer* observer) = 0; 91 virtual bool HasObserver(Observer* observer) = 0; 92 93 // Decreases the screen brightness. |allow_off| controls whether or not 94 // it's allowed to turn off the back light. 95 virtual void DecreaseScreenBrightness(bool allow_off) = 0; 96 97 // Increases the screen brightness. 98 virtual void IncreaseScreenBrightness() = 0; 99 100 // Set the screen brightness to |percent|, in the range [0.0, 100.0]. 101 // If |gradual| is true, the transition will be animated. 102 virtual void SetScreenBrightnessPercent(double percent, bool gradual) = 0; 103 104 // Asynchronously gets the current screen brightness, in the range 105 // [0.0, 100.0]. 106 virtual void GetScreenBrightnessPercent( 107 const GetScreenBrightnessPercentCallback& callback) = 0; 108 109 // Decreases the keyboard brightness. 110 virtual void DecreaseKeyboardBrightness() = 0; 111 112 // Increases the keyboard brightness. 113 virtual void IncreaseKeyboardBrightness() = 0; 114 115 // Requests an updated copy of the power status. Observer::PowerChanged() 116 // will be called asynchronously. 117 virtual void RequestStatusUpdate() = 0; 118 119 // Requests restart of the system. 120 virtual void RequestRestart() = 0; 121 122 // Requests shutdown of the system. 123 virtual void RequestShutdown() = 0; 124 125 // Notifies the power manager that the user is active (i.e. generating input 126 // events). 127 virtual void NotifyUserActivity(power_manager::UserActivityType type) = 0; 128 129 // Notifies the power manager that a video is currently playing. It also 130 // includes whether or not the containing window for the video is fullscreen. 131 virtual void NotifyVideoActivity(bool is_fullscreen) = 0; 132 133 // Tells the power manager to begin using |policy|. 134 virtual void SetPolicy( 135 const power_manager::PowerManagementPolicy& policy) = 0; 136 137 // Tells powerd whether or not we are in a projecting mode. This is used to 138 // adjust idleness thresholds and derived, on this side, from the number of 139 // video outputs attached. 140 virtual void SetIsProjecting(bool is_projecting) = 0; 141 142 // Returns a callback that can be called by an observer to report 143 // readiness for suspend. See Observer::SuspendImminent(). 144 virtual base::Closure GetSuspendReadinessCallback() = 0; 145 146 // Returns the number of callbacks returned by GetSuspendReadinessCallback() 147 // for the current suspend attempt but not yet called. Used by tests. 148 virtual int GetNumPendingSuspendReadinessCallbacks() = 0; 149 150 // Creates the instance. 151 static PowerManagerClient* Create(DBusClientImplementationType type); 152 153 virtual ~PowerManagerClient(); 154 155 protected: 156 // Create() should be used instead. 157 PowerManagerClient(); 158 159 private: 160 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient); 161 }; 162 163 } // namespace chromeos 164 165 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ 166