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