blob: 3564e09a3f87949c0645ceae0477ec6c4b6b6551 [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);
Darin Petkov3ec55342012-09-28 14:04:44 +020027 virtual void UnregisterSuspendDelay();
28 virtual void SuspendReady(uint32 sequence_number);
Darin Petkov394b7d42011-11-03 15:48:02 +010029
30 private:
mukesh agrawal7c1fece2012-01-13 11:31:27 -080031 // Only this factory method can create a PowerManagerProxy.
32 friend PowerManagerProxyInterface *ProxyFactory::CreatePowerManagerProxy(
33 PowerManagerProxyDelegate *delegate);
34
Darin Petkov394b7d42011-11-03 15:48:02 +010035 class Proxy : public org::chromium::PowerManager_proxy,
36 public DBus::ObjectProxy {
37 public:
38 Proxy(PowerManagerProxyDelegate *delegate,
39 DBus::Connection *connection);
40 virtual ~Proxy();
41
42 private:
43 // Signal callbacks inherited from org::chromium::PowerManager_proxy.
44 virtual void SuspendDelay(const uint32_t &sequence_number);
mukesh agrawal7c1fece2012-01-13 11:31:27 -080045 virtual void PowerStateChanged(const std::string &new_power_state);
Darin Petkov394b7d42011-11-03 15:48:02 +010046
mukesh agrawal7c1fece2012-01-13 11:31:27 -080047 PowerManagerProxyDelegate *const delegate_;
Darin Petkov394b7d42011-11-03 15:48:02 +010048
49 DISALLOW_COPY_AND_ASSIGN(Proxy);
50 };
51
mukesh agrawal7c1fece2012-01-13 11:31:27 -080052 // The PowerStateChanged event occurs on this path. The root path ("/") is
53 // used because the powerd_suspend script sends signals on that path. When
54 // the powerd_suspend script is fixed to use the same path as the rest of the
55 // power manager, then this proxy can use the usual power manager path
56 // power_manager::kPowerManagerServicePath.
57 static const char kRootPath[];
58
59 // Constructs a PowerManager DBus object proxy with signals dispatched to
60 // |delegate|.
61 PowerManagerProxy(PowerManagerProxyDelegate *delegate,
62 DBus::Connection *connection);
63
Darin Petkov394b7d42011-11-03 15:48:02 +010064 Proxy proxy_;
65
66 DISALLOW_COPY_AND_ASSIGN(PowerManagerProxy);
67};
68
69} // namespace shill
70
71#endif // SHILL_POWER_MANAGER_PROXY_