blob: 7a9a7d4221c4478f1c9c8257c1a37ce43a72f86f [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_);
Chris Masone3bd3c8c2011-06-13 08:20:26 -070044}
45
46CellularService::~CellularService() { }
47
Darin Petkov4d6d9412011-08-24 13:19:54 -070048void CellularService::Connect(Error *error) {
49 cellular_->Connect(error);
Darin Petkovc5f56562011-08-06 16:40:05 -070050}
Chris Masone3bd3c8c2011-06-13 08:20:26 -070051
mukesh agrawal0ed0f2e2011-12-05 20:36:17 +000052void CellularService::Disconnect(Error */*error*/) { }
Chris Masone3bd3c8c2011-06-13 08:20:26 -070053
Darin Petkovb100ae72011-08-24 16:19:45 -070054void CellularService::ActivateCellularModem(const string &carrier,
55 Error *error) {
56 cellular_->Activate(carrier, error);
Darin Petkovc408e692011-08-17 13:47:15 -070057}
58
Paul Stewart22aa71b2011-09-16 12:15:11 -070059bool CellularService::TechnologyIs(const Technology::Identifier type) const {
60 return cellular_->TechnologyIs(type);
61}
62
Chris Masone6515aab2011-10-12 16:19:09 -070063string CellularService::GetStorageIdentifier() const {
Chris Masone34af2182011-08-22 11:59:36 -070064 string id = base::StringPrintf("%s_%s_%s",
65 kServiceType,
Chris Masone9d779932011-08-25 16:33:41 -070066 cellular_->address().c_str(),
Chris Masone34af2182011-08-22 11:59:36 -070067 serving_operator_.GetName().c_str());
68 std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_');
69 return id;
70}
71
Gaurav Shah1b7a6162011-11-09 11:41:01 -080072string CellularService::GetDeviceRpcId(Error */*error*/) {
Chris Masone95207da2011-06-29 16:50:49 -070073 return cellular_->GetRpcIdentifier();
74}
75
Darin Petkovb72cf402011-11-22 14:51:39 +010076void CellularService::SetNetworkTechnology(const string &technology) {
77 if (technology == network_technology_) {
78 return;
79 }
80 network_technology_ = technology;
81 adaptor()->EmitStringChanged(flimflam::kNetworkTechnologyProperty,
82 technology);
83}
84
85void CellularService::SetRoamingState(const string &state) {
86 if (state == roaming_state_) {
87 return;
88 }
89 roaming_state_ = state;
90 adaptor()->EmitStringChanged(flimflam::kRoamingStateProperty, state);
91}
92
Darin Petkov3335b372011-08-22 11:05:32 -070093const Cellular::Operator &CellularService::serving_operator() const {
94 return serving_operator_;
95}
96
97void CellularService::set_serving_operator(const Cellular::Operator &oper) {
98 serving_operator_.CopyFrom(oper);
99}
100
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700101} // namespace shill