Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 1 | // 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 | |
| 16 | namespace shill { |
| 17 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame^] | 18 | class DeviceInfo; |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 19 | class Resolver; |
| 20 | class RoutingTable; |
| 21 | class RTNLHandler; |
| 22 | |
| 23 | // The Conneciton maintains the implemented state of an IPConfig, e.g, |
| 24 | // the IP address, routing table and DNS table entries. |
| 25 | class Connection : public base::RefCounted<Connection> { |
| 26 | public: |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame^] | 27 | Connection(int interface_index, |
| 28 | const std::string &interface_name, |
| 29 | const DeviceInfo *device_info); |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 30 | 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 Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame^] | 58 | const DeviceInfo *device_info_; |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 59 | 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_ |