blob: f822b2ccdbee184ec8787d075844c7eb092d73b9 [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
Darin Petkov92c43902011-06-09 20:46:06 -070055 // Request, renew and release IP configuration. Return true on success, false
Darin Petkove7cb7f82011-06-03 13:21:51 -070056 // otherwise. The default implementation always returns false indicating a
57 // failure.
Darin Petkov92c43902011-06-09 20:46:06 -070058 virtual bool RequestIP();
59 virtual bool RenewIP();
60 virtual bool ReleaseIP();
Darin Petkovd1b715b2011-06-02 21:21:22 -070061
Darin Petkovefb09c32011-06-07 20:24:17 -070062 protected:
63 // Updates the IP configuration properties and notifies registered listeners
64 // about the event.
65 void UpdateProperties(const Properties &properties);
66
Darin Petkove02b3ca2011-05-31 16:00:44 -070067 private:
Darin Petkovefb09c32011-06-07 20:24:17 -070068 FRIEND_TEST(IPConfigTest, UpdateCallback);
69 FRIEND_TEST(IPConfigTest, UpdateProperties);
70
Chris Masonec1e50412011-06-07 13:04:53 -070071 DeviceConstRefPtr device_;
Darin Petkove7cb7f82011-06-03 13:21:51 -070072 Properties properties_;
Darin Petkovefb09c32011-06-07 20:24:17 -070073 scoped_ptr<Callback1<IPConfigRefPtr>::Type> update_callback_;
Darin Petkove02b3ca2011-05-31 16:00:44 -070074
75 DISALLOW_COPY_AND_ASSIGN(IPConfig);
76};
77
78} // namespace shill
79
80#endif // SHILL_IPCONFIG_