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 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 15 | #include "shill/dbus_bindings/power_manager.h" |
| 16 | #include "shill/power_manager_proxy_interface.h" |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 17 | #include "shill/proxy_factory.h" |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 18 | |
| 19 | namespace shill { |
| 20 | |
| 21 | class PowerManagerProxy : public PowerManagerProxyInterface { |
| 22 | public: |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 23 | virtual ~PowerManagerProxy(); |
| 24 | |
| 25 | // Inherited from PowerManagerProxyInterface. |
| 26 | virtual void RegisterSuspendDelay(uint32 delay_ms); |
Darin Petkov | 3ec5534 | 2012-09-28 14:04:44 +0200 | [diff] [blame] | 27 | virtual void UnregisterSuspendDelay(); |
| 28 | virtual void SuspendReady(uint32 sequence_number); |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 29 | |
| 30 | private: |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 31 | // Only this factory method can create a PowerManagerProxy. |
| 32 | friend PowerManagerProxyInterface *ProxyFactory::CreatePowerManagerProxy( |
| 33 | PowerManagerProxyDelegate *delegate); |
| 34 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 35 | class Proxy : public org::chromium::PowerManager_proxy, |
| 36 | public DBus::ObjectProxy { |
| 37 | public: |
| 38 | Proxy(PowerManagerProxyDelegate *delegate, |
| 39 | DBus::Connection *connection); |
| 40 | virtual ~Proxy(); |
| 41 | |
| 42 | private: |
| 43 | // Signal callbacks inherited from org::chromium::PowerManager_proxy. |
| 44 | virtual void SuspendDelay(const uint32_t &sequence_number); |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 45 | virtual void PowerStateChanged(const std::string &new_power_state); |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 46 | |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 47 | PowerManagerProxyDelegate *const delegate_; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 48 | |
| 49 | DISALLOW_COPY_AND_ASSIGN(Proxy); |
| 50 | }; |
| 51 | |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 52 | // The PowerStateChanged event occurs on this path. The root path ("/") is |
| 53 | // used because the powerd_suspend script sends signals on that path. When |
| 54 | // the powerd_suspend script is fixed to use the same path as the rest of the |
| 55 | // power manager, then this proxy can use the usual power manager path |
| 56 | // power_manager::kPowerManagerServicePath. |
| 57 | static const char kRootPath[]; |
| 58 | |
| 59 | // Constructs a PowerManager DBus object proxy with signals dispatched to |
| 60 | // |delegate|. |
| 61 | PowerManagerProxy(PowerManagerProxyDelegate *delegate, |
| 62 | DBus::Connection *connection); |
| 63 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 64 | Proxy proxy_; |
| 65 | |
| 66 | DISALLOW_COPY_AND_ASSIGN(PowerManagerProxy); |
| 67 | }; |
| 68 | |
| 69 | } // namespace shill |
| 70 | |
| 71 | #endif // SHILL_POWER_MANAGER_PROXY_ |