blob: 725b41b20edf961aaa467468bb3afece75bed0d4 [file] [log] [blame]
Darin Petkov5c97ac52011-07-19 16:30:49 -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_
6#define SHILL_MODEM_
7
8#include <string>
Hristo Stefanoved2c28c2011-11-29 15:37:30 -08009#include <vector>
Darin Petkov5c97ac52011-07-19 16:30:49 -070010
11#include <base/basictypes.h>
12#include <base/memory/scoped_ptr.h>
Darin Petkov67d8ecf2011-07-26 16:03:30 -070013#include <base/task.h>
Darin Petkove0a312e2011-07-20 13:45:28 -070014#include <gtest/gtest_prod.h> // for FRIEND_TEST
15
16#include "shill/dbus_properties_proxy_interface.h"
17#include "shill/refptr_types.h"
Darin Petkov5c97ac52011-07-19 16:30:49 -070018
Darin Petkov137884a2011-10-26 18:52:47 +020019struct mobile_provider_db;
20
Darin Petkov5c97ac52011-07-19 16:30:49 -070021namespace shill {
22
23class ControlInterface;
Darin Petkov5c97ac52011-07-19 16:30:49 -070024class EventDispatcher;
25class Manager;
Darin Petkovab565bb2011-10-06 02:55:51 -070026class ProxyFactory;
Darin Petkov5c97ac52011-07-19 16:30:49 -070027
Darin Petkove0a312e2011-07-20 13:45:28 -070028// Handles an instance of ModemManager.Modem and an instance of a Cellular
29// device.
Darin Petkov580c7af2011-10-24 12:32:50 +020030class Modem : public DBusPropertiesProxyDelegate {
Darin Petkov5c97ac52011-07-19 16:30:49 -070031 public:
Darin Petkove0a312e2011-07-20 13:45:28 -070032 // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is
33 // the ModemManager.Modem DBus object path (e.g.,
34 // "/org/chromium/ModemManager/Gobi/0").
Darin Petkov5c97ac52011-07-19 16:30:49 -070035 Modem(const std::string &owner,
36 const std::string &path,
37 ControlInterface *control_interface,
38 EventDispatcher *dispatcher,
Darin Petkov137884a2011-10-26 18:52:47 +020039 Manager *manager,
40 mobile_provider_db *provider_db);
Darin Petkov5c97ac52011-07-19 16:30:49 -070041 ~Modem();
42
Darin Petkovc5f56562011-08-06 16:40:05 -070043 // Asynchronously initializes support for the modem, possibly constructing a
44 // Cellular device.
Darin Petkove0a312e2011-07-20 13:45:28 -070045 void Init();
46
Darin Petkov5c97ac52011-07-19 16:30:49 -070047 private:
Darin Petkove0a312e2011-07-20 13:45:28 -070048 friend class ModemManagerTest;
49 friend class ModemTest;
Darin Petkova7b89492011-07-27 12:48:17 -070050 FRIEND_TEST(ModemManagerTest, Connect);
51 FRIEND_TEST(ModemManagerTest, AddRemoveModem);
Darin Petkove0a312e2011-07-20 13:45:28 -070052 FRIEND_TEST(ModemTest, CreateCellularDevice);
53 FRIEND_TEST(ModemTest, Init);
54
55 static const char kPropertyLinkName[];
56 static const char kPropertyIPMethod[];
Darin Petkovbac96002011-08-09 13:22:00 -070057 static const char kPropertyState[];
Darin Petkove0a312e2011-07-20 13:45:28 -070058 static const char kPropertyType[];
Darin Petkove0a312e2011-07-20 13:45:28 -070059
Darin Petkova7b89492011-07-27 12:48:17 -070060 void InitTask();
61
Darin Petkov67d8ecf2011-07-26 16:03:30 -070062 // Creates and registers a Cellular device in |device_| based on
63 // ModemManager.Modem's |properties|. The device may not be created if the
64 // properties are invalid.
Darin Petkove0a312e2011-07-20 13:45:28 -070065 void CreateCellularDevice(const DBusPropertiesMap &properties);
66
Darin Petkov580c7af2011-10-24 12:32:50 +020067 // Signal callbacks inherited from DBusPropertiesProxyDelegate.
Darin Petkovc5f56562011-08-06 16:40:05 -070068 virtual void OnDBusPropertiesChanged(
69 const std::string &interface,
70 const DBusPropertiesMap &changed_properties,
71 const std::vector<std::string> &invalidated_properties);
72 virtual void OnModemManagerPropertiesChanged(
73 const std::string &interface,
74 const DBusPropertiesMap &properties);
75
Darin Petkovab565bb2011-10-06 02:55:51 -070076 // Store cached copies of singletons for speed/ease of testing.
77 ProxyFactory *proxy_factory_;
78
Darin Petkove0a312e2011-07-20 13:45:28 -070079 // A proxy to the org.freedesktop.DBus.Properties interface used to obtain
80 // ModemManager.Modem properties and watch for property changes.
Darin Petkov5c97ac52011-07-19 16:30:49 -070081 scoped_ptr<DBusPropertiesProxyInterface> dbus_properties_proxy_;
82
Darin Petkove0a312e2011-07-20 13:45:28 -070083 const std::string owner_;
84 const std::string path_;
85
86 CellularRefPtr device_;
87
Darin Petkov67d8ecf2011-07-26 16:03:30 -070088 ScopedRunnableMethodFactory<Modem> task_factory_;
Darin Petkov5c97ac52011-07-19 16:30:49 -070089 ControlInterface *control_interface_;
90 EventDispatcher *dispatcher_;
91 Manager *manager_;
Darin Petkov137884a2011-10-26 18:52:47 +020092 mobile_provider_db *provider_db_;
Darin Petkov5c97ac52011-07-19 16:30:49 -070093
94 DISALLOW_COPY_AND_ASSIGN(Modem);
95};
96
97} // namespace shill
98
99#endif // SHILL_MODEM_