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 | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 13 | #include <base/task.h> |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 15 | |
| 16 | #include "shill/dbus_properties_proxy_interface.h" |
| 17 | #include "shill/refptr_types.h" |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 18 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 19 | struct mobile_provider_db; |
| 20 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 21 | namespace shill { |
| 22 | |
| 23 | class ControlInterface; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 24 | class EventDispatcher; |
| 25 | class Manager; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 26 | class ProxyFactory; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 27 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 28 | // Handles an instance of ModemManager.Modem and an instance of a Cellular |
| 29 | // device. |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 30 | class Modem : public DBusPropertiesProxyDelegate { |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 31 | public: |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 32 | // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is |
| 33 | // the ModemManager.Modem DBus object path (e.g., |
| 34 | // "/org/chromium/ModemManager/Gobi/0"). |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 35 | Modem(const std::string &owner, |
| 36 | const std::string &path, |
| 37 | ControlInterface *control_interface, |
| 38 | EventDispatcher *dispatcher, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 39 | Manager *manager, |
| 40 | mobile_provider_db *provider_db); |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 41 | ~Modem(); |
| 42 | |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 43 | // Asynchronously initializes support for the modem, possibly constructing a |
| 44 | // Cellular device. |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 45 | void Init(); |
| 46 | |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 47 | void OnDeviceInfoAvailable(const std::string &link_name); |
| 48 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 49 | private: |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 50 | friend class ModemManagerTest; |
| 51 | friend class ModemTest; |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 52 | FRIEND_TEST(ModemManagerTest, Connect); |
| 53 | FRIEND_TEST(ModemManagerTest, AddRemoveModem); |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 54 | FRIEND_TEST(ModemTest, CreateDeviceFromProperties); |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 55 | FRIEND_TEST(ModemTest, Init); |
| 56 | |
| 57 | static const char kPropertyLinkName[]; |
| 58 | static const char kPropertyIPMethod[]; |
Darin Petkov | bac9600 | 2011-08-09 13:22:00 -0700 | [diff] [blame] | 59 | static const char kPropertyState[]; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 60 | static const char kPropertyType[]; |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 61 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 62 | void InitTask(); |
| 63 | |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 64 | // Creates and registers a Cellular device in |device_| based on |
| 65 | // ModemManager.Modem's |properties|. The device may not be created if the |
| 66 | // properties are invalid. |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 67 | void CreateDeviceFromProperties(const DBusPropertiesMap &properties); |
| 68 | void CreateDevice(); |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 69 | |
Darin Petkov | 580c7af | 2011-10-24 12:32:50 +0200 | [diff] [blame] | 70 | // Signal callbacks inherited from DBusPropertiesProxyDelegate. |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 71 | virtual void OnDBusPropertiesChanged( |
| 72 | const std::string &interface, |
| 73 | const DBusPropertiesMap &changed_properties, |
| 74 | const std::vector<std::string> &invalidated_properties); |
| 75 | virtual void OnModemManagerPropertiesChanged( |
| 76 | const std::string &interface, |
| 77 | const DBusPropertiesMap &properties); |
| 78 | |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 79 | // Store cached copies of singletons for speed/ease of testing. |
| 80 | ProxyFactory *proxy_factory_; |
| 81 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 82 | // A proxy to the org.freedesktop.DBus.Properties interface used to obtain |
| 83 | // ModemManager.Modem properties and watch for property changes. |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 84 | scoped_ptr<DBusPropertiesProxyInterface> dbus_properties_proxy_; |
| 85 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 86 | const std::string owner_; |
| 87 | const std::string path_; |
| 88 | |
| 89 | CellularRefPtr device_; |
| 90 | |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 91 | ScopedRunnableMethodFactory<Modem> task_factory_; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 92 | ControlInterface *control_interface_; |
| 93 | EventDispatcher *dispatcher_; |
| 94 | Manager *manager_; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 95 | mobile_provider_db *provider_db_; |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 96 | std::string link_name_; |
| 97 | bool pending_device_info_; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 98 | |
| 99 | DISALLOW_COPY_AND_ASSIGN(Modem); |
| 100 | }; |
| 101 | |
| 102 | } // namespace shill |
| 103 | |
| 104 | #endif // SHILL_MODEM_ |