blob: 2e9a26068d04ea4a318f579ab12f1fbc9947d755 [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
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_POWER_MANAGER_PROXY_H_
6#define SHILL_POWER_MANAGER_PROXY_H_
Darin Petkov394b7d42011-11-03 15:48:02 +01007
mukesh agrawal7c1fece2012-01-13 11:31:27 -08008// 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 Erat0818cca2012-12-14 10:16:21 -080015#include <stdint.h>
16
17#include <string>
18#include <vector>
19
20#include <base/compiler_specific.h>
21
Liam McLoughlinef342b42013-09-13 21:05:36 +010022#include "shill/dbus_proxies/power_manager.h"
Darin Petkov394b7d42011-11-03 15:48:02 +010023#include "shill/power_manager_proxy_interface.h"
mukesh agrawal7c1fece2012-01-13 11:31:27 -080024#include "shill/proxy_factory.h"
Darin Petkov394b7d42011-11-03 15:48:02 +010025
26namespace shill {
27
28class PowerManagerProxy : public PowerManagerProxyInterface {
29 public:
Ben Chan5ea763b2014-08-13 11:07:54 -070030 ~PowerManagerProxy() override;
Darin Petkov394b7d42011-11-03 15:48:02 +010031
32 // Inherited from PowerManagerProxyInterface.
Ben Chan14f745f2014-08-11 21:13:39 -070033 bool RegisterSuspendDelay(base::TimeDelta timeout,
Paul Stewart1a212a62015-06-16 13:13:10 -070034 const std::string& description,
35 int* delay_id_out) override;
Ben Chan14f745f2014-08-11 21:13:39 -070036 bool UnregisterSuspendDelay(int delay_id) override;
37 bool ReportSuspendReadiness(int delay_id, int suspend_id) override;
Prathmesh Prabhu64ad2382014-08-26 11:19:30 -070038 bool RegisterDarkSuspendDelay(base::TimeDelta timeout,
Paul Stewart1a212a62015-06-16 13:13:10 -070039 const std::string& description,
40 int* delay_id_out) override;
Prathmesh Prabhu64ad2382014-08-26 11:19:30 -070041 bool UnregisterDarkSuspendDelay(int delay_id) override;
42 bool ReportDarkSuspendReadiness(int delay_id, int suspend_id) override;
Paul Stewart1a212a62015-06-16 13:13:10 -070043 bool RecordDarkResumeWakeReason(const std::string& wake_reason) override;
Darin Petkov394b7d42011-11-03 15:48:02 +010044
45 private:
mukesh agrawal7c1fece2012-01-13 11:31:27 -080046 // Only this factory method can create a PowerManagerProxy.
Paul Stewart1a212a62015-06-16 13:13:10 -070047 friend PowerManagerProxyInterface* ProxyFactory::CreatePowerManagerProxy(
48 PowerManagerProxyDelegate* delegate);
mukesh agrawal7c1fece2012-01-13 11:31:27 -080049
Darin Petkov394b7d42011-11-03 15:48:02 +010050 class Proxy : public org::chromium::PowerManager_proxy,
51 public DBus::ObjectProxy {
52 public:
Paul Stewart1a212a62015-06-16 13:13:10 -070053 Proxy(PowerManagerProxyDelegate* delegate,
54 DBus::Connection* connection);
Ben Chan5ea763b2014-08-13 11:07:54 -070055 ~Proxy() override;
Darin Petkov394b7d42011-11-03 15:48:02 +010056
57 private:
58 // Signal callbacks inherited from org::chromium::PowerManager_proxy.
Paul Stewart1a212a62015-06-16 13:13:10 -070059 void SuspendImminent(const std::vector<uint8_t>& serialized_proto) override;
60 void SuspendDone(const std::vector<uint8_t>& serialized_proto) override;
Yunlian Jiang6acd9662015-01-30 08:36:10 -080061 void DarkSuspendImminent(
Paul Stewart1a212a62015-06-16 13:13:10 -070062 const std::vector<uint8_t>& serialized_proto) override;
Darin Petkov394b7d42011-11-03 15:48:02 +010063
Paul Stewart1a212a62015-06-16 13:13:10 -070064 PowerManagerProxyDelegate* const delegate_;
Darin Petkov394b7d42011-11-03 15:48:02 +010065
66 DISALLOW_COPY_AND_ASSIGN(Proxy);
67 };
68
mukesh agrawal7c1fece2012-01-13 11:31:27 -080069 // Constructs a PowerManager DBus object proxy with signals dispatched to
70 // |delegate|.
Paul Stewart1a212a62015-06-16 13:13:10 -070071 PowerManagerProxy(PowerManagerProxyDelegate* delegate,
72 DBus::Connection* connection);
mukesh agrawal7c1fece2012-01-13 11:31:27 -080073
Prathmesh Prabhu64ad2382014-08-26 11:19:30 -070074 bool RegisterSuspendDelayInternal(bool is_dark,
75 base::TimeDelta timeout,
Paul Stewart1a212a62015-06-16 13:13:10 -070076 const std::string& description,
77 int* delay_id_out);
Prathmesh Prabhu64ad2382014-08-26 11:19:30 -070078 bool UnregisterSuspendDelayInternal(bool is_dark, int delay_id);
79 bool ReportSuspendReadinessInternal(bool is_dark,
80 int delay_id,
81 int suspend_id);
82
Darin Petkov394b7d42011-11-03 15:48:02 +010083 Proxy proxy_;
84
85 DISALLOW_COPY_AND_ASSIGN(PowerManagerProxy);
86};
87
88} // namespace shill
89
Ben Chanc45688b2014-07-02 23:50:45 -070090#endif // SHILL_POWER_MANAGER_PROXY_H_