blob: 037bba9d8a3a61ed22bd8c23bf2728fc09f2bbf3 [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 Petkov887f2982011-07-14 16:10:17 -070024
Darin Petkov5c97ac52011-07-19 16:30:49 -070025// Handles a modem manager service and creates and destroys modem instances.
Darin Petkov887f2982011-07-14 16:10:17 -070026class ModemManager {
27 public:
28 ModemManager(const std::string &service,
29 const std::string &path,
30 ControlInterface *control_interface,
31 EventDispatcher *dispatcher,
32 Manager *manager,
33 GLib *glib);
34 ~ModemManager();
35
36 // Starts watching for and handling the DBus modem manager service.
37 void Start();
38
39 // Stops watching for the DBus modem manager service and destroys any
Darin Petkov5c97ac52011-07-19 16:30:49 -070040 // associated modems.
Darin Petkov887f2982011-07-14 16:10:17 -070041 void Stop();
42
Darin Petkov5c97ac52011-07-19 16:30:49 -070043 // Adds a modem on |path|.
44 void AddModem(const std::string &path);
45
46 // Removes a modem on |path|.
47 void RemoveModem(const std::string &path);
48
Darin Petkov887f2982011-07-14 16:10:17 -070049 private:
50 friend class ModemManagerTest;
51 FRIEND_TEST(ModemInfoTest, RegisterModemManager);
Darin Petkov5c97ac52011-07-19 16:30:49 -070052 FRIEND_TEST(ModemManagerTest, AddRemoveModem);
Darin Petkov887f2982011-07-14 16:10:17 -070053 FRIEND_TEST(ModemManagerTest, Connect);
54 FRIEND_TEST(ModemManagerTest, Disconnect);
55 FRIEND_TEST(ModemManagerTest, OnAppear);
56 FRIEND_TEST(ModemManagerTest, OnVanish);
57 FRIEND_TEST(ModemManagerTest, Start);
58 FRIEND_TEST(ModemManagerTest, Stop);
59
Darin Petkov5c97ac52011-07-19 16:30:49 -070060 typedef std::map<std::string, std::tr1::shared_ptr<Modem> > Modems;
61
Darin Petkov887f2982011-07-14 16:10:17 -070062 // Connects a newly appeared modem manager service.
63 void Connect(const std::string &owner);
64
65 // Disconnects a vanished modem manager service.
66 void Disconnect();
67
68 // DBus service watcher callbacks.
69 static void OnAppear(GDBusConnection *connection,
70 const gchar *name,
71 const gchar *name_owner,
72 gpointer user_data);
73 static void OnVanish(GDBusConnection *connection,
74 const gchar *name,
75 gpointer user_data);
76
77 const std::string service_;
78 const std::string path_;
79 guint watcher_id_;
80
Darin Petkovc90fe522011-07-15 13:59:47 -070081 std::string owner_; // DBus service owner.
82 scoped_ptr<ModemManagerProxyInterface> proxy_; // DBus service proxy.
Darin Petkov887f2982011-07-14 16:10:17 -070083
Darin Petkov5c97ac52011-07-19 16:30:49 -070084 Modems modems_; // Maps a modem |path| to a modem instance.
85
Darin Petkov887f2982011-07-14 16:10:17 -070086 ControlInterface *control_interface_;
87 EventDispatcher *dispatcher_;
88 Manager *manager_;
89 GLib *glib_;
90
91 DISALLOW_COPY_AND_ASSIGN(ModemManager);
92};
93
94} // namespace shill
95
96#endif // SHILL_MODEM_MANAGER_