blob: 2b19897551e7628639076ecc917e441a5f59347f [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 Masone27c4aa52011-07-02 13:10:14 -070033class Device : public base::RefCounted<Device> {
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 Masone27c4aa52011-07-02 13:10:14 -070063 std::string GetRpcIdentifier();
Chris Masone8fe2c7e2011-06-09 15:51:19 -070064
Darin Petkovafa6fc42011-06-21 16:21:08 -070065 const std::string &link_name() const { return link_name_; }
66
Chris Masone27c4aa52011-07-02 13:10:14 -070067 PropertyStore *store() { return &store_; }
68
Darin Petkovafa6fc42011-06-21 16:21:08 -070069 // Returns a string that is guaranteed to uniquely identify this Device
70 // instance.
71 const std::string &UniqueName() const;
Chris Masonea82b7112011-05-25 15:16:29 -070072
Paul Stewartd5843772011-05-11 15:40:42 -070073 protected:
Darin Petkovafa6fc42011-06-21 16:21:08 -070074 FRIEND_TEST(DeviceTest, AcquireDHCPConfig);
75 FRIEND_TEST(DeviceTest, DestroyIPConfig);
76 FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
Chris Masone95207da2011-06-29 16:50:49 -070077 FRIEND_TEST(DeviceTest, GetProperties);
Darin Petkovafa6fc42011-06-21 16:21:08 -070078
79 // If there's an IP configuration in |ipconfig_|, releases the IP address and
80 // destroys the configuration instance.
81 void DestroyIPConfig();
82
83 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
84 // requests a new IP configuration. Registers a callback to
85 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
86 // request was successfully sent.
87 bool AcquireDHCPConfig();
88
Chris Masone27c4aa52011-07-02 13:10:14 -070089 void HelpRegisterDerivedString(const std::string &name,
Chris Masoneb925cc82011-06-22 15:39:57 -070090 std::string(Device::*get)(void),
91 bool(Device::*set)(const std::string&));
Chris Masone27c4aa52011-07-02 13:10:14 -070092 void HelpRegisterDerivedStrings(const std::string &name,
Chris Masone4e851612011-07-01 10:46:53 -070093 Strings(Device::*get)(void),
94 bool(Device::*set)(const Strings&));
Chris Masoneb925cc82011-06-22 15:39:57 -070095
96 // Properties
97 std::string hardware_address_;
Chris Masoneb925cc82011-06-22 15:39:57 -070098 bool powered_; // TODO(pstew): Is this what |running_| is for?
99 bool reconnect_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700100
Chris Masone27c4aa52011-07-02 13:10:14 -0700101 PropertyStore store_;
102
Chris Masonec1e50412011-06-07 13:04:53 -0700103 std::vector<ServiceRefPtr> services_;
Paul Stewartb50f0b92011-05-16 16:31:42 -0700104 int interface_index_;
105 bool running_;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700106 Manager *manager_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700107 IPConfigRefPtr ipconfig_;
Paul Stewartd5843772011-05-11 15:40:42 -0700108
Paul Stewart75897df2011-04-27 09:05:53 -0700109 private:
Chris Masone413a3192011-05-09 17:10:05 -0700110 friend class DeviceAdaptorInterface;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700111
112 // Callback invoked on every IP configuration update.
Chris Masone2b105542011-06-22 10:58:09 -0700113 void IPConfigUpdatedCallback(const IPConfigRefPtr &ipconfig, bool success);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700114
Chris Masone4e851612011-07-01 10:46:53 -0700115 std::vector<std::string> AvailableIPConfigs();
116 std::string GetRpcConnectionIdentifier();
117
Darin Petkovafa6fc42011-06-21 16:21:08 -0700118 const std::string link_name_;
119 scoped_ptr<DeviceAdaptorInterface> adaptor_;
120
Chris Masone9be4a9d2011-05-16 15:44:09 -0700121 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -0700122};
123
Paul Stewart75897df2011-04-27 09:05:53 -0700124} // namespace shill
125
126#endif // SHILL_DEVICE_