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 | #include "shill/dhcpcd_proxy.h" |
| 6 | |
| 7 | #include <base/logging.h> |
| 8 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 9 | #include "shill/dhcp_provider.h" |
| 10 | |
| 11 | using std::string; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 12 | using std::vector; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 13 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 14 | namespace shill { |
| 15 | |
| 16 | const char DHCPCDProxy::kDBusInterfaceName[] = "org.chromium.dhcpcd"; |
| 17 | const char DHCPCDProxy::kDBusPath[] = "/org/chromium/dhcpcd"; |
| 18 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 19 | DHCPCDListener::DHCPCDListener(DBus::Connection *connection, |
| 20 | DHCPProvider *provider) |
| 21 | : proxy_(connection, provider) {} |
| 22 | |
| 23 | DHCPCDListener::Proxy::Proxy(DBus::Connection *connection, |
| 24 | DHCPProvider *provider) |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 25 | : DBus::InterfaceProxy(DHCPCDProxy::kDBusInterfaceName), |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 26 | DBus::ObjectProxy(*connection, DHCPCDProxy::kDBusPath), |
| 27 | provider_(provider) { |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 28 | VLOG(2) << __func__; |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 29 | connect_signal(DHCPCDListener::Proxy, Event, EventSignal); |
| 30 | connect_signal(DHCPCDListener::Proxy, StatusChanged, StatusChangedSignal); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 33 | void DHCPCDListener::Proxy::EventSignal(const DBus::SignalMessage &signal) { |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 34 | VLOG(2) << __func__; |
| 35 | DBus::MessageIter ri = signal.reader(); |
| 36 | unsigned int pid; |
| 37 | ri >> pid; |
| 38 | VLOG(2) << "sender(" << signal.sender() << ") pid(" << pid << ")"; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 39 | |
| 40 | DHCPConfigRefPtr config = provider_->GetConfig(pid); |
| 41 | if (!config.get()) { |
| 42 | LOG(ERROR) << "Unknown DHCP client PID " << pid; |
| 43 | return; |
| 44 | } |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 45 | config->InitProxy(signal.sender()); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 46 | |
| 47 | string reason; |
| 48 | ri >> reason; |
| 49 | DHCPConfig::Configuration configuration; |
| 50 | ri >> configuration; |
| 51 | config->ProcessEventSignal(reason, configuration); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 54 | void DHCPCDListener::Proxy::StatusChangedSignal( |
| 55 | const DBus::SignalMessage &signal) { |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 56 | VLOG(2) << __func__; |
| 57 | DBus::MessageIter ri = signal.reader(); |
| 58 | unsigned int pid; |
| 59 | ri >> pid; |
| 60 | VLOG(2) << "sender(" << signal.sender() << ") pid(" << pid << ")"; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 61 | |
| 62 | // Accept StatusChanged signals just to get the sender address and create an |
| 63 | // appropriate proxy for the PID/sender pair. |
| 64 | DHCPConfigRefPtr config = provider_->GetConfig(pid); |
| 65 | if (!config.get()) { |
| 66 | LOG(ERROR) << "Unknown DHCP client PID " << pid; |
| 67 | return; |
| 68 | } |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 69 | config->InitProxy(signal.sender()); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 72 | DHCPCDProxy::DHCPCDProxy(DBus::Connection *connection, const string &service) |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 73 | : proxy_(connection, service) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 74 | VLOG(2) << "DHCPCDProxy(service=" << service << ")."; |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 75 | } |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 76 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 77 | void DHCPCDProxy::Rebind(const string &interface) { |
| 78 | proxy_.Rebind(interface); |
| 79 | } |
| 80 | |
| 81 | void DHCPCDProxy::Release(const string &interface) { |
| 82 | proxy_.Release(interface); |
| 83 | } |
| 84 | |
| 85 | DHCPCDProxy::Proxy::Proxy(DBus::Connection *connection, |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 86 | const string &service) |
| 87 | : DBus::ObjectProxy(*connection, kDBusPath, service.c_str()) { |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 88 | // Don't catch signals directly in this proxy because they will be dispatched |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 89 | // to the client by the DHCPCD listener. |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 90 | _signals.erase("Event"); |
| 91 | _signals.erase("StatusChanged"); |
| 92 | } |
| 93 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 94 | DHCPCDProxy::Proxy::~Proxy() {} |
| 95 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 96 | void DHCPCDProxy::Proxy::Event( |
| 97 | const uint32_t &/*pid*/, |
| 98 | const std::string &/*reason*/, |
| 99 | const DHCPConfig::Configuration &/*configuration*/) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 100 | NOTREACHED(); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 101 | } |
| 102 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 103 | void DHCPCDProxy::Proxy::StatusChanged(const uint32_t &/*pid*/, |
| 104 | const std::string &/*status*/) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 105 | NOTREACHED(); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | } // namespace shill |