Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 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_MODEM_ |
| 6 | #define SHILL_MODEM_ |
| 7 | |
| 8 | #include <string> |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 9 | #include <vector> |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 10 | |
| 11 | #include <base/basictypes.h> |
| 12 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 14 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 15 | #include "shill/cellular.h" |
| 16 | #include "shill/dbus_objectmanager_proxy_interface.h" |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 17 | #include "shill/dbus_properties_proxy_interface.h" |
| 18 | #include "shill/refptr_types.h" |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 19 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 20 | struct mobile_provider_db; |
| 21 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 22 | namespace shill { |
| 23 | |
| 24 | class ControlInterface; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 25 | class EventDispatcher; |
| 26 | class Manager; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 27 | class Metrics; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 28 | class ProxyFactory; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 29 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 30 | // Handles an instance of ModemManager.Modem and an instance of a Cellular |
| 31 | // device. |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 32 | class Modem { |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 33 | public: |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 34 | // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is |
| 35 | // the ModemManager.Modem DBus object path (e.g., |
| 36 | // "/org/chromium/ModemManager/Gobi/0"). |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 37 | Modem(const std::string &owner, |
| 38 | const std::string &path, |
| 39 | ControlInterface *control_interface, |
| 40 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 41 | Metrics *metrics, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 42 | Manager *manager, |
| 43 | mobile_provider_db *provider_db); |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 44 | ~Modem(); |
| 45 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 46 | // Asynchronously initializes support for the modem. If the |
| 47 | // |modem_properties| are valid and the MAC address is present, |
| 48 | // constructs and registers a Cellular device in |device_| based on |
| 49 | // |modem_properties|. |
| 50 | virtual void CreateDeviceFromModemProperties( |
| 51 | const DBusPropertiesMap &modem_properties); |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 52 | |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 53 | void OnDeviceInfoAvailable(const std::string &link_name); |
| 54 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 55 | const std::string &owner() const { return owner_; } |
| 56 | const std::string &path() const { return path_; } |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 57 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 58 | void set_type(Cellular::Type type) { type_ = type; } |
| 59 | |
| 60 | protected: |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 61 | static const char kPropertyLinkName[]; |
| 62 | static const char kPropertyIPMethod[]; |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 63 | static const char kPropertyState[]; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 64 | static const char kPropertyType[]; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 65 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 66 | ControlInterface *control_interface() const { return control_interface_; } |
| 67 | CellularRefPtr device() const { return device_; } |
| 68 | EventDispatcher *dispatcher() const { return dispatcher_; } |
| 69 | Manager *manager() const { return manager_; } |
| 70 | Metrics *metrics() const { return metrics_; } |
| 71 | mobile_provider_db *provider_db() const { return provider_db_; } |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 72 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 73 | virtual Cellular *ConstructCellular(const std::string &link_name, |
| 74 | const std::string &device_name, |
| 75 | int interface_index); |
| 76 | virtual Cellular::ModemState ConvertMmToCellularModemState( |
| 77 | uint32 input) const = 0; |
| 78 | virtual bool GetLinkName(const DBusPropertiesMap &properties, |
| 79 | std::string *name) const = 0; |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 80 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 81 | private: |
| 82 | friend class ModemTest; |
| 83 | FRIEND_TEST(ModemManager1Test, Connect); |
| 84 | FRIEND_TEST(ModemManagerClassicTest, Connect); |
| 85 | FRIEND_TEST(ModemManagerCoreTest, ShouldAddModem); |
| 86 | FRIEND_TEST(ModemTest, CreateDeviceEarlyFailures); |
| 87 | FRIEND_TEST(ModemTest, EarlyDeviceProperties); |
| 88 | FRIEND_TEST(ModemTest, Init); |
| 89 | FRIEND_TEST(ModemTest, PendingDevicePropertiesAndCreate); |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 90 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 91 | DBusPropertiesMap initial_modem_properties_; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 92 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 93 | const std::string owner_; |
| 94 | const std::string path_; |
| 95 | |
| 96 | CellularRefPtr device_; |
| 97 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 98 | ControlInterface *control_interface_; |
| 99 | EventDispatcher *dispatcher_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 100 | Metrics *metrics_; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 101 | Manager *manager_; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 102 | mobile_provider_db *provider_db_; |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 103 | std::string link_name_; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 104 | Cellular::Type type_; |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 105 | bool pending_device_info_; |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 106 | RTNLHandler *rtnl_handler_; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 107 | |
| 108 | DISALLOW_COPY_AND_ASSIGN(Modem); |
| 109 | }; |
| 110 | |
David Rochberg | fa1d31d | 2012-03-20 10:38:07 -0400 | [diff] [blame] | 111 | class ModemClassic : public Modem, public DBusPropertiesProxyDelegate { |
| 112 | public: |
| 113 | ModemClassic(const std::string &owner, |
| 114 | const std::string &path, |
| 115 | ControlInterface *control_interface, |
| 116 | EventDispatcher *dispatcher, |
| 117 | Metrics *metrics, |
| 118 | Manager *manager, |
| 119 | mobile_provider_db *provider_db); |
| 120 | virtual ~ModemClassic(); |
| 121 | |
| 122 | // Gathers information and passes it to CreateDeviceFromModemProperties. |
| 123 | void CreateDeviceClassic(const DBusPropertiesMap &modem_properties); |
| 124 | |
| 125 | // Signal callbacks inherited from DBusPropertiesProxyDelegate. |
| 126 | virtual void OnDBusPropertiesChanged( |
| 127 | const std::string &interface, |
| 128 | const DBusPropertiesMap &changed_properties, |
| 129 | const std::vector<std::string> &invalidated_properties); |
| 130 | virtual void OnModemManagerPropertiesChanged( |
| 131 | const std::string &interface, |
| 132 | const DBusPropertiesMap &properties); |
| 133 | |
| 134 | protected: |
| 135 | virtual Cellular::ModemState ConvertMmToCellularModemState( |
| 136 | uint32 input) const; |
| 137 | virtual bool GetLinkName(const DBusPropertiesMap &modem_properties, |
| 138 | std::string *name) const; |
| 139 | |
| 140 | private: |
| 141 | DISALLOW_COPY_AND_ASSIGN(ModemClassic); |
| 142 | }; |
| 143 | |
| 144 | class Modem1 : public Modem { |
| 145 | // TODO(rochberg) Need to register to receive DBus property changes. |
| 146 | // crosbug.com/28596 |
| 147 | public: |
| 148 | Modem1(const std::string &owner, |
| 149 | const std::string &path, |
| 150 | ControlInterface *control_interface, |
| 151 | EventDispatcher *dispatcher, |
| 152 | Metrics *metrics, |
| 153 | Manager *manager, |
| 154 | mobile_provider_db *provider_db); |
| 155 | virtual ~Modem1(); |
| 156 | |
| 157 | // Gathers information and passes it to CreateDeviceFromModemProperties. |
| 158 | void CreateDeviceMM1(const DBusInterfaceToProperties &i_to_p); |
| 159 | |
| 160 | protected: |
| 161 | virtual Cellular::ModemState ConvertMmToCellularModemState( |
| 162 | uint32 input) const; |
| 163 | virtual bool GetLinkName(const DBusPropertiesMap &modem_properties, |
| 164 | std::string *name) const; |
| 165 | |
| 166 | private: |
| 167 | DISALLOW_COPY_AND_ASSIGN(Modem1); |
| 168 | }; |
| 169 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 170 | } // namespace shill |
| 171 | |
| 172 | #endif // SHILL_MODEM_ |