blob: ef75711492a8b765628f119f6e800e31526105f9 [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
Darin Petkovafa6fc42011-06-21 16:21:08 -070016#include "shill/ipconfig.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070017#include "shill/property_store.h"
Chris Masone2b105542011-06-22 10:58:09 -070018#include "shill/refptr_types.h"
Paul Stewart75897df2011-04-27 09:05:53 -070019#include "shill/shill_event.h"
20
21namespace shill {
22
Chris Masone9be4a9d2011-05-16 15:44:09 -070023class ControlInterface;
24class DeviceAdaptorInterface;
Chris Masonec1e50412011-06-07 13:04:53 -070025class DeviceInfo;
Paul Stewartf1ce5d22011-05-19 13:10:20 -070026class Endpoint;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070027class Error;
28class EventDispatcher;
Paul Stewartf1ce5d22011-05-19 13:10:20 -070029class Manager;
Chris Masone9be4a9d2011-05-16 15:44:09 -070030
Paul Stewart75897df2011-04-27 09:05:53 -070031// Device superclass. Individual network interfaces types will inherit from
32// this class.
Chris Masone2b105542011-06-22 10:58:09 -070033class Device : public base::RefCounted<Device>, public PropertyStore {
Paul Stewart75897df2011-04-27 09:05:53 -070034 public:
Chris Masone9be4a9d2011-05-16 15:44:09 -070035 enum Technology {
36 kEthernet,
37 kWifi,
38 kCellular,
Paul Stewartb50f0b92011-05-16 16:31:42 -070039 kBlackListed,
40 kUnknown,
Chris Masone9be4a9d2011-05-16 15:44:09 -070041 kNumTechnologies
42 };
Chris Masone0e1d1042011-05-09 18:07:03 -070043
Chris Masone9be4a9d2011-05-16 15:44:09 -070044 // A constructor for the Device object
45 Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070046 EventDispatcher *dispatcher,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070047 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070048 const std::string &link_name,
Paul Stewartb50f0b92011-05-16 16:31:42 -070049 int interface_index);
Chris Masone9be4a9d2011-05-16 15:44:09 -070050 virtual ~Device();
51
52 virtual void Start();
53 virtual void Stop();
54
Darin Petkovafa6fc42011-06-21 16:21:08 -070055 // Base method always returns false.
56 virtual bool TechnologyIs(const Technology type);
57
Paul Stewartf1ce5d22011-05-19 13:10:20 -070058 virtual void LinkEvent(unsigned flags, unsigned change);
59 virtual void Scan();
Paul Stewart75897df2011-04-27 09:05:53 -070060
Chris Masonec1e50412011-06-07 13:04:53 -070061 virtual void ConfigIP() {}
62
Chris Masoneb925cc82011-06-22 15:39:57 -070063 // Implementation of PropertyStore
Chris Masone3bd3c8c2011-06-13 08:20:26 -070064 virtual bool SetBoolProperty(const std::string& name,
65 bool value,
66 Error *error);
67 virtual bool SetInt32Property(const std::string& name,
68 int32 value,
69 Error *error);
70 virtual bool SetUint16Property(const std::string& name,
71 uint16 value,
72 Error *error);
Chris Masoneb925cc82011-06-22 15:39:57 -070073 virtual bool SetStringProperty(const std::string &name,
74 const std::string &value,
75 Error *error);
Chris Masone8fe2c7e2011-06-09 15:51:19 -070076
Darin Petkovafa6fc42011-06-21 16:21:08 -070077 const std::string &link_name() const { return link_name_; }
78
79 // Returns a string that is guaranteed to uniquely identify this Device
80 // instance.
81 const std::string &UniqueName() const;
Chris Masonea82b7112011-05-25 15:16:29 -070082
Paul Stewartd5843772011-05-11 15:40:42 -070083 protected:
Darin Petkovafa6fc42011-06-21 16:21:08 -070084 FRIEND_TEST(DeviceTest, AcquireDHCPConfig);
85 FRIEND_TEST(DeviceTest, DestroyIPConfig);
86 FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
87
88 // If there's an IP configuration in |ipconfig_|, releases the IP address and
89 // destroys the configuration instance.
90 void DestroyIPConfig();
91
92 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
93 // requests a new IP configuration. Registers a callback to
94 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
95 // request was successfully sent.
96 bool AcquireDHCPConfig();
97
Chris Masoneb925cc82011-06-22 15:39:57 -070098 void RegisterDerivedString(const std::string &name,
99 std::string(Device::*get)(void),
100 bool(Device::*set)(const std::string&));
101
102 // Properties
103 std::string hardware_address_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700104 bool powered_; // TODO(pstew): Is this what |running_| is for?
105 bool reconnect_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700106
Chris Masonec1e50412011-06-07 13:04:53 -0700107 std::vector<ServiceRefPtr> services_;
Paul Stewartb50f0b92011-05-16 16:31:42 -0700108 int interface_index_;
109 bool running_;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700110 Manager *manager_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700111 IPConfigRefPtr ipconfig_;
Paul Stewartd5843772011-05-11 15:40:42 -0700112
Paul Stewart75897df2011-04-27 09:05:53 -0700113 private:
Chris Masone413a3192011-05-09 17:10:05 -0700114 friend class DeviceAdaptorInterface;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700115
116 // Callback invoked on every IP configuration update.
Chris Masone2b105542011-06-22 10:58:09 -0700117 void IPConfigUpdatedCallback(const IPConfigRefPtr &ipconfig, bool success);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700118
119 const std::string link_name_;
120 scoped_ptr<DeviceAdaptorInterface> adaptor_;
121
Chris Masone9be4a9d2011-05-16 15:44:09 -0700122 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -0700123};
124
Paul Stewart75897df2011-04-27 09:05:53 -0700125} // namespace shill
126
127#endif // SHILL_DEVICE_