blob: 03d425ab875c913211d25427ecbe7a782cda7797 [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 Masoneb925cc82011-06-22 15:39:57 -070018#include "shill/property_store.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 Masoneb925cc82011-06-22 15:39:57 -070038// DeviceConfigInterface is RefCounted, so this class and derived classes
39// are as well.
40class Device : public DeviceConfigInterface, public PropertyStore {
Paul Stewart75897df2011-04-27 09:05:53 -070041 public:
Chris Masone9be4a9d2011-05-16 15:44:09 -070042 enum Technology {
43 kEthernet,
44 kWifi,
45 kCellular,
Paul Stewartb50f0b92011-05-16 16:31:42 -070046 kBlackListed,
47 kUnknown,
Chris Masone9be4a9d2011-05-16 15:44:09 -070048 kNumTechnologies
49 };
Chris Masone0e1d1042011-05-09 18:07:03 -070050
Chris Masone9be4a9d2011-05-16 15:44:09 -070051 // A constructor for the Device object
52 Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070053 EventDispatcher *dispatcher,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070054 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070055 const std::string &link_name,
Paul Stewartb50f0b92011-05-16 16:31:42 -070056 int interface_index);
Chris Masone9be4a9d2011-05-16 15:44:09 -070057 virtual ~Device();
58
59 virtual void Start();
60 virtual void Stop();
61
Darin Petkovafa6fc42011-06-21 16:21:08 -070062 // Base method always returns false.
63 virtual bool TechnologyIs(const Technology type);
64
Paul Stewartf1ce5d22011-05-19 13:10:20 -070065 virtual void LinkEvent(unsigned flags, unsigned change);
66 virtual void Scan();
Paul Stewart75897df2011-04-27 09:05:53 -070067
Chris Masonec1e50412011-06-07 13:04:53 -070068 // Implementation of DeviceConfigInterface
69 virtual void ConfigIP() {}
70
Chris Masoneb925cc82011-06-22 15:39:57 -070071 // Implementation of PropertyStore
Chris Masone3bd3c8c2011-06-13 08:20:26 -070072 virtual bool SetBoolProperty(const std::string& name,
73 bool value,
74 Error *error);
75 virtual bool SetInt32Property(const std::string& name,
76 int32 value,
77 Error *error);
78 virtual bool SetUint16Property(const std::string& name,
79 uint16 value,
80 Error *error);
Chris Masoneb925cc82011-06-22 15:39:57 -070081 virtual bool SetStringProperty(const std::string &name,
82 const std::string &value,
83 Error *error);
Chris Masone8fe2c7e2011-06-09 15:51:19 -070084
Darin Petkovafa6fc42011-06-21 16:21:08 -070085 const std::string &link_name() const { return link_name_; }
86
87 // Returns a string that is guaranteed to uniquely identify this Device
88 // instance.
89 const std::string &UniqueName() const;
Chris Masonea82b7112011-05-25 15:16:29 -070090
Paul Stewartd5843772011-05-11 15:40:42 -070091 protected:
Darin Petkovafa6fc42011-06-21 16:21:08 -070092 FRIEND_TEST(DeviceTest, AcquireDHCPConfig);
93 FRIEND_TEST(DeviceTest, DestroyIPConfig);
94 FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
95
96 // If there's an IP configuration in |ipconfig_|, releases the IP address and
97 // destroys the configuration instance.
98 void DestroyIPConfig();
99
100 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
101 // requests a new IP configuration. Registers a callback to
102 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
103 // request was successfully sent.
104 bool AcquireDHCPConfig();
105
Chris Masoneb925cc82011-06-22 15:39:57 -0700106 void RegisterDerivedString(const std::string &name,
107 std::string(Device::*get)(void),
108 bool(Device::*set)(const std::string&));
109
110 // Properties
111 std::string hardware_address_;
112 std::string bgscan_method_;
113 uint16 bgscan_short_interval_;
114 int32 bgscan_signal_threshold_;
115 bool powered_; // TODO(pstew): Is this what |running_| is for?
116 bool reconnect_;
117 uint16 scan_interval_;
118
Chris Masonec1e50412011-06-07 13:04:53 -0700119 std::vector<ServiceRefPtr> services_;
Paul Stewartb50f0b92011-05-16 16:31:42 -0700120 int interface_index_;
121 bool running_;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700122 Manager *manager_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700123 IPConfigRefPtr ipconfig_;
Paul Stewartd5843772011-05-11 15:40:42 -0700124
Paul Stewart75897df2011-04-27 09:05:53 -0700125 private:
Chris Masone413a3192011-05-09 17:10:05 -0700126 friend class DeviceAdaptorInterface;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700127
128 // Callback invoked on every IP configuration update.
129 void IPConfigUpdatedCallback(IPConfigRefPtr ipconfig, bool success);
130
131 const std::string link_name_;
132 scoped_ptr<DeviceAdaptorInterface> adaptor_;
133
Chris Masone9be4a9d2011-05-16 15:44:09 -0700134 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -0700135};
136
Paul Stewart75897df2011-04-27 09:05:53 -0700137} // namespace shill
138
139#endif // SHILL_DEVICE_