1 //
2 // Copyright (C) 2012 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include "shill/cellular/modem_info.h"
18
19 #include <base/files/file_path.h>
20 #if defined(__ANDROID__)
21 #include <dbus/service_constants.h>
22 #else
23 #include <chromeos/dbus/service_constants.h>
24 #endif // __ANDROID__
25
26 #include "shill/cellular/modem_manager.h"
27 #include "shill/logging.h"
28 #include "shill/manager.h"
29 #include "shill/pending_activation_store.h"
30
31 using base::FilePath;
32 using std::string;
33
34 namespace shill {
35
ModemInfo(ControlInterface * control_interface,EventDispatcher * dispatcher,Metrics * metrics,Manager * manager)36 ModemInfo::ModemInfo(ControlInterface* control_interface,
37 EventDispatcher* dispatcher,
38 Metrics* metrics,
39 Manager* manager)
40 : control_interface_(control_interface),
41 dispatcher_(dispatcher),
42 metrics_(metrics),
43 manager_(manager) {}
44
~ModemInfo()45 ModemInfo::~ModemInfo() {
46 Stop();
47 }
48
Start()49 void ModemInfo::Start() {
50 pending_activation_store_.reset(new PendingActivationStore());
51 pending_activation_store_->InitStorage(manager_->storage_path());
52
53 RegisterModemManager(new ModemManagerClassic(control_interface_,
54 cromo::kCromoServiceName,
55 cromo::kCromoServicePath,
56 this));
57 RegisterModemManager(
58 new ModemManager1(control_interface_,
59 modemmanager::kModemManager1ServiceName,
60 modemmanager::kModemManager1ServicePath,
61 this));
62 }
63
Stop()64 void ModemInfo::Stop() {
65 pending_activation_store_.reset();
66 modem_managers_.clear();
67 }
68
OnDeviceInfoAvailable(const string & link_name)69 void ModemInfo::OnDeviceInfoAvailable(const string& link_name) {
70 for (const auto& manager : modem_managers_) {
71 manager->OnDeviceInfoAvailable(link_name);
72 }
73 }
74
set_pending_activation_store(PendingActivationStore * pending_activation_store)75 void ModemInfo::set_pending_activation_store(
76 PendingActivationStore* pending_activation_store) {
77 pending_activation_store_.reset(pending_activation_store);
78 }
79
RegisterModemManager(ModemManager * manager)80 void ModemInfo::RegisterModemManager(ModemManager* manager) {
81 modem_managers_.push_back(manager); // Passes ownership.
82 manager->Start();
83 }
84
85 } // namespace shill
86