blob: d3d7310a7c1e5766f0e849121c24a5f10fd0c23d [file] [log] [blame]
Paul Stewartdd60e452011-08-08 11:38:36 -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_CONNECTION_
6#define SHILL_CONNECTION_
7
8#include <string>
9#include <vector>
10
11#include <base/memory/ref_counted.h>
12#include <gtest/gtest_prod.h> // for FRIEND_TEST
13
14#include "shill/refptr_types.h"
15
16namespace shill {
17
18class Resolver;
19class RoutingTable;
20class RTNLHandler;
21
22// The Conneciton maintains the implemented state of an IPConfig, e.g,
23// the IP address, routing table and DNS table entries.
24class Connection : public base::RefCounted<Connection> {
25 public:
26 Connection(int interface_index, const std::string& interface_name);
27 virtual ~Connection();
28
29 // Add the contents of an IPConfig reference to the list of managed state.
30 // This will replace all previous state for this address family.
31 void UpdateFromIPConfig(const IPConfigRefPtr &config);
32
33 // Sets the current connection as "default", i.e., routes and DNS entries
34 // should be used by all system components that don't select explicitly.
35 bool is_default() const { return is_default_; }
36 void SetDefault(bool is_default);
37
38 private:
39 friend class ConnectionTest;
40 FRIEND_TEST(ConnectionTest, InitState);
41 FRIEND_TEST(ConnectionTest, AddConfig);
42 FRIEND_TEST(ConnectionTest, AddConfigReverse);
43 FRIEND_TEST(ConnectionTest, Destructor);
44
45 static const uint32 kDefaultMetric;
46 static const uint32 kNonDefaultMetric;
47
48 bool is_default_;
49 int interface_index_;
50 const std::string interface_name_;
51 std::vector<std::string> dns_servers_;
52 std::vector<std::string> dns_domain_search_;
53
54 // Store cached copies of singletons for speed/ease of testing
55 Resolver *resolver_;
56 RoutingTable *routing_table_;
57 RTNLHandler *rtnl_handler_;
58
59 DISALLOW_COPY_AND_ASSIGN(Connection);
60};
61
62} // namespace shill
63
64#endif // SHILL_CONNECTION_