blob: 487df55edaa55ef8757e54f9152df477ca94a646 [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 Petkovc5f56562011-08-06 16:40:05 -070048void CellularService::Connect() {
49 cellular_->Connect();
50}
Chris Masone3bd3c8c2011-06-13 08:20:26 -070051
52void CellularService::Disconnect() { }
53
Darin Petkovc408e692011-08-17 13:47:15 -070054void CellularService::ActivateCellularModem(const string &carrier) {
55 cellular_->Activate(carrier);
56}
57
Chris Masone34af2182011-08-22 11:59:36 -070058string CellularService::GetStorageIdentifier(const string &mac) {
59 string id = base::StringPrintf("%s_%s_%s",
60 kServiceType,
61 mac.c_str(),
62 serving_operator_.GetName().c_str());
63 std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_');
64 return id;
65}
66
Darin Petkovc408e692011-08-17 13:47:15 -070067string CellularService::GetDeviceRpcId() {
Chris Masone95207da2011-06-29 16:50:49 -070068 return cellular_->GetRpcIdentifier();
69}
70
Darin Petkov3335b372011-08-22 11:05:32 -070071const Cellular::Operator &CellularService::serving_operator() const {
72 return serving_operator_;
73}
74
75void CellularService::set_serving_operator(const Cellular::Operator &oper) {
76 serving_operator_.CopyFrom(oper);
77}
78
Chris Masone3bd3c8c2011-06-13 08:20:26 -070079} // namespace shill