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