blob: c506a77ab6400a527f3f1d923eafdb7556e18bfd [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
Darin Petkovd1b715b2011-06-02 21:21:22 -07009#include "shill/dhcpcd_proxy.h"
10
Darin Petkov50308cd2011-06-01 18:25:07 -070011namespace shill {
12
Darin Petkovf7897bc2011-06-08 17:13:36 -070013DHCPProvider::DHCPProvider() : glib_(NULL) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070014 VLOG(2) << __func__;
Darin Petkov50308cd2011-06-01 18:25:07 -070015}
16
17DHCPProvider::~DHCPProvider() {
Darin Petkovd1b715b2011-06-02 21:21:22 -070018 VLOG(2) << __func__;
Darin Petkov50308cd2011-06-01 18:25:07 -070019}
20
21DHCPProvider* DHCPProvider::GetInstance() {
22 return Singleton<DHCPProvider>::get();
23}
24
Darin Petkovf7897bc2011-06-08 17:13:36 -070025void DHCPProvider::Init(DBus::Connection *connection,
26 GLibInterface *glib) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070027 VLOG(2) << __func__;
28 listener_.reset(new DHCPCDListener(this, connection));
Darin Petkovf7897bc2011-06-08 17:13:36 -070029 glib_ = glib;
Darin Petkovd1b715b2011-06-02 21:21:22 -070030}
31
Chris Masonec1e50412011-06-07 13:04:53 -070032DHCPConfigRefPtr DHCPProvider::CreateConfig(DeviceConstRefPtr device) {
Darin Petkovd1b715b2011-06-02 21:21:22 -070033 VLOG(2) << __func__;
Darin Petkovf7897bc2011-06-08 17:13:36 -070034 return DHCPConfigRefPtr(new DHCPConfig(this, device, glib_));
Darin Petkovd1b715b2011-06-02 21:21:22 -070035}
36
37DHCPConfigRefPtr DHCPProvider::GetConfig(unsigned int pid) {
38 VLOG(2) << __func__;
39 PIDConfigMap::iterator it = configs_.find(pid);
40 if (it == configs_.end()) {
41 return DHCPConfigRefPtr(NULL);
42 }
43 return it->second;
44}
45
46void DHCPProvider::BindPID(unsigned int pid, DHCPConfigRefPtr config) {
47 VLOG(2) << __func__ << " pid: " << pid;
48 configs_[pid] = config;
49}
50
51void DHCPProvider::UnbindPID(unsigned int pid) {
52 VLOG(2) << __func__ << " pid: " << pid;
53 configs_.erase(pid);
54}
55
Darin Petkov50308cd2011-06-01 18:25:07 -070056} // namespace shill