Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 1 | // 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 | #include "shill/cellular_service.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <base/logging.h> |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 10 | #include <base/stringprintf.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 11 | #include <chromeos/dbus/service_constants.h> |
| 12 | |
| 13 | #include "shill/cellular.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 14 | |
| 15 | using std::string; |
| 16 | |
| 17 | namespace shill { |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 18 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 19 | // static |
| 20 | const char CellularService::kServiceType[] = "cellular"; |
| 21 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 22 | CellularService::CellularService(ControlInterface *control_interface, |
| 23 | EventDispatcher *dispatcher, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 24 | Manager *manager, |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 25 | const CellularRefPtr &device) |
| 26 | : Service(control_interface, dispatcher, manager), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 27 | strength_(0), |
mukesh agrawal | f60e406 | 2011-05-27 13:13:41 -0700 | [diff] [blame] | 28 | cellular_(device), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 29 | type_(flimflam::kTypeCellular) { |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame^] | 30 | PropertyStore *store = this->store(); |
| 31 | store->RegisterConstString(flimflam::kActivationStateProperty, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 32 | &activation_state_); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame^] | 33 | store->RegisterStringmap(flimflam::kCellularApnProperty, &apn_info_); |
| 34 | store->RegisterConstStringmap(flimflam::kCellularLastGoodApnProperty, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 35 | &last_good_apn_info_); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame^] | 36 | store->RegisterConstString(flimflam::kNetworkTechnologyProperty, |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 37 | &network_tech_); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame^] | 38 | store->RegisterConstString(flimflam::kPaymentURLProperty, &payment_url_); |
| 39 | store->RegisterConstString(flimflam::kRoamingStateProperty, &roaming_state_); |
| 40 | store->RegisterConstStringmap(flimflam::kServingOperatorProperty, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 41 | &serving_operator_.ToDict()); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame^] | 42 | store->RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_); |
| 43 | store->RegisterConstString(flimflam::kTypeProperty, &type_); |
| 44 | store->RegisterConstString(flimflam::kUsageURLProperty, &usage_url_); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | CellularService::~CellularService() { } |
| 48 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 49 | void CellularService::Connect(Error *error) { |
| 50 | cellular_->Connect(error); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 51 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 52 | |
| 53 | void CellularService::Disconnect() { } |
| 54 | |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 55 | void CellularService::ActivateCellularModem(const string &carrier, |
| 56 | Error *error) { |
| 57 | cellular_->Activate(carrier, error); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 60 | string CellularService::GetStorageIdentifier(const string &mac) { |
| 61 | string id = base::StringPrintf("%s_%s_%s", |
| 62 | kServiceType, |
| 63 | mac.c_str(), |
| 64 | serving_operator_.GetName().c_str()); |
| 65 | std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_'); |
| 66 | return id; |
| 67 | } |
| 68 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 69 | string CellularService::GetDeviceRpcId() { |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 70 | return cellular_->GetRpcIdentifier(); |
| 71 | } |
| 72 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 73 | const Cellular::Operator &CellularService::serving_operator() const { |
| 74 | return serving_operator_; |
| 75 | } |
| 76 | |
| 77 | void CellularService::set_serving_operator(const Cellular::Operator &oper) { |
| 78 | serving_operator_.CopyFrom(oper); |
| 79 | } |
| 80 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 81 | } // namespace shill |