blob: dac7409dc0d24d44ee090407cdeddda8aaed3198 [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>
9
10#include <base/basictypes.h>
11#include <base/memory/scoped_ptr.h>
Darin Petkov67d8ecf2011-07-26 16:03:30 -070012#include <base/task.h>
Darin Petkove0a312e2011-07-20 13:45:28 -070013#include <gtest/gtest_prod.h> // for FRIEND_TEST
14
15#include "shill/dbus_properties_proxy_interface.h"
16#include "shill/refptr_types.h"
Darin Petkov5c97ac52011-07-19 16:30:49 -070017
18namespace shill {
19
20class ControlInterface;
Darin Petkov5c97ac52011-07-19 16:30:49 -070021class EventDispatcher;
22class Manager;
Darin Petkovab565bb2011-10-06 02:55:51 -070023class ProxyFactory;
Darin Petkov5c97ac52011-07-19 16:30:49 -070024
Darin Petkove0a312e2011-07-20 13:45:28 -070025// Handles an instance of ModemManager.Modem and an instance of a Cellular
26// device.
Darin Petkov580c7af2011-10-24 12:32:50 +020027class Modem : public DBusPropertiesProxyDelegate {
Darin Petkov5c97ac52011-07-19 16:30:49 -070028 public:
Darin Petkove0a312e2011-07-20 13:45:28 -070029 // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is
30 // the ModemManager.Modem DBus object path (e.g.,
31 // "/org/chromium/ModemManager/Gobi/0").
Darin Petkov5c97ac52011-07-19 16:30:49 -070032 Modem(const std::string &owner,
33 const std::string &path,
34 ControlInterface *control_interface,
35 EventDispatcher *dispatcher,
36 Manager *manager);
37 ~Modem();
38
Darin Petkovc5f56562011-08-06 16:40:05 -070039 // Asynchronously initializes support for the modem, possibly constructing a
40 // Cellular device.
Darin Petkove0a312e2011-07-20 13:45:28 -070041 void Init();
42
Darin Petkov5c97ac52011-07-19 16:30:49 -070043 private:
Darin Petkove0a312e2011-07-20 13:45:28 -070044 friend class ModemManagerTest;
45 friend class ModemTest;
Darin Petkova7b89492011-07-27 12:48:17 -070046 FRIEND_TEST(ModemManagerTest, Connect);
47 FRIEND_TEST(ModemManagerTest, AddRemoveModem);
Darin Petkove0a312e2011-07-20 13:45:28 -070048 FRIEND_TEST(ModemTest, CreateCellularDevice);
49 FRIEND_TEST(ModemTest, Init);
50
Darin Petkov48a511a2011-09-15 10:33:37 -070051 static const char kPropertyAccessTechnology[];
Darin Petkove0a312e2011-07-20 13:45:28 -070052 static const char kPropertyLinkName[];
53 static const char kPropertyIPMethod[];
Darin Petkovbac96002011-08-09 13:22:00 -070054 static const char kPropertyState[];
Darin Petkove0a312e2011-07-20 13:45:28 -070055 static const char kPropertyType[];
56 static const char kPropertyUnlockRequired[];
57 static const char kPropertyUnlockRetries[];
58
Darin Petkova7b89492011-07-27 12:48:17 -070059 void InitTask();
60
Darin Petkov67d8ecf2011-07-26 16:03:30 -070061 // Creates and registers a Cellular device in |device_| based on
62 // ModemManager.Modem's |properties|. The device may not be created if the
63 // properties are invalid.
Darin Petkove0a312e2011-07-20 13:45:28 -070064 void CreateCellularDevice(const DBusPropertiesMap &properties);
65
Darin Petkov580c7af2011-10-24 12:32:50 +020066 // Signal callbacks inherited from DBusPropertiesProxyDelegate.
Darin Petkovc5f56562011-08-06 16:40:05 -070067 virtual void OnDBusPropertiesChanged(
68 const std::string &interface,
69 const DBusPropertiesMap &changed_properties,
70 const std::vector<std::string> &invalidated_properties);
71 virtual void OnModemManagerPropertiesChanged(
72 const std::string &interface,
73 const DBusPropertiesMap &properties);
74
Darin Petkovab565bb2011-10-06 02:55:51 -070075 // Store cached copies of singletons for speed/ease of testing.
76 ProxyFactory *proxy_factory_;
77
Darin Petkove0a312e2011-07-20 13:45:28 -070078 // A proxy to the org.freedesktop.DBus.Properties interface used to obtain
79 // ModemManager.Modem properties and watch for property changes.
Darin Petkov5c97ac52011-07-19 16:30:49 -070080 scoped_ptr<DBusPropertiesProxyInterface> dbus_properties_proxy_;
81
Darin Petkove0a312e2011-07-20 13:45:28 -070082 const std::string owner_;
83 const std::string path_;
84
85 CellularRefPtr device_;
86
Darin Petkov67d8ecf2011-07-26 16:03:30 -070087 ScopedRunnableMethodFactory<Modem> task_factory_;
Darin Petkov5c97ac52011-07-19 16:30:49 -070088 ControlInterface *control_interface_;
89 EventDispatcher *dispatcher_;
90 Manager *manager_;
91
92 DISALLOW_COPY_AND_ASSIGN(Modem);
93};
94
95} // namespace shill
96
97#endif // SHILL_MODEM_