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 | |
| 5 | #ifndef SHILL_POWER_MANAGER_PROXY_ |
| 6 | #define SHILL_POWER_MANAGER_PROXY_ |
| 7 | |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 8 | // An implementation of PowerManagerProxyInterface. It connects to the dbus and |
| 9 | // listens for events from the power manager. When they occur, the delegate's |
| 10 | // member functions are called. |
| 11 | |
| 12 | // Do not instantiate this class directly. use |
| 13 | // ProxyFactory::CreatePowerManagerProxy instead. |
| 14 | |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 15 | #include <stdint.h> |
| 16 | |
| 17 | #include <string> |
| 18 | #include <vector> |
| 19 | |
| 20 | #include <base/compiler_specific.h> |
| 21 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 22 | #include "shill/dbus_bindings/power_manager.h" |
| 23 | #include "shill/power_manager_proxy_interface.h" |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 24 | #include "shill/proxy_factory.h" |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 25 | |
| 26 | namespace shill { |
| 27 | |
| 28 | class PowerManagerProxy : public PowerManagerProxyInterface { |
| 29 | public: |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 30 | virtual ~PowerManagerProxy(); |
| 31 | |
| 32 | // Inherited from PowerManagerProxyInterface. |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 33 | virtual bool RegisterSuspendDelay(base::TimeDelta timeout, |
Daniel Erat | f975367 | 2013-01-24 10:17:02 -0800 | [diff] [blame] | 34 | const std::string &description, |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 35 | int *delay_id_out) OVERRIDE; |
| 36 | virtual bool UnregisterSuspendDelay(int delay_id) OVERRIDE; |
| 37 | virtual bool ReportSuspendReadiness(int delay_id, int suspend_id) OVERRIDE; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 38 | |
| 39 | private: |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 40 | // Only this factory method can create a PowerManagerProxy. |
| 41 | friend PowerManagerProxyInterface *ProxyFactory::CreatePowerManagerProxy( |
| 42 | PowerManagerProxyDelegate *delegate); |
| 43 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 44 | class Proxy : public org::chromium::PowerManager_proxy, |
| 45 | public DBus::ObjectProxy { |
| 46 | public: |
| 47 | Proxy(PowerManagerProxyDelegate *delegate, |
| 48 | DBus::Connection *connection); |
| 49 | virtual ~Proxy(); |
| 50 | |
| 51 | private: |
| 52 | // Signal callbacks inherited from org::chromium::PowerManager_proxy. |
Daniel Erat | 0818cca | 2012-12-14 10:16:21 -0800 | [diff] [blame] | 53 | virtual void SuspendImminent(const std::vector<uint8_t> &serialized_proto); |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 54 | virtual void PowerStateChanged(const std::string &new_power_state); |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 55 | |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 56 | PowerManagerProxyDelegate *const delegate_; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 57 | |
| 58 | DISALLOW_COPY_AND_ASSIGN(Proxy); |
| 59 | }; |
| 60 | |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 61 | // The PowerStateChanged event occurs on this path. The root path ("/") is |
| 62 | // used because the powerd_suspend script sends signals on that path. When |
| 63 | // the powerd_suspend script is fixed to use the same path as the rest of the |
| 64 | // power manager, then this proxy can use the usual power manager path |
| 65 | // power_manager::kPowerManagerServicePath. |
| 66 | static const char kRootPath[]; |
| 67 | |
| 68 | // Constructs a PowerManager DBus object proxy with signals dispatched to |
| 69 | // |delegate|. |
| 70 | PowerManagerProxy(PowerManagerProxyDelegate *delegate, |
| 71 | DBus::Connection *connection); |
| 72 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 73 | Proxy proxy_; |
| 74 | |
| 75 | DISALLOW_COPY_AND_ASSIGN(PowerManagerProxy); |
| 76 | }; |
| 77 | |
| 78 | } // namespace shill |
| 79 | |
| 80 | #endif // SHILL_POWER_MANAGER_PROXY_ |