blob: 71389524a2c429f0c25ef696aaf5b89b7f95976b [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,
Chris Masone6791a432011-07-12 13:23:19 -070025 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070026 const CellularRefPtr &device)
Gaurav Shah435de2c2011-11-17 19:01:07 -080027 : Service(control_interface, dispatcher, manager, Technology::kCellular),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070028 strength_(0),
mukesh agrawal7a4e4002011-09-06 11:26:05 -070029 cellular_(device) {
mukesh agrawalde29fa82011-09-16 16:16:36 -070030 PropertyStore *store = this->mutable_store();
Paul Stewartac4ac002011-08-26 12:04:26 -070031 store->RegisterConstString(flimflam::kActivationStateProperty,
Chris Masone27c4aa52011-07-02 13:10:14 -070032 &activation_state_);
Paul Stewartac4ac002011-08-26 12:04:26 -070033 store->RegisterStringmap(flimflam::kCellularApnProperty, &apn_info_);
34 store->RegisterConstStringmap(flimflam::kCellularLastGoodApnProperty,
Chris Masone27c4aa52011-07-02 13:10:14 -070035 &last_good_apn_info_);
Paul Stewartac4ac002011-08-26 12:04:26 -070036 store->RegisterConstString(flimflam::kNetworkTechnologyProperty,
Darin Petkovb72cf402011-11-22 14:51:39 +010037 &network_technology_);
Paul Stewartac4ac002011-08-26 12:04:26 -070038 store->RegisterConstString(flimflam::kPaymentURLProperty, &payment_url_);
39 store->RegisterConstString(flimflam::kRoamingStateProperty, &roaming_state_);
40 store->RegisterConstStringmap(flimflam::kServingOperatorProperty,
Darin Petkov3335b372011-08-22 11:05:32 -070041 &serving_operator_.ToDict());
Paul Stewartac4ac002011-08-26 12:04:26 -070042 store->RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_);
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) {
51 cellular_->Connect(error);
Darin Petkovc5f56562011-08-06 16:40:05 -070052}
Chris Masone3bd3c8c2011-06-13 08:20:26 -070053
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +000054void CellularService::Disconnect(Error */*error*/) { }
Chris Masone3bd3c8c2011-06-13 08:20:26 -070055
Darin Petkovb100ae72011-08-24 16:19:45 -070056void CellularService::ActivateCellularModem(const string &carrier,
57 Error *error) {
58 cellular_->Activate(carrier, error);
Darin Petkovc408e692011-08-17 13:47:15 -070059}
60
Paul Stewart22aa71b2011-09-16 12:15:11 -070061bool CellularService::TechnologyIs(const Technology::Identifier type) const {
62 return cellular_->TechnologyIs(type);
63}
64
Chris Masone6515aab2011-10-12 16:19:09 -070065string CellularService::GetStorageIdentifier() const {
Darin Petkovac635a82012-01-10 16:51:58 +010066 // TODO(petkov): Fix the return value (crosbug.com/24952).
Chris Masone34af2182011-08-22 11:59:36 -070067 string id = base::StringPrintf("%s_%s_%s",
68 kServiceType,
Chris Masone9d779932011-08-25 16:33:41 -070069 cellular_->address().c_str(),
Chris Masone34af2182011-08-22 11:59:36 -070070 serving_operator_.GetName().c_str());
71 std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_');
72 return id;
73}
74
Gaurav Shah1b7a6162011-11-09 11:41:01 -080075string CellularService::GetDeviceRpcId(Error */*error*/) {
Chris Masone95207da2011-06-29 16:50:49 -070076 return cellular_->GetRpcIdentifier();
77}
78
Darin Petkovb9c99332012-01-12 13:13:00 +010079void CellularService::SetActivationState(const string &state) {
80 if (state == activation_state_) {
81 return;
82 }
83 activation_state_ = state;
84 adaptor()->EmitStringChanged(flimflam::kActivationStateProperty, state);
85}
86
Darin Petkovb72cf402011-11-22 14:51:39 +010087void CellularService::SetNetworkTechnology(const string &technology) {
88 if (technology == network_technology_) {
89 return;
90 }
91 network_technology_ = technology;
92 adaptor()->EmitStringChanged(flimflam::kNetworkTechnologyProperty,
93 technology);
94}
95
96void CellularService::SetRoamingState(const string &state) {
97 if (state == roaming_state_) {
98 return;
99 }
100 roaming_state_ = state;
101 adaptor()->EmitStringChanged(flimflam::kRoamingStateProperty, state);
102}
103
Darin Petkov3335b372011-08-22 11:05:32 -0700104const Cellular::Operator &CellularService::serving_operator() const {
105 return serving_operator_;
106}
107
108void CellularService::set_serving_operator(const Cellular::Operator &oper) {
109 serving_operator_.CopyFrom(oper);
110}
111
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700112} // namespace shill