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