blob: e7eaf6debbf7bddce4ea35d7f1c768c95593b9f3 [file] [log] [blame]
mukesh agrawal8a3188d2011-12-01 20:56:44 +00001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masone3bd3c8c2011-06-13 08:20:26 -07002// 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 Masone34af2182011-08-22 11:59:36 -070010#include <base/stringprintf.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070011#include <chromeos/dbus/service_constants.h>
12
Darin Petkovb72cf402011-11-22 14:51:39 +010013#include "shill/adaptor_interfaces.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070014#include "shill/cellular.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070015
16using std::string;
17
18namespace shill {
Darin Petkovc5f56562011-08-06 16:40:05 -070019
Chris Masone34af2182011-08-22 11:59:36 -070020// static
21const char CellularService::kServiceType[] = "cellular";
22
Chris Masone3bd3c8c2011-06-13 08:20:26 -070023CellularService::CellularService(ControlInterface *control_interface,
24 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080025 Metrics *metrics,
Chris Masone6791a432011-07-12 13:23:19 -070026 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070027 const CellularRefPtr &device)
Thieu Le3426c8f2012-01-11 17:35:11 -080028 : Service(control_interface, dispatcher, metrics, manager,
29 Technology::kCellular),
mukesh agrawal7a4e4002011-09-06 11:26:05 -070030 cellular_(device) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070031 PropertyStore *store = this->mutable_store();
Paul Stewartac4ac002011-08-26 12:04:26 -070032 store->RegisterConstString(flimflam::kActivationStateProperty,
Chris Masone27c4aa52011-07-02 13:10:14 -070033 &activation_state_);
Paul Stewartac4ac002011-08-26 12:04:26 -070034 store->RegisterStringmap(flimflam::kCellularApnProperty, &apn_info_);
35 store->RegisterConstStringmap(flimflam::kCellularLastGoodApnProperty,
Chris Masone27c4aa52011-07-02 13:10:14 -070036 &last_good_apn_info_);
Paul Stewartac4ac002011-08-26 12:04:26 -070037 store->RegisterConstString(flimflam::kNetworkTechnologyProperty,
Darin Petkovb72cf402011-11-22 14:51:39 +010038 &network_technology_);
Paul Stewartac4ac002011-08-26 12:04:26 -070039 store->RegisterConstString(flimflam::kPaymentURLProperty, &payment_url_);
40 store->RegisterConstString(flimflam::kRoamingStateProperty, &roaming_state_);
41 store->RegisterConstStringmap(flimflam::kServingOperatorProperty,
Darin Petkov3335b372011-08-22 11:05:32 -070042 &serving_operator_.ToDict());
Paul Stewartac4ac002011-08-26 12:04:26 -070043 store->RegisterConstString(flimflam::kUsageURLProperty, &usage_url_);
Darin Petkovac635a82012-01-10 16:51:58 +010044
45 set_friendly_name(device->CreateFriendlyServiceName());
Chris Masone3bd3c8c2011-06-13 08:20:26 -070046}
47
48CellularService::~CellularService() { }
49
Darin Petkov4d6d9412011-08-24 13:19:54 -070050void CellularService::Connect(Error *error) {
mukesh agrawaladb68482012-01-17 16:31:51 -080051 Service::Connect(error);
Darin Petkov4d6d9412011-08-24 13:19:54 -070052 cellular_->Connect(error);
Darin Petkovc5f56562011-08-06 16:40:05 -070053}
Chris Masone3bd3c8c2011-06-13 08:20:26 -070054
Darin Petkovfb0625e2012-01-16 13:05:56 +010055void CellularService::Disconnect(Error *error) {
56 Service::Disconnect(error);
57 cellular_->Disconnect(error);
58}
59
Darin Petkovb100ae72011-08-24 16:19:45 -070060void CellularService::ActivateCellularModem(const string &carrier,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050061 ReturnerInterface *returner) {
62 cellular_->Activate(carrier, returner);
Darin Petkovc408e692011-08-17 13:47:15 -070063}
64
Paul Stewart22aa71b2011-09-16 12:15:11 -070065bool CellularService::TechnologyIs(const Technology::Identifier type) const {
66 return cellular_->TechnologyIs(type);
67}
68
Chris Masone6515aab2011-10-12 16:19:09 -070069string CellularService::GetStorageIdentifier() const {
Darin Petkovac635a82012-01-10 16:51:58 +010070 // TODO(petkov): Fix the return value (crosbug.com/24952).
Chris Masone34af2182011-08-22 11:59:36 -070071 string id = base::StringPrintf("%s_%s_%s",
72 kServiceType,
Chris Masone9d779932011-08-25 16:33:41 -070073 cellular_->address().c_str(),
Chris Masone34af2182011-08-22 11:59:36 -070074 serving_operator_.GetName().c_str());
75 std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_');
76 return id;
77}
78
Gaurav Shah1b7a6162011-11-09 11:41:01 -080079string CellularService::GetDeviceRpcId(Error */*error*/) {
Chris Masone95207da2011-06-29 16:50:49 -070080 return cellular_->GetRpcIdentifier();
81}
82
Darin Petkovb9c99332012-01-12 13:13:00 +010083void CellularService::SetActivationState(const string &state) {
84 if (state == activation_state_) {
85 return;
86 }
87 activation_state_ = state;
88 adaptor()->EmitStringChanged(flimflam::kActivationStateProperty, state);
89}
90
Darin Petkovb72cf402011-11-22 14:51:39 +010091void CellularService::SetNetworkTechnology(const string &technology) {
92 if (technology == network_technology_) {
93 return;
94 }
95 network_technology_ = technology;
96 adaptor()->EmitStringChanged(flimflam::kNetworkTechnologyProperty,
97 technology);
98}
99
100void CellularService::SetRoamingState(const string &state) {
101 if (state == roaming_state_) {
102 return;
103 }
104 roaming_state_ = state;
105 adaptor()->EmitStringChanged(flimflam::kRoamingStateProperty, state);
106}
107
Darin Petkov3335b372011-08-22 11:05:32 -0700108const Cellular::Operator &CellularService::serving_operator() const {
109 return serving_operator_;
110}
111
Darin Petkov9cb02682012-01-28 00:17:38 +0100112void CellularService::SetServingOperator(const Cellular::Operator &oper) {
113 if (serving_operator_.Equals(oper)) {
114 return;
115 }
Darin Petkov3335b372011-08-22 11:05:32 -0700116 serving_operator_.CopyFrom(oper);
Darin Petkov9cb02682012-01-28 00:17:38 +0100117 adaptor()->EmitStringmapChanged(flimflam::kServingOperatorProperty,
118 oper.ToDict());
Darin Petkov3335b372011-08-22 11:05:32 -0700119}
120
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700121} // namespace shill