[shill] Add getting/setting for ipconfig properties

BUG=chromium-os:17261
TEST=unit tests

Change-Id: I96aed7c979c7913c568d00ce408a662898969d76
Reviewed-on: http://gerrit.chromium.org/gerrit/3583
Tested-by: Chris Masone <cmasone@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
diff --git a/ipconfig.cc b/ipconfig.cc
index a1d4182..b8c55d7 100644
--- a/ipconfig.cc
+++ b/ipconfig.cc
@@ -5,14 +5,31 @@
 #include "shill/ipconfig.h"
 
 #include <base/logging.h>
+#include <base/stl_util-inl.h>
+#include <chromeos/dbus/service_constants.h>
 
 #include "shill/adaptor_interfaces.h"
+#include "shill/error.h"
 
 using std::string;
 
 namespace shill {
 
 IPConfig::IPConfig(const std::string &device_name) : device_name_(device_name) {
+  // Address might be R/O or not, depending on the type of IPconfig, so
+  // we'll leave this up to the subclasses.
+  // Register(Const?)String(flimflam::kAddressProperty, &properties_.address);
+  RegisterString(flimflam::kBroadcastProperty, &properties_.broadcast_address);
+  RegisterString(flimflam::kDomainNameProperty, &properties_.domain_name);
+  RegisterString(flimflam::kGatewayProperty, &properties_.gateway);
+  RegisterConstString(flimflam::kMethodProperty, &properties_.method);
+  RegisterInt32(flimflam::kMtuProperty, &properties_.mtu);
+  RegisterStrings(flimflam::kNameServersProperty, &properties_.dns_servers);
+  RegisterString(flimflam::kPeerAddressProperty, &properties_.peer_address);
+  RegisterInt32(flimflam::kPrefixlenProperty, &properties_.subnet_cidr);
+  // TODO(cmasone): Does anyone use this?
+  // RegisterStrings(flimflam::kSearchDomainsProperty,
+  //                 &properties_.domain_search);
   VLOG(2) << __func__ << " device: " << device_name;
 }
 
@@ -36,6 +53,28 @@
   return false;
 }
 
+bool IPConfig::SetInt32Property(const std::string& name,
+                                int32 value,
+                                Error *error) {
+  VLOG(2) << "Setting " << name << " as an int32.";
+  bool set = (ContainsKey(int32_properties_, name) &&
+              int32_properties_[name]->Set(value));
+  if (!set && error)
+    error->Populate(Error::kInvalidArguments, name + " is not a R/W int32.");
+  return set;
+}
+
+bool IPConfig::SetStringProperty(const string& name,
+                                 const string& value,
+                                 Error *error) {
+  VLOG(2) << "Setting " << name << " as a string.";
+  bool set = (ContainsKey(string_properties_, name) &&
+              string_properties_[name]->Set(value));
+  if (!set && error)
+    error->Populate(Error::kInvalidArguments, name + " is not a R/W string.");
+  return set;
+}
+
 void IPConfig::UpdateProperties(const Properties &properties, bool success) {
   properties_ = properties;
   if (update_callback_.get()) {