blob: 4fd96d6d4cd6ca6898d52e76d648423b9a532ad1 [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 Masone8fe2c7e2011-06-09 15:51:19 -070011#include <base/basictypes.h>
Chris Masone487b8bf2011-05-13 16:27:57 -070012#include <base/memory/ref_counted.h>
Paul Stewartb50f0b92011-05-16 16:31:42 -070013#include <base/memory/scoped_ptr.h>
Darin Petkovafa6fc42011-06-21 16:21:08 -070014#include <gtest/gtest_prod.h> // for FRIEND_TEST
Paul Stewartd5843772011-05-11 15:40:42 -070015
Chris Masonec1e50412011-06-07 13:04:53 -070016#include "shill/device_config_interface.h"
Darin Petkovafa6fc42011-06-21 16:21:08 -070017#include "shill/ipconfig.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070018#include "shill/property_store_interface.h"
Chris Masone9be4a9d2011-05-16 15:44:09 -070019#include "shill/service.h"
Paul Stewart75897df2011-04-27 09:05:53 -070020#include "shill/shill_event.h"
21
22namespace shill {
23
Chris Masone9be4a9d2011-05-16 15:44:09 -070024class ControlInterface;
Chris Masonec1e50412011-06-07 13:04:53 -070025class Device;
Chris Masone9be4a9d2011-05-16 15:44:09 -070026class DeviceAdaptorInterface;
Chris Masonec1e50412011-06-07 13:04:53 -070027class DeviceInfo;
Paul Stewartf1ce5d22011-05-19 13:10:20 -070028class Endpoint;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070029class Error;
30class EventDispatcher;
Paul Stewartf1ce5d22011-05-19 13:10:20 -070031class Manager;
Chris Masone9be4a9d2011-05-16 15:44:09 -070032
Chris Masonec1e50412011-06-07 13:04:53 -070033typedef scoped_refptr<const Device> DeviceConstRefPtr;
34typedef scoped_refptr<Device> DeviceRefPtr;
35
Paul Stewart75897df2011-04-27 09:05:53 -070036// Device superclass. Individual network interfaces types will inherit from
37// this class.
Chris Masone8fe2c7e2011-06-09 15:51:19 -070038class Device : public DeviceConfigInterface, public PropertyStoreInterface {
Paul Stewart75897df2011-04-27 09:05:53 -070039 public:
Chris Masone9be4a9d2011-05-16 15:44:09 -070040 enum Technology {
41 kEthernet,
42 kWifi,
43 kCellular,
Paul Stewartb50f0b92011-05-16 16:31:42 -070044 kBlackListed,
45 kUnknown,
Chris Masone9be4a9d2011-05-16 15:44:09 -070046 kNumTechnologies
47 };
Chris Masone0e1d1042011-05-09 18:07:03 -070048
Chris Masone9be4a9d2011-05-16 15:44:09 -070049 // A constructor for the Device object
50 Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070051 EventDispatcher *dispatcher,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070052 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070053 const std::string &link_name,
Paul Stewartb50f0b92011-05-16 16:31:42 -070054 int interface_index);
Chris Masone9be4a9d2011-05-16 15:44:09 -070055 virtual ~Device();
56
57 virtual void Start();
58 virtual void Stop();
59
Darin Petkovafa6fc42011-06-21 16:21:08 -070060 // Base method always returns false.
61 virtual bool TechnologyIs(const Technology type);
62
Paul Stewartf1ce5d22011-05-19 13:10:20 -070063 virtual void LinkEvent(unsigned flags, unsigned change);
64 virtual void Scan();
Paul Stewart75897df2011-04-27 09:05:53 -070065
Chris Masonec1e50412011-06-07 13:04:53 -070066 // Implementation of DeviceConfigInterface
67 virtual void ConfigIP() {}
68
Chris Masone8fe2c7e2011-06-09 15:51:19 -070069 // Implementation of PropertyStoreInterface
70 bool SetBoolProperty(const std::string& name, bool value, Error *error);
71 bool SetInt16Property(const std::string& name, int16 value, Error *error);
72 bool SetInt32Property(const std::string& name, int32 value, Error *error);
73 bool SetStringProperty(const std::string& name,
74 const std::string& value,
75 Error *error);
76 bool SetUint16Property(const std::string& name, uint16 value, Error *error);
77 bool SetUint32Property(const std::string& name, uint32 value, Error *error);
78
Darin Petkovafa6fc42011-06-21 16:21:08 -070079 const std::string &link_name() const { return link_name_; }
80
81 // Returns a string that is guaranteed to uniquely identify this Device
82 // instance.
83 const std::string &UniqueName() const;
Chris Masonea82b7112011-05-25 15:16:29 -070084
Paul Stewartd5843772011-05-11 15:40:42 -070085 protected:
Darin Petkovafa6fc42011-06-21 16:21:08 -070086 FRIEND_TEST(DeviceTest, AcquireDHCPConfig);
87 FRIEND_TEST(DeviceTest, DestroyIPConfig);
88 FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
89
90 // If there's an IP configuration in |ipconfig_|, releases the IP address and
91 // destroys the configuration instance.
92 void DestroyIPConfig();
93
94 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
95 // requests a new IP configuration. Registers a callback to
96 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
97 // request was successfully sent.
98 bool AcquireDHCPConfig();
99
Chris Masonec1e50412011-06-07 13:04:53 -0700100 std::vector<ServiceRefPtr> services_;
Paul Stewartb50f0b92011-05-16 16:31:42 -0700101 int interface_index_;
102 bool running_;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700103 Manager *manager_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700104 IPConfigRefPtr ipconfig_;
Paul Stewartd5843772011-05-11 15:40:42 -0700105
Paul Stewart75897df2011-04-27 09:05:53 -0700106 private:
Chris Masone413a3192011-05-09 17:10:05 -0700107 friend class DeviceAdaptorInterface;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700108
109 // Callback invoked on every IP configuration update.
110 void IPConfigUpdatedCallback(IPConfigRefPtr ipconfig, bool success);
111
112 const std::string link_name_;
113 scoped_ptr<DeviceAdaptorInterface> adaptor_;
114
Chris Masone9be4a9d2011-05-16 15:44:09 -0700115 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -0700116};
117
Paul Stewart75897df2011-04-27 09:05:53 -0700118} // namespace shill
119
120#endif // SHILL_DEVICE_