blob: f706b2b1e752610426246a48df5775b33498f574 [file] [log] [blame]
Darin Petkov887f2982011-07-14 16:10:17 -07001// 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 Petkov5c97ac52011-07-19 16:30:49 -07008#include <map>
9#include <tr1/memory>
10
Darin Petkov887f2982011-07-14 16:10:17 -070011#include <base/basictypes.h>
Darin Petkovc90fe522011-07-15 13:59:47 -070012#include <base/memory/scoped_ptr.h>
Darin Petkov887f2982011-07-14 16:10:17 -070013#include <gtest/gtest_prod.h> // for FRIEND_TEST
14
15#include "shill/glib.h"
16
17namespace shill {
18
19class ControlInterface;
20class EventDispatcher;
21class Manager;
Darin Petkov5c97ac52011-07-19 16:30:49 -070022class Modem;
Darin Petkovc90fe522011-07-15 13:59:47 -070023class ModemManagerProxyInterface;
Darin Petkovab565bb2011-10-06 02:55:51 -070024class ProxyFactory;
Darin Petkov887f2982011-07-14 16:10:17 -070025
Darin Petkov5c97ac52011-07-19 16:30:49 -070026// Handles a modem manager service and creates and destroys modem instances.
Darin Petkov887f2982011-07-14 16:10:17 -070027class ModemManager {
28 public:
29 ModemManager(const std::string &service,
30 const std::string &path,
31 ControlInterface *control_interface,
32 EventDispatcher *dispatcher,
33 Manager *manager,
34 GLib *glib);
35 ~ModemManager();
36
37 // Starts watching for and handling the DBus modem manager service.
38 void Start();
39
40 // Stops watching for the DBus modem manager service and destroys any
Darin Petkov5c97ac52011-07-19 16:30:49 -070041 // associated modems.
Darin Petkov887f2982011-07-14 16:10:17 -070042 void Stop();
43
Darin Petkov5c97ac52011-07-19 16:30:49 -070044 // Adds a modem on |path|.
45 void AddModem(const std::string &path);
46
47 // Removes a modem on |path|.
48 void RemoveModem(const std::string &path);
49
Darin Petkov887f2982011-07-14 16:10:17 -070050 private:
51 friend class ModemManagerTest;
52 FRIEND_TEST(ModemInfoTest, RegisterModemManager);
Darin Petkov5c97ac52011-07-19 16:30:49 -070053 FRIEND_TEST(ModemManagerTest, AddRemoveModem);
Darin Petkov887f2982011-07-14 16:10:17 -070054 FRIEND_TEST(ModemManagerTest, Connect);
55 FRIEND_TEST(ModemManagerTest, Disconnect);
56 FRIEND_TEST(ModemManagerTest, OnAppear);
57 FRIEND_TEST(ModemManagerTest, OnVanish);
58 FRIEND_TEST(ModemManagerTest, Start);
59 FRIEND_TEST(ModemManagerTest, Stop);
60
Darin Petkov5c97ac52011-07-19 16:30:49 -070061 typedef std::map<std::string, std::tr1::shared_ptr<Modem> > Modems;
62
Darin Petkov887f2982011-07-14 16:10:17 -070063 // Connects a newly appeared modem manager service.
64 void Connect(const std::string &owner);
65
66 // Disconnects a vanished modem manager service.
67 void Disconnect();
68
69 // DBus service watcher callbacks.
70 static void OnAppear(GDBusConnection *connection,
71 const gchar *name,
72 const gchar *name_owner,
73 gpointer user_data);
74 static void OnVanish(GDBusConnection *connection,
75 const gchar *name,
76 gpointer user_data);
77
Darin Petkovab565bb2011-10-06 02:55:51 -070078 // Store cached copies of singletons for speed/ease of testing.
79 ProxyFactory *proxy_factory_;
80
Darin Petkov887f2982011-07-14 16:10:17 -070081 const std::string service_;
82 const std::string path_;
83 guint watcher_id_;
84
Darin Petkovc90fe522011-07-15 13:59:47 -070085 std::string owner_; // DBus service owner.
86 scoped_ptr<ModemManagerProxyInterface> proxy_; // DBus service proxy.
Darin Petkov887f2982011-07-14 16:10:17 -070087
Darin Petkov5c97ac52011-07-19 16:30:49 -070088 Modems modems_; // Maps a modem |path| to a modem instance.
89
Darin Petkov887f2982011-07-14 16:10:17 -070090 ControlInterface *control_interface_;
91 EventDispatcher *dispatcher_;
92 Manager *manager_;
93 GLib *glib_;
94
95 DISALLOW_COPY_AND_ASSIGN(ModemManager);
96};
97
98} // namespace shill
99
100#endif // SHILL_MODEM_MANAGER_