blob: bc27c5b7333ac2ed722744a8efb1449037073e73 [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) {
Paul Stewartac4ac002011-08-26 12:04:26 -070030 PropertyStore *store = this->store();
31 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,
Chris Masone4d42df82011-07-02 17:09:39 -070037 &network_tech_);
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_);
43 store->RegisterConstString(flimflam::kTypeProperty, &type_);
44 store->RegisterConstString(flimflam::kUsageURLProperty, &usage_url_);
Chris Masone3bd3c8c2011-06-13 08:20:26 -070045}
46
47CellularService::~CellularService() { }
48
Darin Petkov4d6d9412011-08-24 13:19:54 -070049void CellularService::Connect(Error *error) {
50 cellular_->Connect(error);
Darin Petkovc5f56562011-08-06 16:40:05 -070051}
Chris Masone3bd3c8c2011-06-13 08:20:26 -070052
53void CellularService::Disconnect() { }
54
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
Chris Masone34af2182011-08-22 11:59:36 -070060string CellularService::GetStorageIdentifier(const string &mac) {
61 string id = base::StringPrintf("%s_%s_%s",
62 kServiceType,
63 mac.c_str(),
64 serving_operator_.GetName().c_str());
65 std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_');
66 return id;
67}
68
Darin Petkovc408e692011-08-17 13:47:15 -070069string CellularService::GetDeviceRpcId() {
Chris Masone95207da2011-06-29 16:50:49 -070070 return cellular_->GetRpcIdentifier();
71}
72
Darin Petkov3335b372011-08-22 11:05:32 -070073const Cellular::Operator &CellularService::serving_operator() const {
74 return serving_operator_;
75}
76
77void CellularService::set_serving_operator(const Cellular::Operator &oper) {
78 serving_operator_.CopyFrom(oper);
79}
80
Chris Masone3bd3c8c2011-06-13 08:20:26 -070081} // namespace shill