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