blob: 100c9477b3fe473f18a28b8242604cf7dbcafff7 [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());
Darin Petkov31332412012-01-28 01:50:02 +010046 SetStorageIdentifier("cellular_" + device->address() + "_" + friendly_name());
Chris Masone3bd3c8c2011-06-13 08:20:26 -070047}
48
49CellularService::~CellularService() { }
50
Darin Petkov4d6d9412011-08-24 13:19:54 -070051void CellularService::Connect(Error *error) {
mukesh agrawaladb68482012-01-17 16:31:51 -080052 Service::Connect(error);
Darin Petkov4d6d9412011-08-24 13:19:54 -070053 cellular_->Connect(error);
Darin Petkovc5f56562011-08-06 16:40:05 -070054}
Chris Masone3bd3c8c2011-06-13 08:20:26 -070055
Darin Petkovfb0625e2012-01-16 13:05:56 +010056void CellularService::Disconnect(Error *error) {
57 Service::Disconnect(error);
58 cellular_->Disconnect(error);
59}
60
Darin Petkovb100ae72011-08-24 16:19:45 -070061void CellularService::ActivateCellularModem(const string &carrier,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050062 ReturnerInterface *returner) {
63 cellular_->Activate(carrier, returner);
Darin Petkovc408e692011-08-17 13:47:15 -070064}
65
Paul Stewart22aa71b2011-09-16 12:15:11 -070066bool CellularService::TechnologyIs(const Technology::Identifier type) const {
67 return cellular_->TechnologyIs(type);
68}
69
Darin Petkov31332412012-01-28 01:50:02 +010070void CellularService::SetStorageIdentifier(const string &identifier) {
71 storage_identifier_ = identifier;
72 std::replace_if(storage_identifier_.begin(),
73 storage_identifier_.end(),
74 &Service::IllegalChar, '_');
75}
76
Chris Masone6515aab2011-10-12 16:19:09 -070077string CellularService::GetStorageIdentifier() const {
Darin Petkov31332412012-01-28 01:50:02 +010078 return storage_identifier_;
Chris Masone34af2182011-08-22 11:59:36 -070079}
80
Gaurav Shah1b7a6162011-11-09 11:41:01 -080081string CellularService::GetDeviceRpcId(Error */*error*/) {
Chris Masone95207da2011-06-29 16:50:49 -070082 return cellular_->GetRpcIdentifier();
83}
84
Darin Petkovb9c99332012-01-12 13:13:00 +010085void CellularService::SetActivationState(const string &state) {
86 if (state == activation_state_) {
87 return;
88 }
89 activation_state_ = state;
90 adaptor()->EmitStringChanged(flimflam::kActivationStateProperty, state);
91}
92
Darin Petkovb72cf402011-11-22 14:51:39 +010093void CellularService::SetNetworkTechnology(const string &technology) {
94 if (technology == network_technology_) {
95 return;
96 }
97 network_technology_ = technology;
98 adaptor()->EmitStringChanged(flimflam::kNetworkTechnologyProperty,
99 technology);
100}
101
102void CellularService::SetRoamingState(const string &state) {
103 if (state == roaming_state_) {
104 return;
105 }
106 roaming_state_ = state;
107 adaptor()->EmitStringChanged(flimflam::kRoamingStateProperty, state);
108}
109
Darin Petkov3335b372011-08-22 11:05:32 -0700110const Cellular::Operator &CellularService::serving_operator() const {
111 return serving_operator_;
112}
113
Darin Petkov9cb02682012-01-28 00:17:38 +0100114void CellularService::SetServingOperator(const Cellular::Operator &oper) {
115 if (serving_operator_.Equals(oper)) {
116 return;
117 }
Darin Petkov3335b372011-08-22 11:05:32 -0700118 serving_operator_.CopyFrom(oper);
Darin Petkov9cb02682012-01-28 00:17:38 +0100119 adaptor()->EmitStringmapChanged(flimflam::kServingOperatorProperty,
120 oper.ToDict());
Darin Petkov3335b372011-08-22 11:05:32 -0700121}
122
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700123} // namespace shill