blob: 31e484c1941040557dbd31371ab913efadf04c25 [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
Daniel Eratf9753672013-01-24 10:17:02 -08008#include <string>
9
Darin Petkov394b7d42011-11-03 15:48:02 +010010#include <base/basictypes.h>
Daniel Erat0818cca2012-12-14 10:16:21 -080011#include <base/time.h>
Darin Petkov394b7d42011-11-03 15:48:02 +010012
13namespace shill {
14
mukesh agrawal7c1fece2012-01-13 11:31:27 -080015// This class provides events from the power manager. To use this class, create
16// a subclass from PowerManagerProxyDelegate and implement its member functions.
17// Call ProxyFactory::CreatePowerManagerProxy() to create an instance of this
18// proxy, passing it a pointer to the delegate you created. When an event from
19// the power manager is received, your delegate's member function will be
20// called. You retain ownership of the delegate and must ensure that the proxy
21// is deleted before the delegate.
Darin Petkov394b7d42011-11-03 15:48:02 +010022class PowerManagerProxyInterface {
23 public:
24 virtual ~PowerManagerProxyInterface() {}
25
Daniel Erat0818cca2012-12-14 10:16:21 -080026 // Sends a request to the power manager to wait for this client for up to
Daniel Eratf9753672013-01-24 10:17:02 -080027 // |timeout| before suspending the system. |description| is a
28 // human-readable string describing the delay's purpose. Assigns an ID
29 // corresponding to the registered delay to |delay_id_out| and returns
30 // true on success.
Daniel Erat0818cca2012-12-14 10:16:21 -080031 virtual bool RegisterSuspendDelay(base::TimeDelta timeout,
Daniel Eratf9753672013-01-24 10:17:02 -080032 const std::string &description,
Daniel Erat0818cca2012-12-14 10:16:21 -080033 int *delay_id_out) = 0;
34
35 // Unregisters a previously-registered suspend delay. Returns true on
36 // success.
37 virtual bool UnregisterSuspendDelay(int delay_id) = 0;
38
39 // Calls the power manager's HandleSuspendReadiness method. |delay_id| should
40 // contain the ID returned via RegisterSuspendDelay() and |suspend_id| should
41 // contain the ID from OnSuspendImminent(). Returns true on success.
42 virtual bool ReportSuspendReadiness(int delay_id, int suspend_id) = 0;
Darin Petkov394b7d42011-11-03 15:48:02 +010043};
44
45// PowerManager signal delegate to be associated with the proxy.
46class PowerManagerProxyDelegate {
47 public:
mukesh agrawal7c1fece2012-01-13 11:31:27 -080048 // Possible states broadcast from the powerd_suspend script.
49 enum SuspendState {
50 kOn,
51 kStandby,
52 kMem,
53 kDisk,
Darin Petkov3ec55342012-09-28 14:04:44 +020054 kSuspending, // Internal to shill.
mukesh agrawal7c1fece2012-01-13 11:31:27 -080055 // Place new states above kUnknown.
56 kUnknown
57 };
58
Darin Petkov394b7d42011-11-03 15:48:02 +010059 virtual ~PowerManagerProxyDelegate() {}
60
Daniel Erat0818cca2012-12-14 10:16:21 -080061 // Broadcasted by the power manager when it's about to suspend. RPC clients
62 // that have registered through RegisterSuspendDelay() should tell the power
63 // manager that they're ready to suspend by calling ReportSuspendReadiness()
64 // with the delay ID returned by RegisterSuspendDelay() and |suspend_id|.
65 virtual void OnSuspendImminent(int suspend_id) = 0;
mukesh agrawal7c1fece2012-01-13 11:31:27 -080066
67 // This method will be called when suspending or resuming. |new_power_state|
68 // will be "kMem" when suspending (to memory), or "kOn" when resuming.
69 virtual void OnPowerStateChanged(SuspendState new_power_state) = 0;
Darin Petkov394b7d42011-11-03 15:48:02 +010070};
71
72} // namespace shill
73
Darin Petkov3ec55342012-09-28 14:04:44 +020074#endif // SHILL_POWER_MANAGER_PROXY_INTERFACE_H_