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 | |
| 8 | #include <base/basictypes.h> |
| 9 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 10 | |
| 11 | #include "shill/glib.h" |
| 12 | |
| 13 | namespace shill { |
| 14 | |
| 15 | class ControlInterface; |
| 16 | class EventDispatcher; |
| 17 | class Manager; |
| 18 | |
| 19 | // Handles a modem manager service and creates and destroys cellular devices. |
| 20 | class ModemManager { |
| 21 | public: |
| 22 | ModemManager(const std::string &service, |
| 23 | const std::string &path, |
| 24 | ControlInterface *control_interface, |
| 25 | EventDispatcher *dispatcher, |
| 26 | Manager *manager, |
| 27 | GLib *glib); |
| 28 | ~ModemManager(); |
| 29 | |
| 30 | // Starts watching for and handling the DBus modem manager service. |
| 31 | void Start(); |
| 32 | |
| 33 | // Stops watching for the DBus modem manager service and destroys any |
| 34 | // associated modem devices. |
| 35 | void Stop(); |
| 36 | |
| 37 | private: |
| 38 | friend class ModemManagerTest; |
| 39 | FRIEND_TEST(ModemInfoTest, RegisterModemManager); |
| 40 | FRIEND_TEST(ModemManagerTest, Connect); |
| 41 | FRIEND_TEST(ModemManagerTest, Disconnect); |
| 42 | FRIEND_TEST(ModemManagerTest, OnAppear); |
| 43 | FRIEND_TEST(ModemManagerTest, OnVanish); |
| 44 | FRIEND_TEST(ModemManagerTest, Start); |
| 45 | FRIEND_TEST(ModemManagerTest, Stop); |
| 46 | |
| 47 | // Connects a newly appeared modem manager service. |
| 48 | void Connect(const std::string &owner); |
| 49 | |
| 50 | // Disconnects a vanished modem manager service. |
| 51 | void Disconnect(); |
| 52 | |
| 53 | // DBus service watcher callbacks. |
| 54 | static void OnAppear(GDBusConnection *connection, |
| 55 | const gchar *name, |
| 56 | const gchar *name_owner, |
| 57 | gpointer user_data); |
| 58 | static void OnVanish(GDBusConnection *connection, |
| 59 | const gchar *name, |
| 60 | gpointer user_data); |
| 61 | |
| 62 | const std::string service_; |
| 63 | const std::string path_; |
| 64 | guint watcher_id_; |
| 65 | |
| 66 | // DBus service owner. |
| 67 | std::string owner_; |
| 68 | |
| 69 | ControlInterface *control_interface_; |
| 70 | EventDispatcher *dispatcher_; |
| 71 | Manager *manager_; |
| 72 | GLib *glib_; |
| 73 | |
| 74 | DISALLOW_COPY_AND_ASSIGN(ModemManager); |
| 75 | }; |
| 76 | |
| 77 | } // namespace shill |
| 78 | |
| 79 | #endif // SHILL_MODEM_MANAGER_ |