Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1 | // 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 | |
| 12 | namespace shill { |
| 13 | |
| 14 | using base::FilePath; |
| 15 | using std::string; |
| 16 | using std::stringstream; |
| 17 | using 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 Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 25 | MobileOperatorInfo::MobileOperatorInfo(EventDispatcher *dispatcher, |
| 26 | const string &info_owner) |
| 27 | : impl_(new MobileOperatorInfoImpl(dispatcher, info_owner)) {} |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 28 | |
| 29 | MobileOperatorInfo::~MobileOperatorInfo() {} |
| 30 | |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 31 | string MobileOperatorInfo::GetLogPrefix(const char *func) const { |
| 32 | return impl_->info_owner() + ": " + func; |
| 33 | } |
| 34 | |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 35 | void MobileOperatorInfo::ClearDatabasePaths() { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 36 | SLOG(Cellular, 3) << GetLogPrefix(__func__); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 37 | impl_->ClearDatabasePaths(); |
| 38 | } |
| 39 | |
| 40 | void MobileOperatorInfo::AddDatabasePath(const FilePath &absolute_path) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 41 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << absolute_path.value() |
| 42 | << ")"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 43 | impl_->AddDatabasePath(absolute_path); |
| 44 | } |
| 45 | |
| 46 | bool MobileOperatorInfo::Init() { |
| 47 | auto result = impl_->Init(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 48 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 49 | return result; |
| 50 | } |
| 51 | |
| 52 | void MobileOperatorInfo::AddObserver(MobileOperatorInfo::Observer *observer) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 53 | SLOG(Cellular, 3) << GetLogPrefix(__func__); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 54 | impl_->AddObserver(observer); |
| 55 | } |
| 56 | |
| 57 | void MobileOperatorInfo::RemoveObserver( |
| 58 | MobileOperatorInfo::Observer *observer) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 59 | SLOG(Cellular, 3) << GetLogPrefix(__func__); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 60 | impl_->RemoveObserver(observer); |
| 61 | } |
| 62 | |
| 63 | bool MobileOperatorInfo::IsMobileNetworkOperatorKnown() const { |
| 64 | auto result = impl_->IsMobileNetworkOperatorKnown(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 65 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 66 | return result; |
| 67 | } |
| 68 | |
| 69 | bool MobileOperatorInfo::IsMobileVirtualNetworkOperatorKnown() const { |
| 70 | auto result = impl_->IsMobileVirtualNetworkOperatorKnown(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 71 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 72 | return result; |
| 73 | } |
| 74 | |
| 75 | const string &MobileOperatorInfo::uuid() const { |
| 76 | const auto &result = impl_->uuid(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 77 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 78 | return result; |
| 79 | } |
| 80 | |
| 81 | const string &MobileOperatorInfo::operator_name() const { |
| 82 | const auto &result = impl_->operator_name(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 83 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 84 | return result; |
| 85 | } |
| 86 | |
| 87 | const string &MobileOperatorInfo::country() const { |
| 88 | const auto &result = impl_->country(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 89 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 90 | return result; |
| 91 | } |
| 92 | |
| 93 | const string &MobileOperatorInfo::mccmnc() const { |
| 94 | const auto &result = impl_->mccmnc(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 95 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 96 | return result; |
| 97 | } |
| 98 | |
| 99 | const string &MobileOperatorInfo::sid() const { |
| 100 | const auto &result = impl_->sid(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 101 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 102 | return result; |
| 103 | } |
| 104 | |
| 105 | const string &MobileOperatorInfo::nid() const { |
| 106 | const auto &result = impl_->nid(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 107 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 108 | return result; |
| 109 | } |
| 110 | |
| 111 | const 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 Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 118 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" |
| 119 | << pp_result.str() << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 120 | } |
| 121 | return result; |
| 122 | } |
| 123 | |
| 124 | const 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 Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 131 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" |
| 132 | << pp_result.str() << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 133 | } |
| 134 | return result; |
| 135 | } |
| 136 | |
| 137 | const vector<MobileOperatorInfo::LocalizedName> & |
| 138 | MobileOperatorInfo::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 Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 143 | pp_result << "(" << operator_name.name << ", " << operator_name.language |
| 144 | << ") "; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 145 | } |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 146 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" |
| 147 | << pp_result.str() << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 148 | } |
| 149 | return result; |
| 150 | } |
| 151 | |
| 152 | const ScopedVector<MobileOperatorInfo::MobileAPN> & |
| 153 | MobileOperatorInfo::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 Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 159 | << ", username: " << mobile_apn->username |
| 160 | << ", password: " << mobile_apn->password; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 161 | pp_result << ", operator_name_list: '"; |
| 162 | for (const auto &operator_name : mobile_apn->operator_name_list) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 163 | pp_result << "(" << operator_name.name << ", " << operator_name.language |
| 164 | << ") "; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 165 | } |
| 166 | pp_result << "') "; |
| 167 | } |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 168 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" |
| 169 | << pp_result.str() << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 170 | } |
| 171 | return result; |
| 172 | } |
| 173 | |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 174 | const vector<MobileOperatorInfo::OnlinePortal> &MobileOperatorInfo::olp_list() |
| 175 | const { |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 176 | 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 Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 180 | pp_result << "(url: " << olp.url << ", method: " << olp.method |
| 181 | << ", post_data: " << olp.post_data << ") "; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 182 | } |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 183 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" |
| 184 | << pp_result.str() << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 185 | } |
| 186 | return result; |
| 187 | } |
| 188 | |
| 189 | const string &MobileOperatorInfo::activation_code() const { |
| 190 | const auto &result = impl_->activation_code(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 191 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 192 | return result; |
| 193 | } |
| 194 | |
| 195 | bool MobileOperatorInfo::requires_roaming() const { |
| 196 | auto result = impl_->requires_roaming(); |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 197 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 198 | return result; |
| 199 | } |
| 200 | |
| 201 | void MobileOperatorInfo::UpdateIMSI(const string &imsi) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 202 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << imsi << ")"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 203 | impl_->UpdateIMSI(imsi); |
| 204 | } |
| 205 | |
| 206 | void MobileOperatorInfo::UpdateICCID(const string &iccid) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 207 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << iccid << ")"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 208 | impl_->UpdateICCID(iccid); |
| 209 | } |
| 210 | |
| 211 | void MobileOperatorInfo::UpdateMCCMNC(const string &mccmnc) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 212 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << mccmnc << ")"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 213 | impl_->UpdateMCCMNC(mccmnc); |
| 214 | } |
| 215 | |
| 216 | void MobileOperatorInfo::UpdateSID(const string &sid) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 217 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << sid << ")"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 218 | impl_->UpdateSID(sid); |
| 219 | } |
| 220 | |
| 221 | void MobileOperatorInfo::UpdateNID(const string &nid) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 222 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << nid << ")"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 223 | impl_->UpdateNID(nid); |
| 224 | } |
| 225 | |
| 226 | void MobileOperatorInfo::UpdateOperatorName(const string &operator_name) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 227 | SLOG(Cellular, 3) << GetLogPrefix(__func__) << "(" << operator_name << ")"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 228 | impl_->UpdateOperatorName(operator_name); |
| 229 | } |
| 230 | |
| 231 | void MobileOperatorInfo::UpdateOnlinePortal(const string &url, |
| 232 | const string &method, |
| 233 | const string &post_data) { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 234 | SLOG(Cellular, 3) << GetLogPrefix(__func__) |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 235 | << "(" << url |
| 236 | << ", " << method |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 237 | << ", " << post_data << ")"; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 238 | impl_->UpdateOnlinePortal(url, method, post_data); |
| 239 | } |
| 240 | |
| 241 | void MobileOperatorInfo::Reset() { |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 242 | SLOG(Cellular, 3) << GetLogPrefix(__func__); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 243 | impl_->Reset(); |
| 244 | } |
| 245 | |
| 246 | } // namespace shill |