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