Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 1 | // 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 Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_DHCPCD_PROXY_H_ |
| 6 | #define SHILL_DHCPCD_PROXY_H_ |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 7 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 10 | #include <base/basictypes.h> |
| 11 | |
Liam McLoughlin | ef342b4 | 2013-09-13 21:05:36 +0100 | [diff] [blame] | 12 | #include "shill/dbus_proxies/dhcpcd.h" |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 13 | #include "shill/dhcp_config.h" |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 14 | #include "shill/dhcp_proxy_interface.h" |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 15 | |
| 16 | namespace shill { |
| 17 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 18 | class DHCPProvider; |
| 19 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 20 | // 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 Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 23 | class DHCPCDListener { |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 24 | public: |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 25 | DHCPCDListener(DBus::Connection *connection, DHCPProvider *provider); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 26 | |
| 27 | private: |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 28 | class Proxy : public DBus::InterfaceProxy, |
| 29 | public DBus::ObjectProxy { |
| 30 | public: |
| 31 | Proxy(DBus::Connection *connection, DHCPProvider *provider); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 32 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 33 | 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 Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 43 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 44 | DISALLOW_COPY_AND_ASSIGN(DHCPCDListener); |
| 45 | }; |
| 46 | |
| 47 | // There's a single DHCPCD proxy per DHCP client identified by its process id |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 48 | // and service name |service|. |
| 49 | class DHCPCDProxy : public DHCPProxyInterface { |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 50 | public: |
| 51 | static const char kDBusInterfaceName[]; |
| 52 | static const char kDBusPath[]; |
| 53 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 54 | DHCPCDProxy(DBus::Connection *connection, const std::string &service); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 55 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 56 | // Inherited from DHCPProxyInterface. |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 57 | virtual void Rebind(const std::string &interface); |
| 58 | virtual void Release(const std::string &interface); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 59 | |
| 60 | private: |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 61 | class Proxy : public org::chromium::dhcpcd_proxy, |
| 62 | public DBus::ObjectProxy { |
| 63 | public: |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 64 | Proxy(DBus::Connection *connection, const std::string &service); |
| 65 | virtual ~Proxy(); |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 66 | |
| 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 Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 82 | DISALLOW_COPY_AND_ASSIGN(DHCPCDProxy); |
| 83 | }; |
| 84 | |
| 85 | } // namespace shill |
| 86 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 87 | #endif // SHILL_DHCPCD_PROXY_H_ |