blob: 43aa9178bb42d47634b7e3c1af9d0f40585b2be5 [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 Petkovb100ae72011-08-24 16:19:45 -070055void CellularService::ActivateCellularModem(const string &carrier,
56 Error *error) {
57 cellular_->Activate(carrier, error);
Darin Petkovc408e692011-08-17 13:47:15 -070058}
59
Paul Stewart22aa71b2011-09-16 12:15:11 -070060bool CellularService::TechnologyIs(const Technology::Identifier type) const {
61 return cellular_->TechnologyIs(type);
62}
63
Chris Masone6515aab2011-10-12 16:19:09 -070064string CellularService::GetStorageIdentifier() const {
Darin Petkovac635a82012-01-10 16:51:58 +010065 // TODO(petkov): Fix the return value (crosbug.com/24952).
Chris Masone34af2182011-08-22 11:59:36 -070066 string id = base::StringPrintf("%s_%s_%s",
67 kServiceType,
Chris Masone9d779932011-08-25 16:33:41 -070068 cellular_->address().c_str(),
Chris Masone34af2182011-08-22 11:59:36 -070069 serving_operator_.GetName().c_str());
70 std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_');
71 return id;
72}
73
Gaurav Shah1b7a6162011-11-09 11:41:01 -080074string CellularService::GetDeviceRpcId(Error */*error*/) {
Chris Masone95207da2011-06-29 16:50:49 -070075 return cellular_->GetRpcIdentifier();
76}
77
Darin Petkovb9c99332012-01-12 13:13:00 +010078void CellularService::SetActivationState(const string &state) {
79 if (state == activation_state_) {
80 return;
81 }
82 activation_state_ = state;
83 adaptor()->EmitStringChanged(flimflam::kActivationStateProperty, state);
84}
85
Darin Petkovb72cf402011-11-22 14:51:39 +010086void CellularService::SetNetworkTechnology(const string &technology) {
87 if (technology == network_technology_) {
88 return;
89 }
90 network_technology_ = technology;
91 adaptor()->EmitStringChanged(flimflam::kNetworkTechnologyProperty,
92 technology);
93}
94
95void CellularService::SetRoamingState(const string &state) {
96 if (state == roaming_state_) {
97 return;
98 }
99 roaming_state_ = state;
100 adaptor()->EmitStringChanged(flimflam::kRoamingStateProperty, state);
101}
102
Darin Petkov3335b372011-08-22 11:05:32 -0700103const Cellular::Operator &CellularService::serving_operator() const {
104 return serving_operator_;
105}
106
107void CellularService::set_serving_operator(const Cellular::Operator &oper) {
108 serving_operator_.CopyFrom(oper);
109}
110
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700111} // namespace shill