blob: a31446fdd1b166d79e2a9d356aa78927b6e5655b [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,
34 int *delay_id_out) OVERRIDE;
35 virtual bool UnregisterSuspendDelay(int delay_id) OVERRIDE;
36 virtual bool ReportSuspendReadiness(int delay_id, int suspend_id) OVERRIDE;
Darin Petkov394b7d42011-11-03 15:48:02 +010037
38 private:
mukesh agrawal7c1fece2012-01-13 11:31:27 -080039 // Only this factory method can create a PowerManagerProxy.
40 friend PowerManagerProxyInterface *ProxyFactory::CreatePowerManagerProxy(
41 PowerManagerProxyDelegate *delegate);
42
Darin Petkov394b7d42011-11-03 15:48:02 +010043 class Proxy : public org::chromium::PowerManager_proxy,
44 public DBus::ObjectProxy {
45 public:
46 Proxy(PowerManagerProxyDelegate *delegate,
47 DBus::Connection *connection);
48 virtual ~Proxy();
49
50 private:
51 // Signal callbacks inherited from org::chromium::PowerManager_proxy.
Daniel Erat0818cca2012-12-14 10:16:21 -080052 virtual void SuspendImminent(const std::vector<uint8_t> &serialized_proto);
mukesh agrawal7c1fece2012-01-13 11:31:27 -080053 virtual void PowerStateChanged(const std::string &new_power_state);
Darin Petkov394b7d42011-11-03 15:48:02 +010054
mukesh agrawal7c1fece2012-01-13 11:31:27 -080055 PowerManagerProxyDelegate *const delegate_;
Darin Petkov394b7d42011-11-03 15:48:02 +010056
57 DISALLOW_COPY_AND_ASSIGN(Proxy);
58 };
59
mukesh agrawal7c1fece2012-01-13 11:31:27 -080060 // The PowerStateChanged event occurs on this path. The root path ("/") is
61 // used because the powerd_suspend script sends signals on that path. When
62 // the powerd_suspend script is fixed to use the same path as the rest of the
63 // power manager, then this proxy can use the usual power manager path
64 // power_manager::kPowerManagerServicePath.
65 static const char kRootPath[];
66
67 // Constructs a PowerManager DBus object proxy with signals dispatched to
68 // |delegate|.
69 PowerManagerProxy(PowerManagerProxyDelegate *delegate,
70 DBus::Connection *connection);
71
Darin Petkov394b7d42011-11-03 15:48:02 +010072 Proxy proxy_;
73
74 DISALLOW_COPY_AND_ASSIGN(PowerManagerProxy);
75};
76
77} // namespace shill
78
79#endif // SHILL_POWER_MANAGER_PROXY_