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_implementation_type.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h" 16 17 namespace dbus { 18 class Bus; 19 } 20 21 namespace power_manager { 22 class PowerManagementPolicy; 23 class PowerSupplyProperties; 24 } 25 26 namespace chromeos { 27 28 typedef base::Callback<void(void)> IdleNotificationCallback; 29 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; 33 34 // PowerManagerClient is used to communicate with the power manager. 35 class CHROMEOS_EXPORT PowerManagerClient { 36 public: 37 // Interface for observing changes from the power manager. 38 class Observer { 39 public: 40 virtual ~Observer() {} 41 42 // Called if the power manager process restarts. 43 virtual void PowerManagerRestarted() {} 44 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) {} 49 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, 57 int level) {} 58 59 // Called when updated information about the power supply is available. 60 // The status is automatically updated periodically, but 61 // RequestStatusUpdate() can be used to trigger an immediate update. 62 virtual void PowerChanged( 63 const power_manager::PowerSupplyProperties& proto) {} 64 65 // Called when we go idle for threshold time. 66 virtual void IdleNotify(int64 threshold_secs) {} 67 68 // Called when the system is about to suspend. Suspend is deferred until 69 // all observers' implementations of this method have finished running. 70 // 71 // If an observer wishes to asynchronously delay suspend, 72 // PowerManagerClient::GetSuspendReadinessCallback() may be called from 73 // within SuspendImminent(). The returned callback must be called once 74 // the observer is ready for suspend. 75 virtual void SuspendImminent() {} 76 77 // Called when the power button is pressed or released. 78 virtual void PowerButtonEventReceived(bool down, 79 const base::TimeTicks& timestamp) {} 80 81 // Called when the device's lid is opened or closed. 82 virtual void LidEventReceived(bool open, 83 const base::TimeTicks& timestamp) {} 84 85 // Called when the system resumes from sleep. 86 virtual void SystemResumed(const base::TimeDelta& sleep_duration) {} 87 88 // Called when the idle action will be performed soon. 89 virtual void IdleActionImminent() {} 90 91 // Called after IdleActionImminent() when the inactivity timer is reset 92 // before the idle action has been performed. 93 virtual void IdleActionDeferred() {} 94 }; 95 96 // Adds and removes the observer. 97 virtual void AddObserver(Observer* observer) = 0; 98 virtual void RemoveObserver(Observer* observer) = 0; 99 virtual bool HasObserver(Observer* observer) = 0; 100 101 // Decreases the screen brightness. |allow_off| controls whether or not 102 // it's allowed to turn off the back light. 103 virtual void DecreaseScreenBrightness(bool allow_off) = 0; 104 105 // Increases the screen brightness. 106 virtual void IncreaseScreenBrightness() = 0; 107 108 // Set the screen brightness to |percent|, in the range [0.0, 100.0]. 109 // If |gradual| is true, the transition will be animated. 110 virtual void SetScreenBrightnessPercent(double percent, bool gradual) = 0; 111 112 // Asynchronously gets the current screen brightness, in the range 113 // [0.0, 100.0]. 114 virtual void GetScreenBrightnessPercent( 115 const GetScreenBrightnessPercentCallback& callback) = 0; 116 117 // Decreases the keyboard brightness. 118 virtual void DecreaseKeyboardBrightness() = 0; 119 120 // Increases the keyboard brightness. 121 virtual void IncreaseKeyboardBrightness() = 0; 122 123 // Requests an updated copy of the power status. Observer::PowerChanged() 124 // will be called asynchronously. 125 virtual void RequestStatusUpdate() = 0; 126 127 // Requests restart of the system. 128 virtual void RequestRestart() = 0; 129 130 // Requests shutdown of the system. 131 virtual void RequestShutdown() = 0; 132 133 // Idle management functions: 134 135 // Requests notification for Idle at a certain threshold. 136 // NOTE: This notification is one shot, once the machine has been idle for 137 // threshold time, a notification will be sent and then that request will be 138 // removed from the notification queue. If you wish notifications the next 139 // time the machine goes idle for that much time, request again. 140 virtual void RequestIdleNotification(int64 threshold_secs) = 0; 141 142 // Notifies the power manager that the user is active (i.e. generating input 143 // events). 144 virtual void NotifyUserActivity(power_manager::UserActivityType type) = 0; 145 146 // Notifies the power manager that a video is currently playing. It also 147 // includes whether or not the containing window for the video is fullscreen. 148 virtual void NotifyVideoActivity(bool is_fullscreen) = 0; 149 150 // Tells the power manager to begin using |policy|. 151 virtual void SetPolicy( 152 const power_manager::PowerManagementPolicy& policy) = 0; 153 154 // Tells powerd whether or not we are in a projecting mode. This is used to 155 // adjust idleness thresholds and derived, on this side, from the number of 156 // video outputs attached. 157 virtual void SetIsProjecting(bool is_projecting) = 0; 158 159 // Returns a callback that can be called by an observer to report 160 // readiness for suspend. See Observer::SuspendImminent(). 161 virtual base::Closure GetSuspendReadinessCallback() = 0; 162 163 // Creates the instance. 164 static PowerManagerClient* Create(DBusClientImplementationType type, 165 dbus::Bus* bus); 166 167 virtual ~PowerManagerClient(); 168 169 protected: 170 // Create() should be used instead. 171 PowerManagerClient(); 172 173 private: 174 DISALLOW_COPY_AND_ASSIGN(PowerManagerClient); 175 }; 176 177 } // namespace chromeos 178 179 #endif // CHROMEOS_DBUS_POWER_MANAGER_CLIENT_H_ 180