mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 5 | #ifndef SHILL_POWER_MANAGER_PROXY_INTERFACE_H_ |
| 6 | #define SHILL_POWER_MANAGER_PROXY_INTERFACE_H_ |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 7 | |
| 8 | #include <base/basictypes.h> |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 9 | #include <base/time.h> |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 10 | |
| 11 | namespace shill { |
| 12 | |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 13 | // This class provides events from the power manager. To use this class, create |
| 14 | // a subclass from PowerManagerProxyDelegate and implement its member functions. |
| 15 | // Call ProxyFactory::CreatePowerManagerProxy() to create an instance of this |
| 16 | // proxy, passing it a pointer to the delegate you created. When an event from |
| 17 | // the power manager is received, your delegate's member function will be |
| 18 | // called. You retain ownership of the delegate and must ensure that the proxy |
| 19 | // is deleted before the delegate. |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 20 | class PowerManagerProxyInterface { |
| 21 | public: |
| 22 | virtual ~PowerManagerProxyInterface() {} |
| 23 | |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 24 | // Sends a request to the power manager to wait for this client for up to |
| 25 | // |timeout| before suspending the system. Assigns an ID corresponding to the |
| 26 | // registered delay to |delay_id_out| and returns true on success. |
| 27 | virtual bool RegisterSuspendDelay(base::TimeDelta timeout, |
| 28 | int *delay_id_out) = 0; |
| 29 | |
| 30 | // Unregisters a previously-registered suspend delay. Returns true on |
| 31 | // success. |
| 32 | virtual bool UnregisterSuspendDelay(int delay_id) = 0; |
| 33 | |
| 34 | // Calls the power manager's HandleSuspendReadiness method. |delay_id| should |
| 35 | // contain the ID returned via RegisterSuspendDelay() and |suspend_id| should |
| 36 | // contain the ID from OnSuspendImminent(). Returns true on success. |
| 37 | virtual bool ReportSuspendReadiness(int delay_id, int suspend_id) = 0; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | // PowerManager signal delegate to be associated with the proxy. |
| 41 | class PowerManagerProxyDelegate { |
| 42 | public: |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 43 | // Possible states broadcast from the powerd_suspend script. |
| 44 | enum SuspendState { |
| 45 | kOn, |
| 46 | kStandby, |
| 47 | kMem, |
| 48 | kDisk, |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 49 | kSuspending, // Internal to shill. |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 50 | // Place new states above kUnknown. |
| 51 | kUnknown |
| 52 | }; |
| 53 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 54 | virtual ~PowerManagerProxyDelegate() {} |
| 55 | |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 56 | // Broadcasted by the power manager when it's about to suspend. RPC clients |
| 57 | // that have registered through RegisterSuspendDelay() should tell the power |
| 58 | // manager that they're ready to suspend by calling ReportSuspendReadiness() |
| 59 | // with the delay ID returned by RegisterSuspendDelay() and |suspend_id|. |
| 60 | virtual void OnSuspendImminent(int suspend_id) = 0; |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 61 | |
| 62 | // This method will be called when suspending or resuming. |new_power_state| |
| 63 | // will be "kMem" when suspending (to memory), or "kOn" when resuming. |
| 64 | virtual void OnPowerStateChanged(SuspendState new_power_state) = 0; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace shill |
| 68 | |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 69 | #endif // SHILL_POWER_MANAGER_PROXY_INTERFACE_H_ |