shill: Connect Ethernet Device to DHCPConfig.
Most of the implementation is in the base Device class.
BUG=chromium-os:16794
TEST=unit test
Change-Id: I583761f7e54c88b043ce4343cb43f8298aaedf8b
Reviewed-on: http://gerrit.chromium.org/gerrit/2949
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Darin Petkov <petkov@chromium.org>
diff --git a/device.h b/device.h
index e258517..4fd96d6 100644
--- a/device.h
+++ b/device.h
@@ -11,8 +11,10 @@
#include <base/basictypes.h>
#include <base/memory/ref_counted.h>
#include <base/memory/scoped_ptr.h>
+#include <gtest/gtest_prod.h> // for FRIEND_TEST
#include "shill/device_config_interface.h"
+#include "shill/ipconfig.h"
#include "shill/property_store_interface.h"
#include "shill/service.h"
#include "shill/shill_event.h"
@@ -48,14 +50,16 @@
Device(ControlInterface *control_interface,
EventDispatcher *dispatcher,
Manager *manager,
- const std::string& link_name,
+ const std::string &link_name,
int interface_index);
virtual ~Device();
virtual void Start();
virtual void Stop();
- virtual bool TechnologyIs(const Technology type) = 0;
+ // Base method always returns false.
+ virtual bool TechnologyIs(const Technology type);
+
virtual void LinkEvent(unsigned flags, unsigned change);
virtual void Scan();
@@ -72,20 +76,42 @@
bool SetUint16Property(const std::string& name, uint16 value, Error *error);
bool SetUint32Property(const std::string& name, uint32 value, Error *error);
- // Returns a string that is guaranteed to uniquely identify this
- // Device instance.
- const std::string& UniqueName() const;
+ const std::string &link_name() const { return link_name_; }
+
+ // Returns a string that is guaranteed to uniquely identify this Device
+ // instance.
+ const std::string &UniqueName() const;
protected:
+ FRIEND_TEST(DeviceTest, AcquireDHCPConfig);
+ FRIEND_TEST(DeviceTest, DestroyIPConfig);
+ FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
+
+ // If there's an IP configuration in |ipconfig_|, releases the IP address and
+ // destroys the configuration instance.
+ void DestroyIPConfig();
+
+ // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
+ // requests a new IP configuration. Registers a callback to
+ // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
+ // request was successfully sent.
+ bool AcquireDHCPConfig();
+
std::vector<ServiceRefPtr> services_;
- std::string link_name_;
int interface_index_;
bool running_;
Manager *manager_;
+ IPConfigRefPtr ipconfig_;
private:
- scoped_ptr<DeviceAdaptorInterface> adaptor_;
friend class DeviceAdaptorInterface;
+
+ // Callback invoked on every IP configuration update.
+ void IPConfigUpdatedCallback(IPConfigRefPtr ipconfig, bool success);
+
+ const std::string link_name_;
+ scoped_ptr<DeviceAdaptorInterface> adaptor_;
+
DISALLOW_COPY_AND_ASSIGN(Device);
};