blob: 71af22c8e8b635abd0e92411bf0c239b7bd4d9f6 [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;
23
Darin Petkove0a312e2011-07-20 13:45:28 -070024// Handles an instance of ModemManager.Modem and an instance of a Cellular
25// device.
Darin Petkovc5f56562011-08-06 16:40:05 -070026class Modem : public DBusPropertiesProxyListener {
Darin Petkov5c97ac52011-07-19 16:30:49 -070027 public:
Darin Petkove0a312e2011-07-20 13:45:28 -070028 // |owner| is the ModemManager DBus service owner (e.g., ":1.17"). |path| is
29 // the ModemManager.Modem DBus object path (e.g.,
30 // "/org/chromium/ModemManager/Gobi/0").
Darin Petkov5c97ac52011-07-19 16:30:49 -070031 Modem(const std::string &owner,
32 const std::string &path,
33 ControlInterface *control_interface,
34 EventDispatcher *dispatcher,
35 Manager *manager);
36 ~Modem();
37
Darin Petkovc5f56562011-08-06 16:40:05 -070038 // Asynchronously initializes support for the modem, possibly constructing a
39 // Cellular device.
Darin Petkove0a312e2011-07-20 13:45:28 -070040 void Init();
41
Darin Petkov5c97ac52011-07-19 16:30:49 -070042 private:
Darin Petkove0a312e2011-07-20 13:45:28 -070043 friend class ModemManagerTest;
44 friend class ModemTest;
Darin Petkova7b89492011-07-27 12:48:17 -070045 FRIEND_TEST(ModemManagerTest, Connect);
46 FRIEND_TEST(ModemManagerTest, AddRemoveModem);
Darin Petkove0a312e2011-07-20 13:45:28 -070047 FRIEND_TEST(ModemTest, CreateCellularDevice);
48 FRIEND_TEST(ModemTest, Init);
49
50 static const char kPropertyLinkName[];
51 static const char kPropertyIPMethod[];
Darin Petkovbac96002011-08-09 13:22:00 -070052 static const char kPropertyState[];
Darin Petkove0a312e2011-07-20 13:45:28 -070053 static const char kPropertyType[];
54 static const char kPropertyUnlockRequired[];
55 static const char kPropertyUnlockRetries[];
56
Darin Petkova7b89492011-07-27 12:48:17 -070057 void InitTask();
58
Darin Petkov67d8ecf2011-07-26 16:03:30 -070059 // Creates and registers a Cellular device in |device_| based on
60 // ModemManager.Modem's |properties|. The device may not be created if the
61 // properties are invalid.
Darin Petkove0a312e2011-07-20 13:45:28 -070062 void CreateCellularDevice(const DBusPropertiesMap &properties);
63
Darin Petkovc5f56562011-08-06 16:40:05 -070064 // Signal callbacks inherited from DBusPropertiesProxyListener.
65 virtual void OnDBusPropertiesChanged(
66 const std::string &interface,
67 const DBusPropertiesMap &changed_properties,
68 const std::vector<std::string> &invalidated_properties);
69 virtual void OnModemManagerPropertiesChanged(
70 const std::string &interface,
71 const DBusPropertiesMap &properties);
72
Darin Petkove0a312e2011-07-20 13:45:28 -070073 // A proxy to the org.freedesktop.DBus.Properties interface used to obtain
74 // ModemManager.Modem properties and watch for property changes.
Darin Petkov5c97ac52011-07-19 16:30:49 -070075 scoped_ptr<DBusPropertiesProxyInterface> dbus_properties_proxy_;
76
Darin Petkove0a312e2011-07-20 13:45:28 -070077 const std::string owner_;
78 const std::string path_;
79
80 CellularRefPtr device_;
81
Darin Petkov67d8ecf2011-07-26 16:03:30 -070082 ScopedRunnableMethodFactory<Modem> task_factory_;
Darin Petkov5c97ac52011-07-19 16:30:49 -070083 ControlInterface *control_interface_;
84 EventDispatcher *dispatcher_;
85 Manager *manager_;
86
87 DISALLOW_COPY_AND_ASSIGN(Modem);
88};
89
90} // namespace shill
91
92#endif // SHILL_MODEM_