cellular_service.cc revision 34af218abe6a99144ffe01332ce36fbad94f2628
176b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
276b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest// Use of this source code is governed by a BSD-style license that can be
376b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest// found in the LICENSE file.
476b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
576b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest#include "shill/cellular_service.h"
676b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
776b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest#include <string>
876b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
976b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest#include <base/logging.h>
1076b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest#include <base/stringprintf.h>
1176b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest#include <chromeos/dbus/service_constants.h>
1276b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
1376b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest#include "shill/cellular.h"
140183fb5394f105d544472a52b2b4ba628e01da92Wink Saville
1576b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWestusing std::string;
1676b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
1776b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWestnamespace shill {
1876b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
1976b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest// static
2076b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWestconst char CellularService::kServiceType[] = "cellular";
2176b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
2276b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWestCellularService::CellularService(ControlInterface *control_interface,
237995ca4165cae43b9bff25a6e6eafdb51445b698Sanket Padawe                                 EventDispatcher *dispatcher,
2476b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest                                 Manager *manager,
2576b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest                                 const CellularRefPtr &device)
26dcd0bf72b86932dcbefbb9313952cd3707226490Meng Wang    : Service(control_interface, dispatcher, manager),
2776b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest      strength_(0),
286f03829e746aa3f505d71723001a7f84a806452fXiaohui Chen      cellular_(device),
2939b467482d1bf256a111c757e9b7621c6f523271Jason Monk      type_(flimflam::kTypeCellular) {
30b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk  store_.RegisterConstString(flimflam::kActivationStateProperty,
3176b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest                             &activation_state_);
3276b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  store_.RegisterStringmap(flimflam::kCellularApnProperty, &apn_info_);
3376b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  store_.RegisterConstStringmap(flimflam::kCellularLastGoodApnProperty,
3476b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest                                &last_good_apn_info_);
3576b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  store_.RegisterConstString(flimflam::kNetworkTechnologyProperty,
3676b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest                             &network_tech_);
3776b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  store_.RegisterConstString(flimflam::kPaymentURLProperty, &payment_url_);
3876b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  store_.RegisterConstString(flimflam::kRoamingStateProperty, &roaming_state_);
3976b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  store_.RegisterConstStringmap(flimflam::kServingOperatorProperty,
40b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk                                &serving_operator_.ToDict());
4176b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  store_.RegisterConstUint8(flimflam::kSignalStrengthProperty, &strength_);
42b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk  store_.RegisterConstString(flimflam::kTypeProperty, &type_);
4376b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  store_.RegisterConstString(flimflam::kUsageURLProperty, &usage_url_);
4476b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest}
4576b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
4676b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWestCellularService::~CellularService() { }
4776b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
4876b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWestvoid CellularService::Connect() {
4976b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  cellular_->Connect();
509d1bfd1e8de6e46137a9571507c03526880d6a46Chris Wren}
5139b467482d1bf256a111c757e9b7621c6f523271Jason Monk
5239b467482d1bf256a111c757e9b7621c6f523271Jason Monkvoid CellularService::Disconnect() { }
5339b467482d1bf256a111c757e9b7621c6f523271Jason Monk
5439b467482d1bf256a111c757e9b7621c6f523271Jason Monkvoid CellularService::ActivateCellularModem(const string &carrier) {
55b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk  cellular_->Activate(carrier);
56b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk}
57ad2114e99b545d3e8c5d8addedd418deb97f3210Fan Zhang
5839b467482d1bf256a111c757e9b7621c6f523271Jason Monkstring CellularService::GetStorageIdentifier(const string &mac) {
5976b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  string id = base::StringPrintf("%s_%s_%s",
6076b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest                                 kServiceType,
61ad2114e99b545d3e8c5d8addedd418deb97f3210Fan Zhang                                 mac.c_str(),
62ad2114e99b545d3e8c5d8addedd418deb97f3210Fan Zhang                                 serving_operator_.GetName().c_str());
63ad2114e99b545d3e8c5d8addedd418deb97f3210Fan Zhang  std::replace_if(id.begin(), id.end(), &Service::LegalChar, '_');
6476b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  return id;
6576b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest}
6676b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
6776b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWeststring CellularService::GetDeviceRpcId() {
6876b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  return cellular_->GetRpcIdentifier();
6976b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest}
7076b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
7176b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWestconst Cellular::Operator &CellularService::serving_operator() const {
7276b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest  return serving_operator_;
7376b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest}
7476b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
7576b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWestvoid CellularService::set_serving_operator(const Cellular::Operator &oper) {
76b7e4380cd27ffd8a060ecb61201057fb6843e408Jason Monk  serving_operator_.CopyFrom(oper);
7776b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest}
7876b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest
7976b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest}  // namespace shill
8076b0801173b6b8493cd9776e44f4effddd5512c2PauloftheWest