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 | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 10 | #include <base/memory/ref_counted.h> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame^] | 11 | #include <base/memory/scoped_ptr.h> |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 12 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 13 | #include "shill/service.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 14 | #include "shill/shill_event.h" |
| 15 | |
| 16 | namespace shill { |
| 17 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 18 | class ControlInterface; |
| 19 | class DeviceAdaptorInterface; |
| 20 | class EventDispatcher; |
| 21 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 22 | // Device superclass. Individual network interfaces types will inherit from |
| 23 | // this class. |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 24 | class Device : public base::RefCounted<Device> { |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 25 | public: |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 26 | enum Technology { |
| 27 | kEthernet, |
| 28 | kWifi, |
| 29 | kCellular, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame^] | 30 | kBlackListed, |
| 31 | kUnknown, |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 32 | kNumTechnologies |
| 33 | }; |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 34 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 35 | // A constructor for the Device object |
| 36 | Device(ControlInterface *control_interface, |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame^] | 37 | EventDispatcher *dispatcher, |
| 38 | const string &link_name, |
| 39 | int interface_index); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 40 | virtual ~Device(); |
| 41 | |
| 42 | virtual void Start(); |
| 43 | virtual void Stop(); |
| 44 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame^] | 45 | virtual bool TechnologyIs(const Technology type) = 0; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 46 | |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 47 | protected: |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 48 | std::vector<scoped_refptr<Service> > services_; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame^] | 49 | string link_name_; |
| 50 | int interface_index_; |
| 51 | bool running_; |
Paul Stewart | d584377 | 2011-05-11 15:40:42 -0700 | [diff] [blame] | 52 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 53 | private: |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame^] | 54 | scoped_ptr<DeviceAdaptorInterface> adaptor_; |
| 55 | friend class base::RefCounted<Device>; |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 56 | friend class DeviceAdaptorInterface; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 57 | DISALLOW_COPY_AND_ASSIGN(Device); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame^] | 60 | // Non-functional Device subclass used for non-operable or blacklisted devices |
| 61 | class StubDevice : public Device { |
| 62 | public: |
| 63 | StubDevice(ControlInterface *control_interface, |
| 64 | EventDispatcher *dispatcher, |
| 65 | const string link_name, |
| 66 | int interface_index, |
| 67 | Technology technology) |
| 68 | : Device(control_interface, dispatcher, link_name, interface_index), |
| 69 | technology_(technology) {} |
| 70 | void Start() {} |
| 71 | void Stop() {} |
| 72 | bool TechnologyIs(const Technology type) { return type == technology_; } |
| 73 | |
| 74 | private: |
| 75 | Technology technology_; |
| 76 | DISALLOW_COPY_AND_ASSIGN(StubDevice); |
| 77 | }; |
| 78 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 79 | } // namespace shill |
| 80 | |
| 81 | #endif // SHILL_DEVICE_ |