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