blob: 5e2ae32e7f1318914ef22b6ce3cd33dcd5c3bd85 [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#ifndef SHILL_IPCONFIG_
6#define SHILL_IPCONFIG_
7
8#include <string>
Darin Petkove7cb7f82011-06-03 13:21:51 -07009#include <vector>
Darin Petkove02b3ca2011-05-31 16:00:44 -070010
Darin Petkovefb09c32011-06-07 20:24:17 -070011#include <base/callback_old.h>
Darin Petkove02b3ca2011-05-31 16:00:44 -070012#include <base/memory/ref_counted.h>
Darin Petkovefb09c32011-06-07 20:24:17 -070013#include <base/memory/scoped_ptr.h>
14#include <gtest/gtest_prod.h> // for FRIEND_TEST
Darin Petkove02b3ca2011-05-31 16:00:44 -070015
Chris Masonec1e50412011-06-07 13:04:53 -070016#include "shill/device.h"
Darin Petkove02b3ca2011-05-31 16:00:44 -070017
Chris Masonec1e50412011-06-07 13:04:53 -070018namespace shill {
Darin Petkove02b3ca2011-05-31 16:00:44 -070019
Darin Petkovefb09c32011-06-07 20:24:17 -070020class IPConfig;
21
22typedef scoped_refptr<IPConfig> IPConfigRefPtr;
23
Darin Petkove02b3ca2011-05-31 16:00:44 -070024// IPConfig superclass. Individual IP configuration types will inherit from this
25// class.
26class IPConfig : public base::RefCounted<IPConfig> {
27 public:
Darin Petkove7cb7f82011-06-03 13:21:51 -070028 struct Properties {
29 Properties() : subnet_cidr(0), mtu(0) {}
30
31 std::string address;
32 int subnet_cidr;
33 std::string broadcast_address;
34 std::string gateway;
35 std::vector<std::string> dns_servers;
36 std::string domain_name;
37 std::vector<std::string> domain_search;
38 int mtu;
39 };
40
Chris Masonec1e50412011-06-07 13:04:53 -070041 explicit IPConfig(DeviceConstRefPtr device);
Darin Petkove02b3ca2011-05-31 16:00:44 -070042 virtual ~IPConfig();
43
Chris Masonec1e50412011-06-07 13:04:53 -070044 DeviceConstRefPtr device() const { return device_; }
Darin Petkove02b3ca2011-05-31 16:00:44 -070045 const std::string &GetDeviceName() const;
46
Darin Petkovefb09c32011-06-07 20:24:17 -070047 // Registers a callback that's executed every time the configuration
48 // properties change. Takes ownership of |callback|. Pass NULL to remove a
49 // callback. The callback's argument is a pointer to this IP configuration
50 // instance allowing clients to more easily manage multiple IP configurations.
51 void RegisterUpdateCallback(Callback1<IPConfigRefPtr>::Type *callback);
Darin Petkove7cb7f82011-06-03 13:21:51 -070052
53 const Properties &properties() const { return properties_; }
54
55 // Request or renew IP configuration. Return true on success, false
56 // otherwise. The default implementation always returns false indicating a
57 // failure.
58 virtual bool Request();
59 virtual bool Renew();
Darin Petkovd1b715b2011-06-02 21:21:22 -070060
Darin Petkovefb09c32011-06-07 20:24:17 -070061 protected:
62 // Updates the IP configuration properties and notifies registered listeners
63 // about the event.
64 void UpdateProperties(const Properties &properties);
65
Darin Petkove02b3ca2011-05-31 16:00:44 -070066 private:
Darin Petkovefb09c32011-06-07 20:24:17 -070067 FRIEND_TEST(IPConfigTest, UpdateCallback);
68 FRIEND_TEST(IPConfigTest, UpdateProperties);
69
Chris Masonec1e50412011-06-07 13:04:53 -070070 DeviceConstRefPtr device_;
Darin Petkove7cb7f82011-06-03 13:21:51 -070071 Properties properties_;
Darin Petkovefb09c32011-06-07 20:24:17 -070072 scoped_ptr<Callback1<IPConfigRefPtr>::Type> update_callback_;
Darin Petkove02b3ca2011-05-31 16:00:44 -070073
74 DISALLOW_COPY_AND_ASSIGN(IPConfig);
75};
76
77} // namespace shill
78
79#endif // SHILL_IPCONFIG_