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 | 887f298 | 2011-07-14 16:10:17 -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_MANAGER_ |
| 6 | #define SHILL_MODEM_MANAGER_ |
| 7 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 8 | #include <map> |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 9 | #include <string> |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 10 | #include <tr1/memory> |
| 11 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 12 | #include <base/basictypes.h> |
Darin Petkov | c90fe52 | 2011-07-15 13:59:47 -0700 | [diff] [blame] | 13 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 15 | |
| 16 | #include "shill/glib.h" |
| 17 | |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 18 | struct mobile_provider_db; |
| 19 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 20 | namespace shill { |
| 21 | |
| 22 | class ControlInterface; |
| 23 | class EventDispatcher; |
| 24 | class Manager; |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 25 | class Modem; |
Darin Petkov | c90fe52 | 2011-07-15 13:59:47 -0700 | [diff] [blame] | 26 | class ModemManagerProxyInterface; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 27 | class ProxyFactory; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 28 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 29 | // Handles a modem manager service and creates and destroys modem instances. |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 30 | class ModemManager { |
| 31 | public: |
| 32 | ModemManager(const std::string &service, |
| 33 | const std::string &path, |
| 34 | ControlInterface *control_interface, |
| 35 | EventDispatcher *dispatcher, |
| 36 | Manager *manager, |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 37 | GLib *glib, |
| 38 | mobile_provider_db *provider_db); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 39 | ~ModemManager(); |
| 40 | |
| 41 | // Starts watching for and handling the DBus modem manager service. |
| 42 | void Start(); |
| 43 | |
| 44 | // Stops watching for the DBus modem manager service and destroys any |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 45 | // associated modems. |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 46 | void Stop(); |
| 47 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 48 | // Adds a modem on |path|. |
| 49 | void AddModem(const std::string &path); |
| 50 | |
| 51 | // Removes a modem on |path|. |
| 52 | void RemoveModem(const std::string &path); |
| 53 | |
Darin Petkov | 41c0e0a | 2012-01-09 16:38:53 +0100 | [diff] [blame] | 54 | void OnDeviceInfoAvailable(const std::string &link_name); |
| 55 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 56 | private: |
| 57 | friend class ModemManagerTest; |
| 58 | FRIEND_TEST(ModemInfoTest, RegisterModemManager); |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 59 | FRIEND_TEST(ModemManagerTest, AddRemoveModem); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 60 | FRIEND_TEST(ModemManagerTest, Connect); |
| 61 | FRIEND_TEST(ModemManagerTest, Disconnect); |
| 62 | FRIEND_TEST(ModemManagerTest, OnAppear); |
| 63 | FRIEND_TEST(ModemManagerTest, OnVanish); |
| 64 | FRIEND_TEST(ModemManagerTest, Start); |
| 65 | FRIEND_TEST(ModemManagerTest, Stop); |
| 66 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 67 | typedef std::map<std::string, std::tr1::shared_ptr<Modem> > Modems; |
| 68 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 69 | // Connects a newly appeared modem manager service. |
| 70 | void Connect(const std::string &owner); |
| 71 | |
| 72 | // Disconnects a vanished modem manager service. |
| 73 | void Disconnect(); |
| 74 | |
| 75 | // DBus service watcher callbacks. |
| 76 | static void OnAppear(GDBusConnection *connection, |
| 77 | const gchar *name, |
| 78 | const gchar *name_owner, |
| 79 | gpointer user_data); |
| 80 | static void OnVanish(GDBusConnection *connection, |
| 81 | const gchar *name, |
| 82 | gpointer user_data); |
| 83 | |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 84 | // Store cached copies of singletons for speed/ease of testing. |
| 85 | ProxyFactory *proxy_factory_; |
| 86 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 87 | const std::string service_; |
| 88 | const std::string path_; |
| 89 | guint watcher_id_; |
| 90 | |
Darin Petkov | c90fe52 | 2011-07-15 13:59:47 -0700 | [diff] [blame] | 91 | std::string owner_; // DBus service owner. |
| 92 | scoped_ptr<ModemManagerProxyInterface> proxy_; // DBus service proxy. |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 93 | |
Darin Petkov | 5c97ac5 | 2011-07-19 16:30:49 -0700 | [diff] [blame] | 94 | Modems modems_; // Maps a modem |path| to a modem instance. |
| 95 | |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 96 | ControlInterface *control_interface_; |
| 97 | EventDispatcher *dispatcher_; |
| 98 | Manager *manager_; |
| 99 | GLib *glib_; |
Darin Petkov | 137884a | 2011-10-26 18:52:47 +0200 | [diff] [blame] | 100 | mobile_provider_db *provider_db_; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 101 | |
| 102 | DISALLOW_COPY_AND_ASSIGN(ModemManager); |
| 103 | }; |
| 104 | |
| 105 | } // namespace shill |
| 106 | |
| 107 | #endif // SHILL_MODEM_MANAGER_ |