blob: 8e9bca8b998abd766bb199592738f45bee83e6a3 [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 Masone46eaaf52011-05-24 13:08:30 -07008#include <string>
Chris Masone9be4a9d2011-05-16 15:44:09 -07009#include <vector>
10
Chris Masone487b8bf2011-05-13 16:27:57 -070011#include <base/memory/ref_counted.h>
Paul Stewartb50f0b92011-05-16 16:31:42 -070012#include <base/memory/scoped_ptr.h>
Paul Stewartd5843772011-05-11 15:40:42 -070013
Chris Masone9be4a9d2011-05-16 15:44:09 -070014#include "shill/service.h"
Paul Stewart75897df2011-04-27 09:05:53 -070015#include "shill/shill_event.h"
16
17namespace shill {
18
Chris Masone9be4a9d2011-05-16 15:44:09 -070019class ControlInterface;
20class DeviceAdaptorInterface;
21class EventDispatcher;
22
Paul Stewart75897df2011-04-27 09:05:53 -070023// Device superclass. Individual network interfaces types will inherit from
24// this class.
Paul Stewartd5843772011-05-11 15:40:42 -070025class Device : public base::RefCounted<Device> {
Paul Stewart75897df2011-04-27 09:05:53 -070026 public:
Chris Masone9be4a9d2011-05-16 15:44:09 -070027 enum Technology {
28 kEthernet,
29 kWifi,
30 kCellular,
Paul Stewartb50f0b92011-05-16 16:31:42 -070031 kBlackListed,
32 kUnknown,
Chris Masone9be4a9d2011-05-16 15:44:09 -070033 kNumTechnologies
34 };
Chris Masone0e1d1042011-05-09 18:07:03 -070035
Chris Masone9be4a9d2011-05-16 15:44:09 -070036 // A constructor for the Device object
37 Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070038 EventDispatcher *dispatcher,
Chris Masone46eaaf52011-05-24 13:08:30 -070039 const std::string& link_name,
Paul Stewartb50f0b92011-05-16 16:31:42 -070040 int interface_index);
Chris Masone9be4a9d2011-05-16 15:44:09 -070041 virtual ~Device();
42
43 virtual void Start();
44 virtual void Stop();
45
Paul Stewartb50f0b92011-05-16 16:31:42 -070046 virtual bool TechnologyIs(const Technology type) = 0;
Paul Stewart75897df2011-04-27 09:05:53 -070047
Paul Stewartd5843772011-05-11 15:40:42 -070048 protected:
Chris Masone9be4a9d2011-05-16 15:44:09 -070049 std::vector<scoped_refptr<Service> > services_;
Chris Masone46eaaf52011-05-24 13:08:30 -070050 std::string link_name_;
Paul Stewartb50f0b92011-05-16 16:31:42 -070051 int interface_index_;
52 bool running_;
Paul Stewartd5843772011-05-11 15:40:42 -070053
Paul Stewart75897df2011-04-27 09:05:53 -070054 private:
Paul Stewartb50f0b92011-05-16 16:31:42 -070055 scoped_ptr<DeviceAdaptorInterface> adaptor_;
56 friend class base::RefCounted<Device>;
Chris Masone413a3192011-05-09 17:10:05 -070057 friend class DeviceAdaptorInterface;
Chris Masone9be4a9d2011-05-16 15:44:09 -070058 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -070059};
60
Paul Stewartb50f0b92011-05-16 16:31:42 -070061// Non-functional Device subclass used for non-operable or blacklisted devices
62class StubDevice : public Device {
63 public:
64 StubDevice(ControlInterface *control_interface,
65 EventDispatcher *dispatcher,
Chris Masone46eaaf52011-05-24 13:08:30 -070066 const std::string& link_name,
Paul Stewartb50f0b92011-05-16 16:31:42 -070067 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 Stewart75897df2011-04-27 09:05:53 -070080} // namespace shill
81
82#endif // SHILL_DEVICE_