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 | |
| 5 | #ifndef SHILL_DHCPCD_PROXY_ |
| 6 | #define SHILL_DHCPCD_PROXY_ |
| 7 | |
| 8 | #include <base/basictypes.h> |
| 9 | |
Darin Petkov | 4a09b6b | 2011-07-19 12:52:06 -0700 | [diff] [blame] | 10 | #include "shill/dbus_bindings/dhcpcd.h" |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 11 | #include "shill/dhcp_config.h" |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 12 | #include "shill/dhcp_proxy_interface.h" |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 13 | |
| 14 | namespace shill { |
| 15 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 16 | class DHCPProvider; |
| 17 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 18 | // 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 Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 21 | class DHCPCDListener { |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 22 | public: |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 23 | DHCPCDListener(DBus::Connection *connection, DHCPProvider *provider); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 24 | |
| 25 | private: |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 26 | class Proxy : public DBus::InterfaceProxy, |
| 27 | public DBus::ObjectProxy { |
| 28 | public: |
| 29 | Proxy(DBus::Connection *connection, DHCPProvider *provider); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 30 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 31 | 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 Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 41 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 42 | DISALLOW_COPY_AND_ASSIGN(DHCPCDListener); |
| 43 | }; |
| 44 | |
| 45 | // 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] | 46 | // and service name |service|. |
| 47 | class DHCPCDProxy : public DHCPProxyInterface { |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 48 | public: |
| 49 | static const char kDBusInterfaceName[]; |
| 50 | static const char kDBusPath[]; |
| 51 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 52 | DHCPCDProxy(DBus::Connection *connection, const std::string &service); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 53 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 54 | // Inherited from DHCPProxyInterface. |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 55 | virtual void Rebind(const std::string &interface); |
| 56 | virtual void Release(const std::string &interface); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 57 | |
| 58 | private: |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 59 | class Proxy : public org::chromium::dhcpcd_proxy, |
| 60 | public DBus::ObjectProxy { |
| 61 | public: |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 62 | Proxy(DBus::Connection *connection, const std::string &service); |
| 63 | virtual ~Proxy(); |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 64 | |
| 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 Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 80 | DISALLOW_COPY_AND_ASSIGN(DHCPCDProxy); |
| 81 | }; |
| 82 | |
| 83 | } // namespace shill |
| 84 | |
| 85 | #endif // SHILL_DHCPCD_PROXY_ |