blob: c30622d7ba565dfde565f48d6eaad5f72199e766 [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
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_DHCPCD_PROXY_H_
6#define SHILL_DHCPCD_PROXY_H_
Darin Petkov50308cd2011-06-01 18:25:07 -07007
Alex Vakulenko8a532292014-06-16 17:18:44 -07008#include <string>
9
Darin Petkov50308cd2011-06-01 18:25:07 -070010#include <base/basictypes.h>
11
Liam McLoughlinef342b42013-09-13 21:05:36 +010012#include "shill/dbus_proxies/dhcpcd.h"
Darin Petkovd1b715b2011-06-02 21:21:22 -070013#include "shill/dhcp_config.h"
Darin Petkov50308cd2011-06-01 18:25:07 -070014#include "shill/dhcp_proxy_interface.h"
Darin Petkov50308cd2011-06-01 18:25:07 -070015
16namespace shill {
17
Darin Petkovd1b715b2011-06-02 21:21:22 -070018class DHCPProvider;
19
Darin Petkov50308cd2011-06-01 18:25:07 -070020// The DHCPCD listener is a singleton proxy that listens to signals from all
21// DHCP clients and dispatches them through the DHCP provider to the appropriate
22// client based on the PID.
Darin Petkovaceede32011-07-18 15:32:38 -070023class DHCPCDListener {
Darin Petkov50308cd2011-06-01 18:25:07 -070024 public:
Darin Petkovaceede32011-07-18 15:32:38 -070025 DHCPCDListener(DBus::Connection *connection, DHCPProvider *provider);
Darin Petkov50308cd2011-06-01 18:25:07 -070026
27 private:
Darin Petkovaceede32011-07-18 15:32:38 -070028 class Proxy : public DBus::InterfaceProxy,
29 public DBus::ObjectProxy {
30 public:
31 Proxy(DBus::Connection *connection, DHCPProvider *provider);
Darin Petkov50308cd2011-06-01 18:25:07 -070032
Darin Petkovaceede32011-07-18 15:32:38 -070033 private:
34 void EventSignal(const DBus::SignalMessage &signal);
35 void StatusChangedSignal(const DBus::SignalMessage &signal);
36
37 DHCPProvider *provider_;
38
39 DISALLOW_COPY_AND_ASSIGN(Proxy);
40 };
41
42 Proxy proxy_;
Darin Petkovd1b715b2011-06-02 21:21:22 -070043
Darin Petkov50308cd2011-06-01 18:25:07 -070044 DISALLOW_COPY_AND_ASSIGN(DHCPCDListener);
45};
46
47// There's a single DHCPCD proxy per DHCP client identified by its process id
Darin Petkovaceede32011-07-18 15:32:38 -070048// and service name |service|.
49class DHCPCDProxy : public DHCPProxyInterface {
Darin Petkov50308cd2011-06-01 18:25:07 -070050 public:
51 static const char kDBusInterfaceName[];
52 static const char kDBusPath[];
53
Darin Petkova7b89492011-07-27 12:48:17 -070054 DHCPCDProxy(DBus::Connection *connection, const std::string &service);
Darin Petkov50308cd2011-06-01 18:25:07 -070055
Darin Petkovd1b715b2011-06-02 21:21:22 -070056 // Inherited from DHCPProxyInterface.
Darin Petkovaceede32011-07-18 15:32:38 -070057 virtual void Rebind(const std::string &interface);
58 virtual void Release(const std::string &interface);
Darin Petkov50308cd2011-06-01 18:25:07 -070059
60 private:
Darin Petkovaceede32011-07-18 15:32:38 -070061 class Proxy : public org::chromium::dhcpcd_proxy,
62 public DBus::ObjectProxy {
63 public:
Darin Petkova7b89492011-07-27 12:48:17 -070064 Proxy(DBus::Connection *connection, const std::string &service);
65 virtual ~Proxy();
Darin Petkovaceede32011-07-18 15:32:38 -070066
67 private:
68 // Signal callbacks inherited from dhcpcd_proxy. Note that these callbacks
69 // are unused because signals are dispatched directly to the DHCP
70 // configuration instance by the signal listener.
71 virtual void Event(
72 const uint32_t &pid,
73 const std::string &reason,
74 const DHCPConfig::Configuration &configuration);
75 virtual void StatusChanged(const uint32_t &pid, const std::string &status);
76
77 DISALLOW_COPY_AND_ASSIGN(Proxy);
78 };
79
80 Proxy proxy_;
81
Darin Petkov50308cd2011-06-01 18:25:07 -070082 DISALLOW_COPY_AND_ASSIGN(DHCPCDProxy);
83};
84
85} // namespace shill
86
Ben Chanc45688b2014-07-02 23:50:45 -070087#endif // SHILL_DHCPCD_PROXY_H_