blob: 17c2f32c8fdd4461bc3d34368ef03f58584ba1dd [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#include "shill/modem_info.h"
6
Darin Petkov137884a2011-10-26 18:52:47 +02007#include <base/logging.h>
Darin Petkov887f2982011-07-14 16:10:17 -07008#include <mm/mm-modem.h>
Darin Petkov137884a2011-10-26 18:52:47 +02009#include <mobile_provider.h>
Darin Petkov887f2982011-07-14 16:10:17 -070010
11#include "shill/modem_manager.h"
12
13using std::string;
14
15namespace shill {
16
17const char ModemInfo::kCromoService[] = "org.chromium.ModemManager";
18const char ModemInfo::kCromoPath[] = "/org/chromium/ModemManager";
David Rochberg7cb06f62012-03-05 11:23:44 -050019
20// TODO(rochberg): Fix modemmanager-next-interfaces ebuild to include
21// these so that we can simply include ModemManager.h and use these
22// defines
23#define MM_DBUS_PATH "/org/freedesktop/ModemManager1"
24#define MM_DBUS_SERVICE "org.freedesktop.ModemManager1"
25
Darin Petkov137884a2011-10-26 18:52:47 +020026const char ModemInfo::kMobileProviderDBPath[] =
27 "/usr/share/mobile-broadband-provider-info/serviceproviders.bfd";
Darin Petkov887f2982011-07-14 16:10:17 -070028
29ModemInfo::ModemInfo(ControlInterface *control_interface,
30 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080031 Metrics *metrics,
Darin Petkov887f2982011-07-14 16:10:17 -070032 Manager *manager,
33 GLib *glib)
34 : control_interface_(control_interface),
Darin Petkov67d8ecf2011-07-26 16:03:30 -070035 dispatcher_(dispatcher),
Thieu Le3426c8f2012-01-11 17:35:11 -080036 metrics_(metrics),
Darin Petkov887f2982011-07-14 16:10:17 -070037 manager_(manager),
Darin Petkov137884a2011-10-26 18:52:47 +020038 glib_(glib),
39 provider_db_path_(kMobileProviderDBPath),
40 provider_db_(NULL) {}
Darin Petkov887f2982011-07-14 16:10:17 -070041
42ModemInfo::~ModemInfo() {
43 Stop();
44}
45
46void ModemInfo::Start() {
Darin Petkov137884a2011-10-26 18:52:47 +020047 // TODO(petkov): Consider initializing the mobile provider database lazily
48 // only if a GSM modem needs to be registered.
49 provider_db_ = mobile_provider_open_db(provider_db_path_.c_str());
50 PLOG_IF(WARNING, !provider_db_)
51 << "Unable to load mobile provider database: ";
David Rochberg7cb06f62012-03-05 11:23:44 -050052 RegisterModemManager<ModemManagerClassic>(MM_MODEMMANAGER_SERVICE,
53 MM_MODEMMANAGER_PATH);
54 RegisterModemManager<ModemManagerClassic>(kCromoService, kCromoPath);
55 RegisterModemManager<ModemManager1>(MM_DBUS_SERVICE, MM_DBUS_PATH);
Darin Petkov887f2982011-07-14 16:10:17 -070056}
57
58void ModemInfo::Stop() {
Darin Petkov137884a2011-10-26 18:52:47 +020059 mobile_provider_close_db(provider_db_);
60 provider_db_ = NULL;
Darin Petkov887f2982011-07-14 16:10:17 -070061 modem_managers_.reset();
62}
63
Darin Petkov41c0e0a2012-01-09 16:38:53 +010064void ModemInfo::OnDeviceInfoAvailable(const string &link_name) {
65 for (ModemManagers::iterator it = modem_managers_.begin();
66 it != modem_managers_.end(); ++it) {
67 (*it)->OnDeviceInfoAvailable(link_name);
68 }
69}
70
David Rochberg7cb06f62012-03-05 11:23:44 -050071template <class mm>
Darin Petkov887f2982011-07-14 16:10:17 -070072void ModemInfo::RegisterModemManager(const string &service,
73 const string &path) {
David Rochberg7cb06f62012-03-05 11:23:44 -050074 ModemManager *manager = new mm(service,
75 path,
76 control_interface_,
77 dispatcher_,
78 metrics_,
79 manager_,
80 glib_,
81 provider_db_);
Darin Petkov887f2982011-07-14 16:10:17 -070082 modem_managers_.push_back(manager); // Passes ownership.
83 manager->Start();
84}
Darin Petkov887f2982011-07-14 16:10:17 -070085} // namespace shill