blob: 44ebd0f711f508c84bddfa32c23a964cb64177f3 [file] [log] [blame]
Paul Stewart75897df2011-04-27 09:05:53 -07001// 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 Masone9be4a9d2011-05-16 15:44:09 -07008#include <vector>
9
Chris Masone487b8bf2011-05-13 16:27:57 -070010#include <base/memory/ref_counted.h>
Paul Stewartb50f0b92011-05-16 16:31:42 -070011#include <base/memory/scoped_ptr.h>
Paul Stewartd5843772011-05-11 15:40:42 -070012
Chris Masone9be4a9d2011-05-16 15:44:09 -070013#include "shill/service.h"
Paul Stewart75897df2011-04-27 09:05:53 -070014#include "shill/shill_event.h"
15
16namespace shill {
17
Chris Masone9be4a9d2011-05-16 15:44:09 -070018class ControlInterface;
19class DeviceAdaptorInterface;
20class EventDispatcher;
21
Paul Stewart75897df2011-04-27 09:05:53 -070022// Device superclass. Individual network interfaces types will inherit from
23// this class.
Paul Stewartd5843772011-05-11 15:40:42 -070024class Device : public base::RefCounted<Device> {
Paul Stewart75897df2011-04-27 09:05:53 -070025 public:
Chris Masone9be4a9d2011-05-16 15:44:09 -070026 enum Technology {
27 kEthernet,
28 kWifi,
29 kCellular,
Paul Stewartb50f0b92011-05-16 16:31:42 -070030 kBlackListed,
31 kUnknown,
Chris Masone9be4a9d2011-05-16 15:44:09 -070032 kNumTechnologies
33 };
Chris Masone0e1d1042011-05-09 18:07:03 -070034
Chris Masone9be4a9d2011-05-16 15:44:09 -070035 // A constructor for the Device object
36 Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070037 EventDispatcher *dispatcher,
38 const string &link_name,
39 int interface_index);
Chris Masone9be4a9d2011-05-16 15:44:09 -070040 virtual ~Device();
41
42 virtual void Start();
43 virtual void Stop();
44
Paul Stewartb50f0b92011-05-16 16:31:42 -070045 virtual bool TechnologyIs(const Technology type) = 0;
Paul Stewart75897df2011-04-27 09:05:53 -070046
Paul Stewartd5843772011-05-11 15:40:42 -070047 protected:
Chris Masone9be4a9d2011-05-16 15:44:09 -070048 std::vector<scoped_refptr<Service> > services_;
Paul Stewartb50f0b92011-05-16 16:31:42 -070049 string link_name_;
50 int interface_index_;
51 bool running_;
Paul Stewartd5843772011-05-11 15:40:42 -070052
Paul Stewart75897df2011-04-27 09:05:53 -070053 private:
Paul Stewartb50f0b92011-05-16 16:31:42 -070054 scoped_ptr<DeviceAdaptorInterface> adaptor_;
55 friend class base::RefCounted<Device>;
Chris Masone413a3192011-05-09 17:10:05 -070056 friend class DeviceAdaptorInterface;
Chris Masone9be4a9d2011-05-16 15:44:09 -070057 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -070058};
59
Paul Stewartb50f0b92011-05-16 16:31:42 -070060// Non-functional Device subclass used for non-operable or blacklisted devices
61class 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 Stewart75897df2011-04-27 09:05:53 -070079} // namespace shill
80
81#endif // SHILL_DEVICE_