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