blob: b79a2b24f409700bd88166d1d0324697f994dc26 [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 Masone19e30402011-07-19 15:48:47 -07009#include "shill/control_interface.h"
Chris Masone2b105542011-06-22 10:58:09 -070010#include "shill/dhcp_config.h"
Darin Petkovd1b715b2011-06-02 21:21:22 -070011#include "shill/dhcpcd_proxy.h"
Darin Petkovaceede32011-07-18 15:32:38 -070012#include "shill/proxy_factory.h"
Darin Petkovd1b715b2011-06-02 21:21:22 -070013
Darin Petkovf65e9282011-06-21 14:29:56 -070014using std::string;
15
Darin Petkov50308cd2011-06-01 18:25:07 -070016namespace shill {
17
Darin Petkova7b89492011-07-27 12:48:17 -070018DHCPProvider::DHCPProvider()
19 : control_interface_(NULL),
20 dispatcher_(NULL),
21 glib_(NULL) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070022 VLOG(2) << __func__;
Darin Petkov50308cd2011-06-01 18:25:07 -070023}
24
25DHCPProvider::~DHCPProvider() {
Darin Petkovd1b715b2011-06-02 21:21:22 -070026 VLOG(2) << __func__;
Darin Petkov50308cd2011-06-01 18:25:07 -070027}
28
29DHCPProvider* DHCPProvider::GetInstance() {
30 return Singleton<DHCPProvider>::get();
31}
32
Darin Petkova7b89492011-07-27 12:48:17 -070033void DHCPProvider::Init(ControlInterface *control_interface,
34 EventDispatcher *dispatcher,
35 GLib *glib) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070036 VLOG(2) << __func__;
Darin Petkovaceede32011-07-18 15:32:38 -070037 listener_.reset(
38 new DHCPCDListener(ProxyFactory::factory()->connection(), this));
Darin Petkovf7897bc2011-06-08 17:13:36 -070039 glib_ = glib;
Chris Masone19e30402011-07-19 15:48:47 -070040 control_interface_ = control_interface;
Darin Petkova7b89492011-07-27 12:48:17 -070041 dispatcher_ = dispatcher;
Darin Petkovd1b715b2011-06-02 21:21:22 -070042}
43
Darin Petkovf65e9282011-06-21 14:29:56 -070044DHCPConfigRefPtr DHCPProvider::CreateConfig(const string &device_name) {
45 VLOG(2) << __func__ << " device: " << device_name;
Darin Petkova7b89492011-07-27 12:48:17 -070046 return new DHCPConfig(
47 control_interface_, dispatcher_, this, device_name, glib_);
Darin Petkovd1b715b2011-06-02 21:21:22 -070048}
49
Darin Petkov98dd6a02011-06-10 15:12:57 -070050DHCPConfigRefPtr DHCPProvider::GetConfig(int pid) {
Darin Petkovf65e9282011-06-21 14:29:56 -070051 VLOG(2) << __func__ << " pid: " << pid;
Darin Petkovf9b0ca82011-06-20 12:10:23 -070052 PIDConfigMap::const_iterator it = configs_.find(pid);
Darin Petkovd1b715b2011-06-02 21:21:22 -070053 if (it == configs_.end()) {
Darin Petkov98dd6a02011-06-10 15:12:57 -070054 return NULL;
Darin Petkovd1b715b2011-06-02 21:21:22 -070055 }
56 return it->second;
57}
58
Chris Masone2b105542011-06-22 10:58:09 -070059void DHCPProvider::BindPID(int pid, const DHCPConfigRefPtr &config) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070060 VLOG(2) << __func__ << " pid: " << pid;
61 configs_[pid] = config;
62}
63
Darin Petkov92c43902011-06-09 20:46:06 -070064void DHCPProvider::UnbindPID(int pid) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070065 VLOG(2) << __func__ << " pid: " << pid;
66 configs_.erase(pid);
67}
68
Darin Petkov50308cd2011-06-01 18:25:07 -070069} // namespace shill