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 | |
Daniel Erat | f975367 | 2013-01-24 10:17:02 -0800 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 10 | #include <base/time/time.h> |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 11 | |
| 12 | namespace shill { |
| 13 | |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 14 | // This class provides events from the power manager. To use this class, create |
| 15 | // a subclass from PowerManagerProxyDelegate and implement its member functions. |
| 16 | // Call ProxyFactory::CreatePowerManagerProxy() to create an instance of this |
| 17 | // proxy, passing it a pointer to the delegate you created. When an event from |
| 18 | // the power manager is received, your delegate's member function will be |
| 19 | // called. You retain ownership of the delegate and must ensure that the proxy |
| 20 | // is deleted before the delegate. |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 21 | class PowerManagerProxyInterface { |
| 22 | public: |
| 23 | virtual ~PowerManagerProxyInterface() {} |
| 24 | |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 25 | // Sends a request to the power manager to wait for this client for up to |
Daniel Erat | f975367 | 2013-01-24 10:17:02 -0800 | [diff] [blame] | 26 | // |timeout| before suspending the system. |description| is a |
| 27 | // human-readable string describing the delay's purpose. Assigns an ID |
| 28 | // corresponding to the registered delay to |delay_id_out| and returns |
| 29 | // true on success. |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 30 | virtual bool RegisterSuspendDelay(base::TimeDelta timeout, |
Daniel Erat | f975367 | 2013-01-24 10:17:02 -0800 | [diff] [blame] | 31 | const std::string &description, |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 32 | int *delay_id_out) = 0; |
| 33 | |
| 34 | // Unregisters a previously-registered suspend delay. Returns true on |
| 35 | // success. |
| 36 | virtual bool UnregisterSuspendDelay(int delay_id) = 0; |
| 37 | |
| 38 | // Calls the power manager's HandleSuspendReadiness method. |delay_id| should |
| 39 | // contain the ID returned via RegisterSuspendDelay() and |suspend_id| should |
| 40 | // contain the ID from OnSuspendImminent(). Returns true on success. |
| 41 | virtual bool ReportSuspendReadiness(int delay_id, int suspend_id) = 0; |
Prathmesh Prabhu | 64ad238 | 2014-08-26 11:19:30 -0700 | [diff] [blame] | 42 | |
| 43 | // Sends a request to the power manager to wait for this client for up to |
| 44 | // |timeout| before suspending the system from a dark resume. Arguments |
| 45 | // are as explained for |RegisterSuspendDelay|. Returns true on success. |
| 46 | virtual bool RegisterDarkSuspendDelay(base::TimeDelta timeout, |
| 47 | const std::string &description, |
| 48 | int *delay_id_out) = 0; |
| 49 | |
| 50 | // Unregisters a previously-registered dark suspend delay. Returns true on |
| 51 | // success. |
| 52 | virtual bool UnregisterDarkSuspendDelay(int delay_id) = 0; |
| 53 | |
| 54 | // Calls the power manager's HandleDarkSuspendReadiness method. Arguments are |
| 55 | // as explained for ReportSuspendReadiness. Returns true on success. |
| 56 | virtual bool ReportDarkSuspendReadiness(int delay_id, int suspend_id) = 0; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | // PowerManager signal delegate to be associated with the proxy. |
| 60 | class PowerManagerProxyDelegate { |
| 61 | public: |
| 62 | virtual ~PowerManagerProxyDelegate() {} |
| 63 | |
Prathmesh Prabhu | 64ad238 | 2014-08-26 11:19:30 -0700 | [diff] [blame] | 64 | // Broadcast by the power manager when it's about to suspend. Delegates |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 65 | // that have registered through RegisterSuspendDelay() should tell the power |
| 66 | // manager that they're ready to suspend by calling ReportSuspendReadiness() |
| 67 | // with the delay ID returned by RegisterSuspendDelay() and |suspend_id|. |
| 68 | virtual void OnSuspendImminent(int suspend_id) = 0; |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 69 | |
Daniel Erat | fac0953 | 2014-04-17 20:25:59 -0700 | [diff] [blame] | 70 | // Broadcast by the power manager when a suspend attempt has completed. |
| 71 | virtual void OnSuspendDone(int suspend_id) = 0; |
Prathmesh Prabhu | 64ad238 | 2014-08-26 11:19:30 -0700 | [diff] [blame] | 72 | |
| 73 | // Broadcast by the power manager when the system enters dark resume. |
| 74 | // Delegates that have registered through RegisterDarkSuspendDelay() should |
| 75 | // tell the power manager when they are ready to suspend from the dark resume |
| 76 | // by calling ReportDarkSuspendResume() with the delay ID returned by |
| 77 | // RegisterDarkSuspendDelay() and |suspend_id|. |
| 78 | virtual void OnDarkSuspendImminent(int suspend_id) = 0; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // namespace shill |
| 82 | |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 83 | #endif // SHILL_POWER_MANAGER_PROXY_INTERFACE_H_ |