blob: ff4c309afc3f6bd23a1d147d9dfc2411445a7451 [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
5#ifndef SHILL_POWER_MANAGER_PROXY_
6#define SHILL_POWER_MANAGER_PROXY_
7
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
Darin Petkov394b7d42011-11-03 15:48:02 +010022#include "shill/dbus_bindings/power_manager.h"
23#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:
Darin Petkov394b7d42011-11-03 15:48:02 +010030 virtual ~PowerManagerProxy();
31
32 // Inherited from PowerManagerProxyInterface.
Daniel Erat0818cca2012-12-14 10:16:21 -080033 virtual bool RegisterSuspendDelay(base::TimeDelta timeout,
Daniel Eratf9753672013-01-24 10:17:02 -080034 const std::string &description,
Daniel Erat0818cca2012-12-14 10:16:21 -080035 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 Petkov394b7d42011-11-03 15:48:02 +010038
39 private:
mukesh agrawal7c1fece2012-01-13 11:31:27 -080040 // Only this factory method can create a PowerManagerProxy.
41 friend PowerManagerProxyInterface *ProxyFactory::CreatePowerManagerProxy(
42 PowerManagerProxyDelegate *delegate);
43
Darin Petkov394b7d42011-11-03 15:48:02 +010044 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 Erat0818cca2012-12-14 10:16:21 -080053 virtual void SuspendImminent(const std::vector<uint8_t> &serialized_proto);
mukesh agrawal7c1fece2012-01-13 11:31:27 -080054 virtual void PowerStateChanged(const std::string &new_power_state);
Darin Petkov394b7d42011-11-03 15:48:02 +010055
mukesh agrawal7c1fece2012-01-13 11:31:27 -080056 PowerManagerProxyDelegate *const delegate_;
Darin Petkov394b7d42011-11-03 15:48:02 +010057
58 DISALLOW_COPY_AND_ASSIGN(Proxy);
59 };
60
mukesh agrawal7c1fece2012-01-13 11:31:27 -080061 // 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 Petkov394b7d42011-11-03 15:48:02 +010073 Proxy proxy_;
74
75 DISALLOW_COPY_AND_ASSIGN(PowerManagerProxy);
76};
77
78} // namespace shill
79
80#endif // SHILL_POWER_MANAGER_PROXY_