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 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_POWER_MANAGER_PROXY_H_ |
| 6 | #define SHILL_POWER_MANAGER_PROXY_H_ |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 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 | |
Liam McLoughlin | ef342b4 | 2013-09-13 21:05:36 +0100 | [diff] [blame] | 22 | #include "shill/dbus_proxies/power_manager.h" |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 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: |
Ben Chan | 5ea763b | 2014-08-13 11:07:54 -0700 | [diff] [blame] | 30 | ~PowerManagerProxy() override; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 31 | |
| 32 | // Inherited from PowerManagerProxyInterface. |
Ben Chan | 14f745f | 2014-08-11 21:13:39 -0700 | [diff] [blame] | 33 | bool RegisterSuspendDelay(base::TimeDelta timeout, |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 34 | const std::string& description, |
| 35 | int* delay_id_out) override; |
Ben Chan | 14f745f | 2014-08-11 21:13:39 -0700 | [diff] [blame] | 36 | bool UnregisterSuspendDelay(int delay_id) override; |
| 37 | bool ReportSuspendReadiness(int delay_id, int suspend_id) override; |
Prathmesh Prabhu | 64ad238 | 2014-08-26 11:19:30 -0700 | [diff] [blame] | 38 | bool RegisterDarkSuspendDelay(base::TimeDelta timeout, |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 39 | const std::string& description, |
| 40 | int* delay_id_out) override; |
Prathmesh Prabhu | 64ad238 | 2014-08-26 11:19:30 -0700 | [diff] [blame] | 41 | bool UnregisterDarkSuspendDelay(int delay_id) override; |
| 42 | bool ReportDarkSuspendReadiness(int delay_id, int suspend_id) override; |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 43 | bool RecordDarkResumeWakeReason(const std::string& wake_reason) override; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 44 | |
| 45 | private: |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 46 | // Only this factory method can create a PowerManagerProxy. |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 47 | friend PowerManagerProxyInterface* ProxyFactory::CreatePowerManagerProxy( |
| 48 | PowerManagerProxyDelegate* delegate); |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 49 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 50 | class Proxy : public org::chromium::PowerManager_proxy, |
| 51 | public DBus::ObjectProxy { |
| 52 | public: |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 53 | Proxy(PowerManagerProxyDelegate* delegate, |
| 54 | DBus::Connection* connection); |
Ben Chan | 5ea763b | 2014-08-13 11:07:54 -0700 | [diff] [blame] | 55 | ~Proxy() override; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 56 | |
| 57 | private: |
| 58 | // Signal callbacks inherited from org::chromium::PowerManager_proxy. |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 59 | void SuspendImminent(const std::vector<uint8_t>& serialized_proto) override; |
| 60 | void SuspendDone(const std::vector<uint8_t>& serialized_proto) override; |
Yunlian Jiang | 6acd966 | 2015-01-30 08:36:10 -0800 | [diff] [blame] | 61 | void DarkSuspendImminent( |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 62 | const std::vector<uint8_t>& serialized_proto) override; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 63 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 64 | PowerManagerProxyDelegate* const delegate_; |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 65 | |
| 66 | DISALLOW_COPY_AND_ASSIGN(Proxy); |
| 67 | }; |
| 68 | |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 69 | // Constructs a PowerManager DBus object proxy with signals dispatched to |
| 70 | // |delegate|. |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 71 | PowerManagerProxy(PowerManagerProxyDelegate* delegate, |
| 72 | DBus::Connection* connection); |
mukesh agrawal | 7c1fece | 2012-01-13 11:31:27 -0800 | [diff] [blame] | 73 | |
Prathmesh Prabhu | 64ad238 | 2014-08-26 11:19:30 -0700 | [diff] [blame] | 74 | bool RegisterSuspendDelayInternal(bool is_dark, |
| 75 | base::TimeDelta timeout, |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 76 | const std::string& description, |
| 77 | int* delay_id_out); |
Prathmesh Prabhu | 64ad238 | 2014-08-26 11:19:30 -0700 | [diff] [blame] | 78 | bool UnregisterSuspendDelayInternal(bool is_dark, int delay_id); |
| 79 | bool ReportSuspendReadinessInternal(bool is_dark, |
| 80 | int delay_id, |
| 81 | int suspend_id); |
| 82 | |
Darin Petkov | 394b7d4 | 2011-11-03 15:48:02 +0100 | [diff] [blame] | 83 | Proxy proxy_; |
| 84 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(PowerManagerProxy); |
| 86 | }; |
| 87 | |
| 88 | } // namespace shill |
| 89 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 90 | #endif // SHILL_POWER_MANAGER_PROXY_H_ |