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/dhcp_provider.h" |
| 6 | |
| 7 | #include <base/logging.h> |
| 8 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame^] | 9 | #include "shill/dhcp_config.h" |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 10 | #include "shill/dhcpcd_proxy.h" |
| 11 | |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 12 | using std::string; |
| 13 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 14 | namespace shill { |
| 15 | |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 16 | DHCPProvider::DHCPProvider() : glib_(NULL) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 17 | VLOG(2) << __func__; |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | DHCPProvider::~DHCPProvider() { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 21 | VLOG(2) << __func__; |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | DHCPProvider* DHCPProvider::GetInstance() { |
| 25 | return Singleton<DHCPProvider>::get(); |
| 26 | } |
| 27 | |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 28 | void DHCPProvider::Init(DBus::Connection *connection, GLib *glib) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 29 | VLOG(2) << __func__; |
| 30 | listener_.reset(new DHCPCDListener(this, connection)); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 31 | glib_ = glib; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 34 | DHCPConfigRefPtr DHCPProvider::CreateConfig(const string &device_name) { |
| 35 | VLOG(2) << __func__ << " device: " << device_name; |
| 36 | return new DHCPConfig(this, device_name, glib_); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 39 | DHCPConfigRefPtr DHCPProvider::GetConfig(int pid) { |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 40 | VLOG(2) << __func__ << " pid: " << pid; |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 41 | PIDConfigMap::const_iterator it = configs_.find(pid); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 42 | if (it == configs_.end()) { |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 43 | return NULL; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 44 | } |
| 45 | return it->second; |
| 46 | } |
| 47 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame^] | 48 | void DHCPProvider::BindPID(int pid, const DHCPConfigRefPtr &config) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 49 | VLOG(2) << __func__ << " pid: " << pid; |
| 50 | configs_[pid] = config; |
| 51 | } |
| 52 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 53 | void DHCPProvider::UnbindPID(int pid) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 54 | VLOG(2) << __func__ << " pid: " << pid; |
| 55 | configs_.erase(pid); |
| 56 | } |
| 57 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 58 | } // namespace shill |