blob: 0f2691029fc2b7974ad9ed9ba7b54113d28d79a7 [file] [log] [blame]
Darin Petkov41c0e0a2012-01-09 16:38:53 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov887f2982011-07-14 16:10:17 -07002// 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>
Hristo Stefanoved2c28c2011-11-29 15:37:30 -08009#include <string>
Darin Petkov5c97ac52011-07-19 16:30:49 -070010#include <tr1/memory>
11
Darin Petkov887f2982011-07-14 16:10:17 -070012#include <base/basictypes.h>
Darin Petkovc90fe522011-07-15 13:59:47 -070013#include <base/memory/scoped_ptr.h>
Darin Petkov887f2982011-07-14 16:10:17 -070014#include <gtest/gtest_prod.h> // for FRIEND_TEST
15
16#include "shill/glib.h"
17
Darin Petkov137884a2011-10-26 18:52:47 +020018struct mobile_provider_db;
19
Darin Petkov887f2982011-07-14 16:10:17 -070020namespace shill {
21
22class ControlInterface;
23class EventDispatcher;
24class Manager;
Darin Petkov5c97ac52011-07-19 16:30:49 -070025class Modem;
Darin Petkovc90fe522011-07-15 13:59:47 -070026class ModemManagerProxyInterface;
Darin Petkovab565bb2011-10-06 02:55:51 -070027class ProxyFactory;
Darin Petkov887f2982011-07-14 16:10:17 -070028
Darin Petkov5c97ac52011-07-19 16:30:49 -070029// Handles a modem manager service and creates and destroys modem instances.
Darin Petkov887f2982011-07-14 16:10:17 -070030class 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 Petkov137884a2011-10-26 18:52:47 +020037 GLib *glib,
38 mobile_provider_db *provider_db);
Darin Petkov887f2982011-07-14 16:10:17 -070039 ~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 Petkov5c97ac52011-07-19 16:30:49 -070045 // associated modems.
Darin Petkov887f2982011-07-14 16:10:17 -070046 void Stop();
47
Darin Petkov5c97ac52011-07-19 16:30:49 -070048 // 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 Petkov41c0e0a2012-01-09 16:38:53 +010054 void OnDeviceInfoAvailable(const std::string &link_name);
55
Darin Petkov887f2982011-07-14 16:10:17 -070056 private:
57 friend class ModemManagerTest;
58 FRIEND_TEST(ModemInfoTest, RegisterModemManager);
Darin Petkov5c97ac52011-07-19 16:30:49 -070059 FRIEND_TEST(ModemManagerTest, AddRemoveModem);
Darin Petkov887f2982011-07-14 16:10:17 -070060 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 Petkov5c97ac52011-07-19 16:30:49 -070067 typedef std::map<std::string, std::tr1::shared_ptr<Modem> > Modems;
68
Darin Petkov887f2982011-07-14 16:10:17 -070069 // 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 Petkovab565bb2011-10-06 02:55:51 -070084 // Store cached copies of singletons for speed/ease of testing.
85 ProxyFactory *proxy_factory_;
86
Darin Petkov887f2982011-07-14 16:10:17 -070087 const std::string service_;
88 const std::string path_;
89 guint watcher_id_;
90
Darin Petkovc90fe522011-07-15 13:59:47 -070091 std::string owner_; // DBus service owner.
92 scoped_ptr<ModemManagerProxyInterface> proxy_; // DBus service proxy.
Darin Petkov887f2982011-07-14 16:10:17 -070093
Darin Petkov5c97ac52011-07-19 16:30:49 -070094 Modems modems_; // Maps a modem |path| to a modem instance.
95
Darin Petkov887f2982011-07-14 16:10:17 -070096 ControlInterface *control_interface_;
97 EventDispatcher *dispatcher_;
98 Manager *manager_;
99 GLib *glib_;
Darin Petkov137884a2011-10-26 18:52:47 +0200100 mobile_provider_db *provider_db_;
Darin Petkov887f2982011-07-14 16:10:17 -0700101
102 DISALLOW_COPY_AND_ASSIGN(ModemManager);
103};
104
105} // namespace shill
106
107#endif // SHILL_MODEM_MANAGER_