blob: 7e5551e7b6ceb22524e3de84cebe38591fbc17fb [file] [log] [blame]
Darin Petkove02b3ca2011-05-31 16:00:44 -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/ipconfig.h"
6
7#include <base/logging.h>
Chris Masone43b48a12011-07-01 13:37:07 -07008#include <chromeos/dbus/service_constants.h>
Darin Petkove02b3ca2011-05-31 16:00:44 -07009
Chris Masonec6c6c132011-06-30 11:29:52 -070010#include "shill/adaptor_interfaces.h"
Chris Masone19e30402011-07-19 15:48:47 -070011#include "shill/control_interface.h"
Chris Masone43b48a12011-07-01 13:37:07 -070012#include "shill/error.h"
Chris Masonec6c6c132011-06-30 11:29:52 -070013
Darin Petkove02b3ca2011-05-31 16:00:44 -070014using std::string;
15
16namespace shill {
17
Chris Masone0756f232011-07-21 17:24:00 -070018// static
19const char IPConfig::kType[] = "ip";
20// static
21uint IPConfig::global_serial_ = 0;
22
Chris Masone19e30402011-07-19 15:48:47 -070023IPConfig::IPConfig(ControlInterface *control_interface,
24 const std::string &device_name)
25 : device_name_(device_name),
Chris Masone0756f232011-07-21 17:24:00 -070026 type_(kType),
27 serial_(global_serial_++),
Chris Masone19e30402011-07-19 15:48:47 -070028 adaptor_(control_interface->CreateIPConfigAdaptor(this)) {
Chris Masone0756f232011-07-21 17:24:00 -070029 Init();
30}
31
32IPConfig::IPConfig(ControlInterface *control_interface,
33 const std::string &device_name,
34 const std::string &type)
35 : device_name_(device_name),
36 type_(type),
37 serial_(global_serial_++),
38 adaptor_(control_interface->CreateIPConfigAdaptor(this)) {
39 Init();
40}
41
42void IPConfig::Init() {
Chris Masone43b48a12011-07-01 13:37:07 -070043 // Address might be R/O or not, depending on the type of IPconfig, so
44 // we'll leave this up to the subclasses.
45 // Register(Const?)String(flimflam::kAddressProperty, &properties_.address);
Chris Masone27c4aa52011-07-02 13:10:14 -070046 store_.RegisterString(flimflam::kBroadcastProperty,
47 &properties_.broadcast_address);
48 store_.RegisterString(flimflam::kDomainNameProperty,
49 &properties_.domain_name);
50 store_.RegisterString(flimflam::kGatewayProperty, &properties_.gateway);
51 store_.RegisterConstString(flimflam::kMethodProperty, &properties_.method);
52 store_.RegisterInt32(flimflam::kMtuProperty, &properties_.mtu);
53 store_.RegisterStrings(flimflam::kNameServersProperty,
54 &properties_.dns_servers);
55 store_.RegisterString(flimflam::kPeerAddressProperty,
56 &properties_.peer_address);
57 store_.RegisterInt32(flimflam::kPrefixlenProperty, &properties_.subnet_cidr);
Chris Masone43b48a12011-07-01 13:37:07 -070058 // TODO(cmasone): Does anyone use this?
Chris Masone27c4aa52011-07-02 13:10:14 -070059 // store_.RegisterStrings(flimflam::kSearchDomainsProperty,
60 // &properties_.domain_search);
Chris Masone0756f232011-07-21 17:24:00 -070061 VLOG(2) << __func__ << " device: " << device_name();
Darin Petkove02b3ca2011-05-31 16:00:44 -070062}
63
64IPConfig::~IPConfig() {
Darin Petkovf65e9282011-06-21 14:29:56 -070065 VLOG(2) << __func__ << " device: " << device_name();
Darin Petkove02b3ca2011-05-31 16:00:44 -070066}
67
Chris Masone4e851612011-07-01 10:46:53 -070068string IPConfig::GetRpcIdentifier() {
69 return adaptor_->GetRpcIdentifier();
70}
71
Darin Petkov92c43902011-06-09 20:46:06 -070072bool IPConfig::RequestIP() {
Darin Petkove7cb7f82011-06-03 13:21:51 -070073 return false;
74}
75
Darin Petkov92c43902011-06-09 20:46:06 -070076bool IPConfig::RenewIP() {
77 return false;
78}
79
80bool IPConfig::ReleaseIP() {
Darin Petkove7cb7f82011-06-03 13:21:51 -070081 return false;
82}
83
Darin Petkovf9b0ca82011-06-20 12:10:23 -070084void IPConfig::UpdateProperties(const Properties &properties, bool success) {
Darin Petkove7cb7f82011-06-03 13:21:51 -070085 properties_ = properties;
Darin Petkovefb09c32011-06-07 20:24:17 -070086 if (update_callback_.get()) {
Darin Petkovf9b0ca82011-06-20 12:10:23 -070087 update_callback_->Run(this, success);
Darin Petkovefb09c32011-06-07 20:24:17 -070088 }
89}
90
91void IPConfig::RegisterUpdateCallback(
Chris Masone2b105542011-06-22 10:58:09 -070092 Callback2<const IPConfigRefPtr&, bool>::Type *callback) {
Darin Petkovefb09c32011-06-07 20:24:17 -070093 update_callback_.reset(callback);
Darin Petkove7cb7f82011-06-03 13:21:51 -070094}
95
Darin Petkove02b3ca2011-05-31 16:00:44 -070096} // namespace shill