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