blob: a6c1140adb3821c28d3b178ac7d3091f204732bc [file] [log] [blame]
Chris Masone3bd3c8c2011-06-13 08:20:26 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2// 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
13#include "shill/cellular.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070014
15using std::string;
16
17namespace shill {
Darin Petkovc5f56562011-08-06 16:40:05 -070018
Chris Masone34af2182011-08-22 11:59:36 -070019// static
20const char CellularService::kServiceType[] = "cellular";
21
Chris Masone3bd3c8c2011-06-13 08:20:26 -070022CellularService::CellularService(ControlInterface *control_interface,
23 EventDispatcher *dispatcher,
Chris Masone6791a432011-07-12 13:23:19 -070024 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070025 const CellularRefPtr &device)
26 : Service(control_interface, dispatcher, manager),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070027 strength_(0),
mukesh agrawalf60e4062011-05-27 13:13:41 -070028 cellular_(device),
Chris Masone3bd3c8c2011-06-13 08:20:26 -070029 type_(flimflam::kTypeCellular) {
Chris Masone27c4aa52011-07-02 13:10:14 -070030 store_.RegisterConstString(flimflam::kActivationStateProperty,
31 &activation_state_);
Chris Masone27c4aa52011-07-02 13:10:14 -070032 store_.RegisterStringmap(flimflam::kCellularApnProperty, &apn_info_);
33 store_.RegisterConstStringmap(flimflam::kCellularLastGoodApnProperty,
34 &last_good_apn_info_);
Chris Masone4d42df82011-07-02 17:09:39 -070035 store_.RegisterConstString(flimflam::kNetworkTechnologyProperty,
36 &network_tech_);
Chris Masone4d42df82011-07-02 17:09:39 -070037 store_.RegisterConstString(flimflam::kPaymentURLProperty, &payment_url_);
38 store_.RegisterConstString(flimflam::kRoamingStateProperty, &roaming_state_);
Darin Petkov3335b372011-08-22 11:05:32 -070039 store_.RegisterConstStringmap(flimflam::kServingOperatorProperty,
40 &serving_operator_.ToDict());
Chris Masone27c4aa52011-07-02 13:10:14 -070041 store_.RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_);
Chris Masone27c4aa52011-07-02 13:10:14 -070042 store_.RegisterConstString(flimflam::kTypeProperty, &type_);
Darin Petkovb27e5442011-08-16 14:36:45 -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
52void CellularService::Disconnect() { }
53
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
Chris Masone34af2182011-08-22 11:59:36 -070059string CellularService::GetStorageIdentifier(const string &mac) {
60 string id = base::StringPrintf("%s_%s_%s",
61 kServiceType,
62 mac.c_str(),
63 serving_operator_.GetName().c_str());
64 std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_');
65 return id;
66}
67
Darin Petkovc408e692011-08-17 13:47:15 -070068string CellularService::GetDeviceRpcId() {
Chris Masone95207da2011-06-29 16:50:49 -070069 return cellular_->GetRpcIdentifier();
70}
71
Darin Petkov3335b372011-08-22 11:05:32 -070072const Cellular::Operator &CellularService::serving_operator() const {
73 return serving_operator_;
74}
75
76void CellularService::set_serving_operator(const Cellular::Operator &oper) {
77 serving_operator_.CopyFrom(oper);
78}
79
Chris Masone3bd3c8c2011-06-13 08:20:26 -070080} // namespace shill