blob: 56063770d7939d93d8fb6fd0c9b2e106cc2059f4 [file] [log] [blame]
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -07001// Copyright (c) 2014 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#include "shill/mobile_operator_info.h"
6
7#include <sstream>
8
9#include "shill/logging.h"
10#include "shill/mobile_operator_info_impl.h"
11
12namespace shill {
13
14using base::FilePath;
15using std::string;
16using std::stringstream;
17using std::vector;
18
19// /////////////////////////////////////////////////////////////////////////////
20// MobileOperatorInfo implementation note:
21// MobileOperatorInfo simply forwards all operations to |impl_|.
22// It also logs the functions/arguments/results at sane log levels. So the
23// implementation need not leave a trace itself.
24
Miao-chen Chou70190b32014-05-14 18:24:30 -070025MobileOperatorInfo::MobileOperatorInfo(EventDispatcher *dispatcher,
26 const string &info_owner)
27 : impl_(new MobileOperatorInfoImpl(dispatcher, info_owner)) {}
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070028
29MobileOperatorInfo::~MobileOperatorInfo() {}
30
Miao-chen Chou70190b32014-05-14 18:24:30 -070031string MobileOperatorInfo::GetLogPrefix(const char *func) const {
32 return impl_->info_owner() + ": " + func;
33}
34
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070035void MobileOperatorInfo::ClearDatabasePaths() {
Miao-chen Chou70190b32014-05-14 18:24:30 -070036 SLOG(Cellular, 3) << GetLogPrefix(__func__);
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070037 impl_->ClearDatabasePaths();
38}
39
40void MobileOperatorInfo::AddDatabasePath(const FilePath &absolute_path) {
Miao-chen Chou70190b32014-05-14 18:24:30 -070041 SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << absolute_path.value()
42 << ")";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070043 impl_->AddDatabasePath(absolute_path);
44}
45
46bool MobileOperatorInfo::Init() {
47 auto result = impl_->Init();
Miao-chen Chou70190b32014-05-14 18:24:30 -070048 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070049 return result;
50}
51
52void MobileOperatorInfo::AddObserver(MobileOperatorInfo::Observer *observer) {
Miao-chen Chou70190b32014-05-14 18:24:30 -070053 SLOG(Cellular, 3) << GetLogPrefix(__func__);
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070054 impl_->AddObserver(observer);
55}
56
57void MobileOperatorInfo::RemoveObserver(
58 MobileOperatorInfo::Observer *observer) {
Miao-chen Chou70190b32014-05-14 18:24:30 -070059 SLOG(Cellular, 3) << GetLogPrefix(__func__);
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070060 impl_->RemoveObserver(observer);
61}
62
63bool MobileOperatorInfo::IsMobileNetworkOperatorKnown() const {
64 auto result = impl_->IsMobileNetworkOperatorKnown();
Miao-chen Chou70190b32014-05-14 18:24:30 -070065 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070066 return result;
67}
68
69bool MobileOperatorInfo::IsMobileVirtualNetworkOperatorKnown() const {
70 auto result = impl_->IsMobileVirtualNetworkOperatorKnown();
Miao-chen Chou70190b32014-05-14 18:24:30 -070071 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070072 return result;
73}
74
75const string &MobileOperatorInfo::uuid() const {
76 const auto &result = impl_->uuid();
Miao-chen Chou70190b32014-05-14 18:24:30 -070077 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070078 return result;
79}
80
81const string &MobileOperatorInfo::operator_name() const {
82 const auto &result = impl_->operator_name();
Miao-chen Chou70190b32014-05-14 18:24:30 -070083 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070084 return result;
85}
86
87const string &MobileOperatorInfo::country() const {
88 const auto &result = impl_->country();
Miao-chen Chou70190b32014-05-14 18:24:30 -070089 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070090 return result;
91}
92
93const string &MobileOperatorInfo::mccmnc() const {
94 const auto &result = impl_->mccmnc();
Miao-chen Chou70190b32014-05-14 18:24:30 -070095 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -070096 return result;
97}
98
99const string &MobileOperatorInfo::sid() const {
100 const auto &result = impl_->sid();
Miao-chen Chou70190b32014-05-14 18:24:30 -0700101 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700102 return result;
103}
104
105const string &MobileOperatorInfo::nid() const {
106 const auto &result = impl_->nid();
Miao-chen Chou70190b32014-05-14 18:24:30 -0700107 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700108 return result;
109}
110
111const vector<string> &MobileOperatorInfo::mccmnc_list() const {
112 const auto &result = impl_->mccmnc_list();
113 if (SLOG_IS_ON(Cellular, 3)) {
114 stringstream pp_result;
115 for (const auto &mccmnc : result) {
116 pp_result << mccmnc << " ";
117 }
Miao-chen Chou70190b32014-05-14 18:24:30 -0700118 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result["
119 << pp_result.str() << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700120 }
121 return result;
122}
123
124const vector<string> &MobileOperatorInfo::sid_list() const {
125 const auto &result = impl_->sid_list();
126 if (SLOG_IS_ON(Cellular, 3)) {
127 stringstream pp_result;
128 for (const auto &sid : result) {
129 pp_result << sid << " ";
130 }
Miao-chen Chou70190b32014-05-14 18:24:30 -0700131 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result["
132 << pp_result.str() << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700133 }
134 return result;
135}
136
137const vector<MobileOperatorInfo::LocalizedName> &
138MobileOperatorInfo::operator_name_list() const {
139 const auto &result = impl_->operator_name_list();
140 if (SLOG_IS_ON(Cellular, 3)) {
141 stringstream pp_result;
142 for (const auto &operator_name : result) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700143 pp_result << "(" << operator_name.name << ", " << operator_name.language
144 << ") ";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700145 }
Miao-chen Chou70190b32014-05-14 18:24:30 -0700146 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result["
147 << pp_result.str() << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700148 }
149 return result;
150}
151
152const ScopedVector<MobileOperatorInfo::MobileAPN> &
153MobileOperatorInfo::apn_list() const {
154 const auto &result = impl_->apn_list();
155 if (SLOG_IS_ON(Cellular, 3)) {
156 stringstream pp_result;
157 for (const auto &mobile_apn : result) {
158 pp_result << "(apn: " << mobile_apn->apn
Miao-chen Chou70190b32014-05-14 18:24:30 -0700159 << ", username: " << mobile_apn->username
160 << ", password: " << mobile_apn->password;
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700161 pp_result << ", operator_name_list: '";
162 for (const auto &operator_name : mobile_apn->operator_name_list) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700163 pp_result << "(" << operator_name.name << ", " << operator_name.language
164 << ") ";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700165 }
166 pp_result << "') ";
167 }
Miao-chen Chou70190b32014-05-14 18:24:30 -0700168 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result["
169 << pp_result.str() << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700170 }
171 return result;
172}
173
Miao-chen Chou70190b32014-05-14 18:24:30 -0700174const vector<MobileOperatorInfo::OnlinePortal> &MobileOperatorInfo::olp_list()
175 const {
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700176 const auto &result = impl_->olp_list();
177 if (SLOG_IS_ON(Cellular, 3)) {
178 stringstream pp_result;
179 for (const auto &olp : result) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700180 pp_result << "(url: " << olp.url << ", method: " << olp.method
181 << ", post_data: " << olp.post_data << ") ";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700182 }
Miao-chen Chou70190b32014-05-14 18:24:30 -0700183 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result["
184 << pp_result.str() << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700185 }
186 return result;
187}
188
189const string &MobileOperatorInfo::activation_code() const {
190 const auto &result = impl_->activation_code();
Miao-chen Chou70190b32014-05-14 18:24:30 -0700191 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700192 return result;
193}
194
195bool MobileOperatorInfo::requires_roaming() const {
196 auto result = impl_->requires_roaming();
Miao-chen Chou70190b32014-05-14 18:24:30 -0700197 SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700198 return result;
199}
200
201void MobileOperatorInfo::UpdateIMSI(const string &imsi) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700202 SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << imsi << ")";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700203 impl_->UpdateIMSI(imsi);
204}
205
206void MobileOperatorInfo::UpdateICCID(const string &iccid) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700207 SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << iccid << ")";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700208 impl_->UpdateICCID(iccid);
209}
210
211void MobileOperatorInfo::UpdateMCCMNC(const string &mccmnc) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700212 SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << mccmnc << ")";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700213 impl_->UpdateMCCMNC(mccmnc);
214}
215
216void MobileOperatorInfo::UpdateSID(const string &sid) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700217 SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << sid << ")";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700218 impl_->UpdateSID(sid);
219}
220
221void MobileOperatorInfo::UpdateNID(const string &nid) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700222 SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << nid << ")";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700223 impl_->UpdateNID(nid);
224}
225
226void MobileOperatorInfo::UpdateOperatorName(const string &operator_name) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700227 SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << operator_name << ")";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700228 impl_->UpdateOperatorName(operator_name);
229}
230
231void MobileOperatorInfo::UpdateOnlinePortal(const string &url,
232 const string &method,
233 const string &post_data) {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700234 SLOG(Cellular, 3) << GetLogPrefix(__func__)
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700235 << "(" << url
236 << ", " << method
Miao-chen Chou70190b32014-05-14 18:24:30 -0700237 << ", " << post_data << ")";
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700238 impl_->UpdateOnlinePortal(url, method, post_data);
239}
240
241void MobileOperatorInfo::Reset() {
Miao-chen Chou70190b32014-05-14 18:24:30 -0700242 SLOG(Cellular, 3) << GetLogPrefix(__func__);
Prathmesh Prabhu28b4a3b2014-03-28 11:52:09 -0700243 impl_->Reset();
244}
245
246} // namespace shill