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 | |
| 9 | namespace shill { |
| 10 | |
| 11 | const char DHCPCDProxy::kDBusInterfaceName[] = "org.chromium.dhcpcd"; |
| 12 | const char DHCPCDProxy::kDBusPath[] = "/org/chromium/dhcpcd"; |
| 13 | |
| 14 | DHCPCDListener::DHCPCDListener(DBus::Connection *connection) |
| 15 | : DBus::InterfaceProxy(DHCPCDProxy::kDBusInterfaceName), |
| 16 | DBus::ObjectProxy(*connection, DHCPCDProxy::kDBusPath) { |
| 17 | VLOG(2) << __func__; |
| 18 | connect_signal(DHCPCDListener, Event, EventSignal); |
| 19 | connect_signal(DHCPCDListener, StatusChanged, StatusChangedSignal); |
| 20 | } |
| 21 | |
| 22 | void DHCPCDListener::EventSignal(const DBus::SignalMessage &signal) { |
| 23 | VLOG(2) << __func__; |
| 24 | DBus::MessageIter ri = signal.reader(); |
| 25 | unsigned int pid; |
| 26 | ri >> pid; |
| 27 | VLOG(2) << "sender(" << signal.sender() << ") pid(" << pid << ")"; |
| 28 | // TODO(petkov): Dispatch the signal to the appropriate DHCPCDProxy. |
| 29 | } |
| 30 | |
| 31 | void DHCPCDListener::StatusChangedSignal(const DBus::SignalMessage &signal) { |
| 32 | VLOG(2) << __func__; |
| 33 | DBus::MessageIter ri = signal.reader(); |
| 34 | unsigned int pid; |
| 35 | ri >> pid; |
| 36 | VLOG(2) << "sender(" << signal.sender() << ") pid(" << pid << ")"; |
| 37 | // TODO(petkov): Dispatch the signal to the appropriate DHCPCDProxy. |
| 38 | } |
| 39 | |
| 40 | DHCPCDProxy::DHCPCDProxy(unsigned int pid, |
| 41 | DBus::Connection *connection, |
| 42 | const char *service) |
| 43 | : DBus::ObjectProxy(*connection, kDBusPath, service), |
| 44 | pid_(pid) { |
| 45 | VLOG(2) << "DHCPCDListener(pid=" << pid_ << " service=" << service << ")."; |
| 46 | |
| 47 | // Don't catch signals directly in this proxy because they will be dispatched |
| 48 | // to us by the DHCPCD listener. |
| 49 | _signals.erase("Event"); |
| 50 | _signals.erase("StatusChanged"); |
| 51 | } |
| 52 | |
| 53 | void DHCPCDProxy::Event( |
| 54 | const uint32_t& pid, |
| 55 | const std::string& reason, |
| 56 | const std::map< std::string, DBus::Variant >& configuration) { |
| 57 | VLOG(2) << "Event(pid=" << pid << " reason=\"" << reason << "\")"; |
| 58 | CHECK_EQ(pid, pid_); |
| 59 | } |
| 60 | |
| 61 | void DHCPCDProxy::StatusChanged(const uint32_t& pid, |
| 62 | const std::string& status) { |
| 63 | VLOG(2) << "StatusChanged(pid=" << pid << " status=\"" << status << "\")"; |
| 64 | CHECK_EQ(pid, pid_); |
| 65 | } |
| 66 | |
| 67 | } // namespace shill |