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