Paul Stewart | 75897df | 2011-04-27 09:05:53 -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_DEVICE_ |
| 6 | #define SHILL_DEVICE_ |
| 7 | |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 8 | #include <string> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 11 | #include <base/basictypes.h> |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 12 | #include <base/memory/ref_counted.h> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 13 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 15 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 16 | #include "shill/ipconfig.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 17 | #include "shill/property_store.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 18 | #include "shill/refptr_types.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 19 | #include "shill/shill_event.h" |
| 20 | |
| 21 | namespace shill { |
| 22 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 23 | class ControlInterface; |
| 24 | class DeviceAdaptorInterface; |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 25 | class DeviceInfo; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 26 | class Endpoint; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 27 | class Error; |
| 28 | class EventDispatcher; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 29 | class Manager; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 30 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 31 | // Device superclass. Individual network interfaces types will inherit from |
| 32 | // this class. |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 33 | class Device : public base::RefCounted<Device> { |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 34 | public: |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 35 | enum Technology { |
| 36 | kEthernet, |
| 37 | kWifi, |
| 38 | kCellular, |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 39 | kBlacklisted, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 40 | kUnknown, |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 41 | kNumTechnologies |
| 42 | }; |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 43 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 44 | // A constructor for the Device object |
| 45 | Device(ControlInterface *control_interface, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 46 | EventDispatcher *dispatcher, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 47 | Manager *manager, |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 48 | const std::string &link_name, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 49 | int interface_index); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 50 | virtual ~Device(); |
| 51 | |
| 52 | virtual void Start(); |
| 53 | virtual void Stop(); |
| 54 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 55 | // Base method always returns false. |
| 56 | virtual bool TechnologyIs(const Technology type); |
| 57 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 58 | virtual void LinkEvent(unsigned flags, unsigned change); |
| 59 | virtual void Scan(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 60 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 61 | virtual void ConfigIP() {} |
| 62 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 63 | std::string GetRpcIdentifier(); |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame^] | 64 | std::string GetStorageIdentifier(); |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 65 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 66 | const std::string &link_name() const { return link_name_; } |
| 67 | int interface_index() const { return interface_index_; } |
| 68 | |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 69 | const std::string &FriendlyName() const; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 70 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 71 | // Returns a string that is guaranteed to uniquely identify this Device |
| 72 | // instance. |
| 73 | const std::string &UniqueName() const; |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 74 | |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 75 | PropertyStore *store() { return &store_; } |
| 76 | |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame^] | 77 | bool Load(StoreInterface *storage); |
| 78 | bool Save(StoreInterface *storage); |
| 79 | |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 80 | protected: |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 81 | FRIEND_TEST(DeviceTest, AcquireDHCPConfig); |
| 82 | FRIEND_TEST(DeviceTest, DestroyIPConfig); |
| 83 | FRIEND_TEST(DeviceTest, DestroyIPConfigNULL); |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 84 | FRIEND_TEST(DeviceTest, GetProperties); |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame^] | 85 | FRIEND_TEST(DeviceTest, Save); |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 86 | |
| 87 | // If there's an IP configuration in |ipconfig_|, releases the IP address and |
| 88 | // destroys the configuration instance. |
| 89 | void DestroyIPConfig(); |
| 90 | |
| 91 | // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and |
| 92 | // requests a new IP configuration. Registers a callback to |
| 93 | // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP |
| 94 | // request was successfully sent. |
| 95 | bool AcquireDHCPConfig(); |
| 96 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 97 | void HelpRegisterDerivedStrings(const std::string &name, |
Chris Masone | 889666b | 2011-07-03 12:58:50 -0700 | [diff] [blame] | 98 | Strings(Device::*get)(void), |
| 99 | bool(Device::*set)(const Strings&)); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 100 | |
| 101 | // Properties |
| 102 | std::string hardware_address_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 103 | bool powered_; // TODO(pstew): Is this what |running_| is for? |
| 104 | bool reconnect_; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 105 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 106 | PropertyStore store_; |
| 107 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 108 | std::vector<ServiceRefPtr> services_; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 109 | const int interface_index_; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 110 | bool running_; |
Chris Masone | 7df0c67 | 2011-07-15 10:24:54 -0700 | [diff] [blame] | 111 | const std::string link_name_; |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 112 | const std::string unique_id_; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 113 | Manager *manager_; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 114 | IPConfigRefPtr ipconfig_; |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 115 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 116 | private: |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 117 | friend class DeviceAdaptorInterface; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 118 | |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame^] | 119 | static const char kStoragePowered[]; |
| 120 | static const char kStorageIPConfigs[]; |
| 121 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 122 | // Callback invoked on every IP configuration update. |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 123 | void IPConfigUpdatedCallback(const IPConfigRefPtr &ipconfig, bool success); |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 124 | |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame^] | 125 | // Right now, Devices reference IPConfigs directly when persisted to disk |
| 126 | // It's not clear that this makes sense long-term, but that's how it is now. |
| 127 | // This call generates a string in the right format for this persisting. |
| 128 | std::string SerializeIPConfigsForStorage(); |
| 129 | |
Chris Masone | 4e85161 | 2011-07-01 10:46:53 -0700 | [diff] [blame] | 130 | std::vector<std::string> AvailableIPConfigs(); |
| 131 | std::string GetRpcConnectionIdentifier(); |
| 132 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 133 | scoped_ptr<DeviceAdaptorInterface> adaptor_; |
| 134 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 135 | DISALLOW_COPY_AND_ASSIGN(Device); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 138 | } // namespace shill |
| 139 | |
| 140 | #endif // SHILL_DEVICE_ |