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> |
| 9 | |
| 10 | namespace shill { |
| 11 | |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 12 | // This class provides events from the power manager. To use this class, create |
| 13 | // a subclass from PowerManagerProxyDelegate and implement its member functions. |
| 14 | // Call ProxyFactory::CreatePowerManagerProxy() to create an instance of this |
| 15 | // proxy, passing it a pointer to the delegate you created. When an event from |
| 16 | // the power manager is received, your delegate's member function will be |
| 17 | // called. You retain ownership of the delegate and must ensure that the proxy |
| 18 | // is deleted before the delegate. |
| 19 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 20 | class PowerManagerProxyInterface { |
| 21 | public: |
| 22 | virtual ~PowerManagerProxyInterface() {} |
| 23 | |
| 24 | // Sends a request to PowerManager to wait for this RPC client for up to |
| 25 | // |delay_ms| before suspending the system. When initiating suspend, |
| 26 | // PowerManager broadcasts a SuspendDelay signal and suspends the system after |
| 27 | // the maximal registered timeout expires or all registered clients are ready |
| 28 | // to suspend. Clients tell PowerManager that they are ready through the |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 29 | // SuspendReady interface. |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 30 | virtual void RegisterSuspendDelay(uint32 delay_ms) = 0; |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 31 | virtual void UnregisterSuspendDelay() = 0; |
| 32 | virtual void SuspendReady(uint32 sequence_number) = 0; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | // PowerManager signal delegate to be associated with the proxy. |
| 36 | class PowerManagerProxyDelegate { |
| 37 | public: |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 38 | // Possible states broadcast from the powerd_suspend script. |
| 39 | enum SuspendState { |
| 40 | kOn, |
| 41 | kStandby, |
| 42 | kMem, |
| 43 | kDisk, |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 44 | kSuspending, // Internal to shill. |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 45 | // Place new states above kUnknown. |
| 46 | kUnknown |
| 47 | }; |
| 48 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 49 | virtual ~PowerManagerProxyDelegate() {} |
| 50 | |
| 51 | // Broadcasted by PowerManager when it initiates suspend. RPC clients that |
| 52 | // have registered through RegisterSuspendDelay tell PowerManager that they're |
| 53 | // ready to suspend by sending a SuspendReady signal with the same |
| 54 | // |sequence_number|. |
| 55 | virtual void OnSuspendDelay(uint32 sequence_number) = 0; |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 56 | |
| 57 | // This method will be called when suspending or resuming. |new_power_state| |
| 58 | // will be "kMem" when suspending (to memory), or "kOn" when resuming. |
| 59 | virtual void OnPowerStateChanged(SuspendState new_power_state) = 0; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace shill |
| 63 | |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 64 | #endif // SHILL_POWER_MANAGER_PROXY_INTERFACE_H_ |