blob: a2b3523a663acd60ca68dafd2b3f1f91b0513569 [file] [log] [blame]
Darin Petkov50308cd2011-06-01 18:25:07 -07001// 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 Masone2b105542011-06-22 10:58:09 -07009#include "shill/dhcp_config.h"
Darin Petkovd1b715b2011-06-02 21:21:22 -070010#include "shill/dhcpcd_proxy.h"
Darin Petkovaceede32011-07-18 15:32:38 -070011#include "shill/proxy_factory.h"
Darin Petkovd1b715b2011-06-02 21:21:22 -070012
Darin Petkovf65e9282011-06-21 14:29:56 -070013using std::string;
14
Darin Petkov50308cd2011-06-01 18:25:07 -070015namespace shill {
16
Darin Petkovf7897bc2011-06-08 17:13:36 -070017DHCPProvider::DHCPProvider() : glib_(NULL) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070018 VLOG(2) << __func__;
Darin Petkov50308cd2011-06-01 18:25:07 -070019}
20
21DHCPProvider::~DHCPProvider() {
Darin Petkovd1b715b2011-06-02 21:21:22 -070022 VLOG(2) << __func__;
Darin Petkov50308cd2011-06-01 18:25:07 -070023}
24
25DHCPProvider* DHCPProvider::GetInstance() {
26 return Singleton<DHCPProvider>::get();
27}
28
Darin Petkovaceede32011-07-18 15:32:38 -070029void DHCPProvider::Init(GLib *glib) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070030 VLOG(2) << __func__;
Darin Petkovaceede32011-07-18 15:32:38 -070031 listener_.reset(
32 new DHCPCDListener(ProxyFactory::factory()->connection(), this));
Darin Petkovf7897bc2011-06-08 17:13:36 -070033 glib_ = glib;
Darin Petkovd1b715b2011-06-02 21:21:22 -070034}
35
Darin Petkovf65e9282011-06-21 14:29:56 -070036DHCPConfigRefPtr DHCPProvider::CreateConfig(const string &device_name) {
37 VLOG(2) << __func__ << " device: " << device_name;
38 return new DHCPConfig(this, device_name, glib_);
Darin Petkovd1b715b2011-06-02 21:21:22 -070039}
40
Darin Petkov98dd6a02011-06-10 15:12:57 -070041DHCPConfigRefPtr DHCPProvider::GetConfig(int pid) {
Darin Petkovf65e9282011-06-21 14:29:56 -070042 VLOG(2) << __func__ << " pid: " << pid;
Darin Petkovf9b0ca82011-06-20 12:10:23 -070043 PIDConfigMap::const_iterator it = configs_.find(pid);
Darin Petkovd1b715b2011-06-02 21:21:22 -070044 if (it == configs_.end()) {
Darin Petkov98dd6a02011-06-10 15:12:57 -070045 return NULL;
Darin Petkovd1b715b2011-06-02 21:21:22 -070046 }
47 return it->second;
48}
49
Chris Masone2b105542011-06-22 10:58:09 -070050void DHCPProvider::BindPID(int pid, const DHCPConfigRefPtr &config) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070051 VLOG(2) << __func__ << " pid: " << pid;
52 configs_[pid] = config;
53}
54
Darin Petkov92c43902011-06-09 20:46:06 -070055void DHCPProvider::UnbindPID(int pid) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070056 VLOG(2) << __func__ << " pid: " << pid;
57 configs_.erase(pid);
58}
59
Darin Petkov50308cd2011-06-01 18:25:07 -070060} // namespace shill