blob: 5f0467472e96a813b9e4735356fffc5e59938b9a [file] [log] [blame]
Darin Petkov50308cd2011-06-01 18:25:07 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2// 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_DHCPCD_PROXY_
6#define SHILL_DHCPCD_PROXY_
7
8#include <base/basictypes.h>
9
Liam McLoughlinef342b42013-09-13 21:05:36 +010010#include "shill/dbus_proxies/dhcpcd.h"
Darin Petkovd1b715b2011-06-02 21:21:22 -070011#include "shill/dhcp_config.h"
Darin Petkov50308cd2011-06-01 18:25:07 -070012#include "shill/dhcp_proxy_interface.h"
Darin Petkov50308cd2011-06-01 18:25:07 -070013
14namespace shill {
15
Darin Petkovd1b715b2011-06-02 21:21:22 -070016class DHCPProvider;
17
Darin Petkov50308cd2011-06-01 18:25:07 -070018// The DHCPCD listener is a singleton proxy that listens to signals from all
19// DHCP clients and dispatches them through the DHCP provider to the appropriate
20// client based on the PID.
Darin Petkovaceede32011-07-18 15:32:38 -070021class DHCPCDListener {
Darin Petkov50308cd2011-06-01 18:25:07 -070022 public:
Darin Petkovaceede32011-07-18 15:32:38 -070023 DHCPCDListener(DBus::Connection *connection, DHCPProvider *provider);
Darin Petkov50308cd2011-06-01 18:25:07 -070024
25 private:
Darin Petkovaceede32011-07-18 15:32:38 -070026 class Proxy : public DBus::InterfaceProxy,
27 public DBus::ObjectProxy {
28 public:
29 Proxy(DBus::Connection *connection, DHCPProvider *provider);
Darin Petkov50308cd2011-06-01 18:25:07 -070030
Darin Petkovaceede32011-07-18 15:32:38 -070031 private:
32 void EventSignal(const DBus::SignalMessage &signal);
33 void StatusChangedSignal(const DBus::SignalMessage &signal);
34
35 DHCPProvider *provider_;
36
37 DISALLOW_COPY_AND_ASSIGN(Proxy);
38 };
39
40 Proxy proxy_;
Darin Petkovd1b715b2011-06-02 21:21:22 -070041
Darin Petkov50308cd2011-06-01 18:25:07 -070042 DISALLOW_COPY_AND_ASSIGN(DHCPCDListener);
43};
44
45// There's a single DHCPCD proxy per DHCP client identified by its process id
Darin Petkovaceede32011-07-18 15:32:38 -070046// and service name |service|.
47class DHCPCDProxy : public DHCPProxyInterface {
Darin Petkov50308cd2011-06-01 18:25:07 -070048 public:
49 static const char kDBusInterfaceName[];
50 static const char kDBusPath[];
51
Darin Petkova7b89492011-07-27 12:48:17 -070052 DHCPCDProxy(DBus::Connection *connection, const std::string &service);
Darin Petkov50308cd2011-06-01 18:25:07 -070053
Darin Petkovd1b715b2011-06-02 21:21:22 -070054 // Inherited from DHCPProxyInterface.
Darin Petkovaceede32011-07-18 15:32:38 -070055 virtual void Rebind(const std::string &interface);
56 virtual void Release(const std::string &interface);
Darin Petkov50308cd2011-06-01 18:25:07 -070057
58 private:
Darin Petkovaceede32011-07-18 15:32:38 -070059 class Proxy : public org::chromium::dhcpcd_proxy,
60 public DBus::ObjectProxy {
61 public:
Darin Petkova7b89492011-07-27 12:48:17 -070062 Proxy(DBus::Connection *connection, const std::string &service);
63 virtual ~Proxy();
Darin Petkovaceede32011-07-18 15:32:38 -070064
65 private:
66 // Signal callbacks inherited from dhcpcd_proxy. Note that these callbacks
67 // are unused because signals are dispatched directly to the DHCP
68 // configuration instance by the signal listener.
69 virtual void Event(
70 const uint32_t &pid,
71 const std::string &reason,
72 const DHCPConfig::Configuration &configuration);
73 virtual void StatusChanged(const uint32_t &pid, const std::string &status);
74
75 DISALLOW_COPY_AND_ASSIGN(Proxy);
76 };
77
78 Proxy proxy_;
79
Darin Petkov50308cd2011-06-01 18:25:07 -070080 DISALLOW_COPY_AND_ASSIGN(DHCPCDProxy);
81};
82
83} // namespace shill
84
85#endif // SHILL_DHCPCD_PROXY_