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 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 16 | #include "shill/device_config_interface.h" |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 17 | #include "shill/ipconfig.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame^] | 18 | #include "shill/property_store.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 19 | #include "shill/service.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 20 | #include "shill/shill_event.h" |
| 21 | |
| 22 | namespace shill { |
| 23 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 24 | class ControlInterface; |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 25 | class Device; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 26 | class DeviceAdaptorInterface; |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 27 | class DeviceInfo; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 28 | class Endpoint; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 29 | class Error; |
| 30 | class EventDispatcher; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 31 | class Manager; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 32 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 33 | typedef scoped_refptr<const Device> DeviceConstRefPtr; |
| 34 | typedef scoped_refptr<Device> DeviceRefPtr; |
| 35 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 36 | // Device superclass. Individual network interfaces types will inherit from |
| 37 | // this class. |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame^] | 38 | // DeviceConfigInterface is RefCounted, so this class and derived classes |
| 39 | // are as well. |
| 40 | class Device : public DeviceConfigInterface, public PropertyStore { |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 41 | public: |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 42 | enum Technology { |
| 43 | kEthernet, |
| 44 | kWifi, |
| 45 | kCellular, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 46 | kBlackListed, |
| 47 | kUnknown, |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 48 | kNumTechnologies |
| 49 | }; |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 50 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 51 | // A constructor for the Device object |
| 52 | Device(ControlInterface *control_interface, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 53 | EventDispatcher *dispatcher, |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 54 | Manager *manager, |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 55 | const std::string &link_name, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 56 | int interface_index); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 57 | virtual ~Device(); |
| 58 | |
| 59 | virtual void Start(); |
| 60 | virtual void Stop(); |
| 61 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 62 | // Base method always returns false. |
| 63 | virtual bool TechnologyIs(const Technology type); |
| 64 | |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 65 | virtual void LinkEvent(unsigned flags, unsigned change); |
| 66 | virtual void Scan(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 67 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 68 | // Implementation of DeviceConfigInterface |
| 69 | virtual void ConfigIP() {} |
| 70 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame^] | 71 | // Implementation of PropertyStore |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 72 | virtual bool SetBoolProperty(const std::string& name, |
| 73 | bool value, |
| 74 | Error *error); |
| 75 | virtual bool SetInt32Property(const std::string& name, |
| 76 | int32 value, |
| 77 | Error *error); |
| 78 | virtual bool SetUint16Property(const std::string& name, |
| 79 | uint16 value, |
| 80 | Error *error); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame^] | 81 | virtual bool SetStringProperty(const std::string &name, |
| 82 | const std::string &value, |
| 83 | Error *error); |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 84 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 85 | const std::string &link_name() const { return link_name_; } |
| 86 | |
| 87 | // Returns a string that is guaranteed to uniquely identify this Device |
| 88 | // instance. |
| 89 | const std::string &UniqueName() const; |
Chris Masone | a82b711 | 2011-05-25 15:16:29 -0700 | [diff] [blame] | 90 | |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 91 | protected: |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 92 | FRIEND_TEST(DeviceTest, AcquireDHCPConfig); |
| 93 | FRIEND_TEST(DeviceTest, DestroyIPConfig); |
| 94 | FRIEND_TEST(DeviceTest, DestroyIPConfigNULL); |
| 95 | |
| 96 | // If there's an IP configuration in |ipconfig_|, releases the IP address and |
| 97 | // destroys the configuration instance. |
| 98 | void DestroyIPConfig(); |
| 99 | |
| 100 | // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and |
| 101 | // requests a new IP configuration. Registers a callback to |
| 102 | // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP |
| 103 | // request was successfully sent. |
| 104 | bool AcquireDHCPConfig(); |
| 105 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame^] | 106 | void RegisterDerivedString(const std::string &name, |
| 107 | std::string(Device::*get)(void), |
| 108 | bool(Device::*set)(const std::string&)); |
| 109 | |
| 110 | // Properties |
| 111 | std::string hardware_address_; |
| 112 | std::string bgscan_method_; |
| 113 | uint16 bgscan_short_interval_; |
| 114 | int32 bgscan_signal_threshold_; |
| 115 | bool powered_; // TODO(pstew): Is this what |running_| is for? |
| 116 | bool reconnect_; |
| 117 | uint16 scan_interval_; |
| 118 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 119 | std::vector<ServiceRefPtr> services_; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 120 | int interface_index_; |
| 121 | bool running_; |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 122 | Manager *manager_; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 123 | IPConfigRefPtr ipconfig_; |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 124 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 125 | private: |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 126 | friend class DeviceAdaptorInterface; |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 127 | |
| 128 | // Callback invoked on every IP configuration update. |
| 129 | void IPConfigUpdatedCallback(IPConfigRefPtr ipconfig, bool success); |
| 130 | |
| 131 | const std::string link_name_; |
| 132 | scoped_ptr<DeviceAdaptorInterface> adaptor_; |
| 133 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 134 | DISALLOW_COPY_AND_ASSIGN(Device); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 137 | } // namespace shill |
| 138 | |
| 139 | #endif // SHILL_DEVICE_ |