blob: c3e670f290c4e1bf87601c30f2e3c239dab5d44b [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
Darin Petkov394b7d42011-11-03 15:48:02 +010015#include "shill/dbus_bindings/power_manager.h"
16#include "shill/power_manager_proxy_interface.h"
mukesh agrawal7c1fece2012-01-13 11:31:27 -080017#include "shill/proxy_factory.h"
Darin Petkov394b7d42011-11-03 15:48:02 +010018
19namespace shill {
20
21class PowerManagerProxy : public PowerManagerProxyInterface {
22 public:
Darin Petkov394b7d42011-11-03 15:48:02 +010023 virtual ~PowerManagerProxy();
24
25 // Inherited from PowerManagerProxyInterface.
26 virtual void RegisterSuspendDelay(uint32 delay_ms);
27
28 private:
mukesh agrawal7c1fece2012-01-13 11:31:27 -080029 // Only this factory method can create a PowerManagerProxy.
30 friend PowerManagerProxyInterface *ProxyFactory::CreatePowerManagerProxy(
31 PowerManagerProxyDelegate *delegate);
32
Darin Petkov394b7d42011-11-03 15:48:02 +010033 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 agrawal7c1fece2012-01-13 11:31:27 -080043 virtual void PowerStateChanged(const std::string &new_power_state);
Darin Petkov394b7d42011-11-03 15:48:02 +010044
mukesh agrawal7c1fece2012-01-13 11:31:27 -080045 PowerManagerProxyDelegate *const delegate_;
Darin Petkov394b7d42011-11-03 15:48:02 +010046
47 DISALLOW_COPY_AND_ASSIGN(Proxy);
48 };
49
mukesh agrawal7c1fece2012-01-13 11:31:27 -080050 // 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 Petkov394b7d42011-11-03 15:48:02 +010062 Proxy proxy_;
63
64 DISALLOW_COPY_AND_ASSIGN(PowerManagerProxy);
65};
66
67} // namespace shill
68
69#endif // SHILL_POWER_MANAGER_PROXY_