Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -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/ipconfig.h" |
| 6 | |
| 7 | #include <base/logging.h> |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 8 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 9 | |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 10 | #include "shill/adaptor_interfaces.h" |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 11 | #include "shill/control_interface.h" |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 12 | #include "shill/error.h" |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 13 | |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 14 | using std::string; |
| 15 | |
| 16 | namespace shill { |
| 17 | |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame^] | 18 | // static |
| 19 | const char IPConfig::kType[] = "ip"; |
| 20 | // static |
| 21 | uint IPConfig::global_serial_ = 0; |
| 22 | |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 23 | IPConfig::IPConfig(ControlInterface *control_interface, |
| 24 | const std::string &device_name) |
| 25 | : device_name_(device_name), |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame^] | 26 | type_(kType), |
| 27 | serial_(global_serial_++), |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 28 | adaptor_(control_interface->CreateIPConfigAdaptor(this)) { |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame^] | 29 | Init(); |
| 30 | } |
| 31 | |
| 32 | IPConfig::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 | |
| 42 | void IPConfig::Init() { |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 43 | // 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 Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 46 | 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 Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 58 | // TODO(cmasone): Does anyone use this? |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 59 | // store_.RegisterStrings(flimflam::kSearchDomainsProperty, |
| 60 | // &properties_.domain_search); |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame^] | 61 | VLOG(2) << __func__ << " device: " << device_name(); |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | IPConfig::~IPConfig() { |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 65 | VLOG(2) << __func__ << " device: " << device_name(); |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Chris Masone | 4e85161 | 2011-07-01 10:46:53 -0700 | [diff] [blame] | 68 | string IPConfig::GetRpcIdentifier() { |
| 69 | return adaptor_->GetRpcIdentifier(); |
| 70 | } |
| 71 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 72 | bool IPConfig::RequestIP() { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 73 | return false; |
| 74 | } |
| 75 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 76 | bool IPConfig::RenewIP() { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | bool IPConfig::ReleaseIP() { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 81 | return false; |
| 82 | } |
| 83 | |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 84 | void IPConfig::UpdateProperties(const Properties &properties, bool success) { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 85 | properties_ = properties; |
Darin Petkov | efb09c3 | 2011-06-07 20:24:17 -0700 | [diff] [blame] | 86 | if (update_callback_.get()) { |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 87 | update_callback_->Run(this, success); |
Darin Petkov | efb09c3 | 2011-06-07 20:24:17 -0700 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | void IPConfig::RegisterUpdateCallback( |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 92 | Callback2<const IPConfigRefPtr&, bool>::Type *callback) { |
Darin Petkov | efb09c3 | 2011-06-07 20:24:17 -0700 | [diff] [blame] | 93 | update_callback_.reset(callback); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 96 | } // namespace shill |