blob: 28da466a3e756337e5ef6fbd78748c2158de4f61 [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,
mukesh agrawal8f317b62011-07-15 11:53:23 -070039 kBlacklisted,
Paul Stewartb50f0b92011-05-16 16:31:42 -070040 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 Petkove0a312e2011-07-20 13:45:28 -070065 const std::string &link_name() const { return link_name_; }
66 int interface_index() const { return interface_index_; }
67
Chris Masone19e30402011-07-19 15:48:47 -070068 const std::string &FriendlyName() const;
Chris Masone27c4aa52011-07-02 13:10:14 -070069
Darin Petkovafa6fc42011-06-21 16:21:08 -070070 // Returns a string that is guaranteed to uniquely identify this Device
71 // instance.
72 const std::string &UniqueName() const;
Chris Masonea82b7112011-05-25 15:16:29 -070073
Chris Masone19e30402011-07-19 15:48:47 -070074 PropertyStore *store() { return &store_; }
75
Paul Stewartd5843772011-05-11 15:40:42 -070076 protected:
Darin Petkovafa6fc42011-06-21 16:21:08 -070077 FRIEND_TEST(DeviceTest, AcquireDHCPConfig);
78 FRIEND_TEST(DeviceTest, DestroyIPConfig);
79 FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
Chris Masone95207da2011-06-29 16:50:49 -070080 FRIEND_TEST(DeviceTest, GetProperties);
Darin Petkovafa6fc42011-06-21 16:21:08 -070081
82 // If there's an IP configuration in |ipconfig_|, releases the IP address and
83 // destroys the configuration instance.
84 void DestroyIPConfig();
85
86 // Creates a new DHCP IP configuration instance, stores it in |ipconfig_| and
87 // requests a new IP configuration. Registers a callback to
88 // IPConfigUpdatedCallback on IP configuration changes. Returns true if the IP
89 // request was successfully sent.
90 bool AcquireDHCPConfig();
91
Chris Masone27c4aa52011-07-02 13:10:14 -070092 void HelpRegisterDerivedString(const std::string &name,
Chris Masone889666b2011-07-03 12:58:50 -070093 std::string(Device::*get)(void),
94 bool(Device::*set)(const std::string&));
Chris Masone27c4aa52011-07-02 13:10:14 -070095 void HelpRegisterDerivedStrings(const std::string &name,
Chris Masone889666b2011-07-03 12:58:50 -070096 Strings(Device::*get)(void),
97 bool(Device::*set)(const Strings&));
Chris Masoneb925cc82011-06-22 15:39:57 -070098
99 // Properties
100 std::string hardware_address_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700101 bool powered_; // TODO(pstew): Is this what |running_| is for?
102 bool reconnect_;
Chris Masoneb925cc82011-06-22 15:39:57 -0700103
Chris Masone27c4aa52011-07-02 13:10:14 -0700104 PropertyStore store_;
105
Chris Masonec1e50412011-06-07 13:04:53 -0700106 std::vector<ServiceRefPtr> services_;
Darin Petkove0a312e2011-07-20 13:45:28 -0700107 const int interface_index_;
Paul Stewartb50f0b92011-05-16 16:31:42 -0700108 bool running_;
Chris Masone7df0c672011-07-15 10:24:54 -0700109 const std::string link_name_;
Chris Masone19e30402011-07-19 15:48:47 -0700110 const std::string unique_id_;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700111 Manager *manager_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700112 IPConfigRefPtr ipconfig_;
Paul Stewartd5843772011-05-11 15:40:42 -0700113
Paul Stewart75897df2011-04-27 09:05:53 -0700114 private:
Chris Masone413a3192011-05-09 17:10:05 -0700115 friend class DeviceAdaptorInterface;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700116
117 // Callback invoked on every IP configuration update.
Chris Masone2b105542011-06-22 10:58:09 -0700118 void IPConfigUpdatedCallback(const IPConfigRefPtr &ipconfig, bool success);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700119
Chris Masone4e851612011-07-01 10:46:53 -0700120 std::vector<std::string> AvailableIPConfigs();
121 std::string GetRpcConnectionIdentifier();
122
Darin Petkovafa6fc42011-06-21 16:21:08 -0700123 scoped_ptr<DeviceAdaptorInterface> adaptor_;
124
Chris Masone9be4a9d2011-05-16 15:44:09 -0700125 DISALLOW_COPY_AND_ASSIGN(Device);
Paul Stewart75897df2011-04-27 09:05:53 -0700126};
127
Paul Stewart75897df2011-04-27 09:05:53 -0700128} // namespace shill
129
130#endif // SHILL_DEVICE_