blob: e9913557a4a84cc3cb0043d180546216c206141d [file] [log] [blame]
mukesh agrawal7c1fece2012-01-13 11:31:27 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov394b7d42011-11-03 15:48:02 +01002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Darin Petkov3ec55342012-09-28 14:04:44 +02005#ifndef SHILL_POWER_MANAGER_PROXY_INTERFACE_H_
6#define SHILL_POWER_MANAGER_PROXY_INTERFACE_H_
Darin Petkov394b7d42011-11-03 15:48:02 +01007
8#include <base/basictypes.h>
Daniel Erat0818cca2012-12-14 10:16:21 -08009#include <base/time.h>
Darin Petkov394b7d42011-11-03 15:48:02 +010010
11namespace shill {
12
mukesh agrawal7c1fece2012-01-13 11:31:27 -080013// 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 Petkov394b7d42011-11-03 15:48:02 +010020class PowerManagerProxyInterface {
21 public:
22 virtual ~PowerManagerProxyInterface() {}
23
Daniel Erat0818cca2012-12-14 10:16:21 -080024 // 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 Petkov394b7d42011-11-03 15:48:02 +010038};
39
40// PowerManager signal delegate to be associated with the proxy.
41class PowerManagerProxyDelegate {
42 public:
mukesh agrawal7c1fece2012-01-13 11:31:27 -080043 // Possible states broadcast from the powerd_suspend script.
44 enum SuspendState {
45 kOn,
46 kStandby,
47 kMem,
48 kDisk,
Darin Petkov3ec55342012-09-28 14:04:44 +020049 kSuspending, // Internal to shill.
mukesh agrawal7c1fece2012-01-13 11:31:27 -080050 // Place new states above kUnknown.
51 kUnknown
52 };
53
Darin Petkov394b7d42011-11-03 15:48:02 +010054 virtual ~PowerManagerProxyDelegate() {}
55
Daniel Erat0818cca2012-12-14 10:16:21 -080056 // 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 agrawal7c1fece2012-01-13 11:31:27 -080061
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 Petkov394b7d42011-11-03 15:48:02 +010065};
66
67} // namespace shill
68
Darin Petkov3ec55342012-09-28 14:04:44 +020069#endif // SHILL_POWER_MANAGER_PROXY_INTERFACE_H_