mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 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 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 13 | #include "shill/adaptor_interfaces.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 14 | #include "shill/cellular.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 15 | |
| 16 | using std::string; |
| 17 | |
| 18 | namespace shill { |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 19 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 20 | // static |
| 21 | const char CellularService::kServiceType[] = "cellular"; |
| 22 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 23 | CellularService::CellularService(ControlInterface *control_interface, |
| 24 | EventDispatcher *dispatcher, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 25 | Manager *manager, |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 26 | const CellularRefPtr &device) |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 27 | : Service(control_interface, dispatcher, manager, Technology::kCellular), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 28 | strength_(0), |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 29 | cellular_(device) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 30 | PropertyStore *store = this->mutable_store(); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 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, |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 37 | &network_technology_); |
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_); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 43 | store->RegisterConstString(flimflam::kUsageURLProperty, &usage_url_); |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 44 | |
| 45 | set_friendly_name(device->CreateFriendlyServiceName()); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | CellularService::~CellularService() { } |
| 49 | |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 50 | void CellularService::Connect(Error *error) { |
| 51 | cellular_->Connect(error); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 52 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 53 | |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 54 | void CellularService::Disconnect(Error */*error*/) { } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 55 | |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 56 | void CellularService::ActivateCellularModem(const string &carrier, |
| 57 | Error *error) { |
| 58 | cellular_->Activate(carrier, error); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 61 | bool CellularService::TechnologyIs(const Technology::Identifier type) const { |
| 62 | return cellular_->TechnologyIs(type); |
| 63 | } |
| 64 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 65 | string CellularService::GetStorageIdentifier() const { |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 66 | // TODO(petkov): Fix the return value (crosbug.com/24952). |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 67 | string id = base::StringPrintf("%s_%s_%s", |
| 68 | kServiceType, |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 69 | cellular_->address().c_str(), |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 70 | serving_operator_.GetName().c_str()); |
| 71 | std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_'); |
| 72 | return id; |
| 73 | } |
| 74 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 75 | string CellularService::GetDeviceRpcId(Error */*error*/) { |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 76 | return cellular_->GetRpcIdentifier(); |
| 77 | } |
| 78 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 79 | void CellularService::SetNetworkTechnology(const string &technology) { |
| 80 | if (technology == network_technology_) { |
| 81 | return; |
| 82 | } |
| 83 | network_technology_ = technology; |
| 84 | adaptor()->EmitStringChanged(flimflam::kNetworkTechnologyProperty, |
| 85 | technology); |
| 86 | } |
| 87 | |
| 88 | void CellularService::SetRoamingState(const string &state) { |
| 89 | if (state == roaming_state_) { |
| 90 | return; |
| 91 | } |
| 92 | roaming_state_ = state; |
| 93 | adaptor()->EmitStringChanged(flimflam::kRoamingStateProperty, state); |
| 94 | } |
| 95 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 96 | const Cellular::Operator &CellularService::serving_operator() const { |
| 97 | return serving_operator_; |
| 98 | } |
| 99 | |
| 100 | void CellularService::set_serving_operator(const Cellular::Operator &oper) { |
| 101 | serving_operator_.CopyFrom(oper); |
| 102 | } |
| 103 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 104 | } // namespace shill |