blob: f2e133a00e8b4c95efa2b5125bec5a0ac34adc08 [file] [log] [blame]
Darin Petkovb9c99332012-01-12 13:13:00 +01001// 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#ifndef SHILL_CELLULAR_SERVICE_
6#define SHILL_CELLULAR_SERVICE_
7
8#include <map>
9#include <string>
10
11#include <base/basictypes.h>
Darin Petkovb72cf402011-11-22 14:51:39 +010012#include <gtest/gtest_prod.h> // for FRIEND_TEST
Chris Masone3bd3c8c2011-06-13 08:20:26 -070013
Darin Petkov3335b372011-08-22 11:05:32 -070014#include "shill/cellular.h"
Chris Masone2b105542011-06-22 10:58:09 -070015#include "shill/refptr_types.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070016#include "shill/service.h"
17
18namespace shill {
19
Chris Masone6791a432011-07-12 13:23:19 -070020class ControlInterface;
Darin Petkovb100ae72011-08-24 16:19:45 -070021class Error;
Chris Masone6791a432011-07-12 13:23:19 -070022class EventDispatcher;
23class Manager;
24
Chris Masone3bd3c8c2011-06-13 08:20:26 -070025class CellularService : public Service {
26 public:
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040027 static const char kStorageAPN[];
28 static const char kStorageLastGoodAPN[];
29
Darin Petkov381928f2012-02-02 23:00:12 +010030 // Online payment portal.
31 class OLP {
32 public:
33 OLP();
34 ~OLP();
35
36 void CopyFrom(const OLP &olp);
37 bool Equals(const OLP &olp) const;
38
39 const std::string &GetURL() const;
40 void SetURL(const std::string &url);
41
42 const std::string &GetMethod() const;
43 void SetMethod(const std::string &method);
44
45 const std::string &GetPostData() const;
46 void SetPostData(const std::string &post_data);
47
48 const Stringmap &ToDict() const;
49
50 private:
51 Stringmap dict_;
52
53 DISALLOW_COPY_AND_ASSIGN(OLP);
54 };
55
Chris Masone3bd3c8c2011-06-13 08:20:26 -070056 CellularService(ControlInterface *control_interface,
57 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080058 Metrics *metrics,
Chris Masone6791a432011-07-12 13:23:19 -070059 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070060 const CellularRefPtr &device);
Darin Petkovd9661952011-08-03 16:25:42 -070061 virtual ~CellularService();
62
Darin Petkovc408e692011-08-17 13:47:15 -070063 // Inherited from Service.
Darin Petkov4d6d9412011-08-24 13:19:54 -070064 virtual void Connect(Error *error);
Darin Petkovfb0625e2012-01-16 13:05:56 +010065 virtual void Disconnect(Error *error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050066 virtual void ActivateCellularModem(const std::string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -050067 Error *error,
68 const ResultCallback &callback);
Paul Stewart22aa71b2011-09-16 12:15:11 -070069 virtual bool TechnologyIs(const Technology::Identifier type) const;
Darin Petkovc408e692011-08-17 13:47:15 -070070
Darin Petkov31332412012-01-28 01:50:02 +010071 virtual std::string GetStorageIdentifier() const;
72 void SetStorageIdentifier(const std::string &identifier);
Chris Masone34af2182011-08-22 11:59:36 -070073
Darin Petkovb9c99332012-01-12 13:13:00 +010074 void SetActivationState(const std::string &state);
Darin Petkovc408e692011-08-17 13:47:15 -070075 const std::string &activation_state() const { return activation_state_; }
Chris Masone3bd3c8c2011-06-13 08:20:26 -070076
Darin Petkov381928f2012-02-02 23:00:12 +010077 void SetOLP(const OLP &olp);
78 const OLP &olp() const { return olp_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070079
Darin Petkov381928f2012-02-02 23:00:12 +010080 void SetUsageURL(const std::string &url);
Darin Petkovb27e5442011-08-16 14:36:45 -070081 const std::string &usage_url() const { return usage_url_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070082
Darin Petkov9cb02682012-01-28 00:17:38 +010083 void SetServingOperator(const Cellular::Operator &oper);
Darin Petkov3335b372011-08-22 11:05:32 -070084 const Cellular::Operator &serving_operator() const;
Darin Petkov3335b372011-08-22 11:05:32 -070085
Darin Petkovb72cf402011-11-22 14:51:39 +010086 // Sets network technology to |technology| and broadcasts the property change.
87 void SetNetworkTechnology(const std::string &technology);
88 const std::string &network_technology() const { return network_technology_; }
Darin Petkovd2045802011-08-23 11:09:25 -070089
Darin Petkovb72cf402011-11-22 14:51:39 +010090 // Sets roaming state to |state| and broadcasts the property change.
91 void SetRoamingState(const std::string &state);
Darin Petkovd2045802011-08-23 11:09:25 -070092 const std::string &roaming_state() const { return roaming_state_; }
Darin Petkovd2045802011-08-23 11:09:25 -070093
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040094 // Overrride Load and Save from parent Service class. We will call
95 // the parent method.
96 virtual bool Load(StoreInterface *storage);
97 virtual bool Save(StoreInterface *storage);
98
99 Stringmap *GetUserSpecifiedApn();
100 Stringmap *GetLastGoodApn();
Jason Glasgow14521872012-05-07 19:12:15 -0400101 virtual void SetLastGoodApn(const Stringmap &apn_info);
102 virtual void ClearLastGoodApn();
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400103
Paul Stewartac4ac002011-08-26 12:04:26 -0700104 private:
Darin Petkovb72cf402011-11-22 14:51:39 +0100105 friend class CellularServiceTest;
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400106 FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList);
107 FRIEND_TEST(CellularCapabilityTest, TryApns);
Darin Petkovb72cf402011-11-22 14:51:39 +0100108 FRIEND_TEST(CellularTest, Connect);
Eric Shienbroodc7073302012-04-03 14:41:44 -0400109 FRIEND_TEST(CellularServiceTest, SetApn);
110 FRIEND_TEST(CellularServiceTest, ClearApn);
111 FRIEND_TEST(CellularServiceTest, LastGoodApn);
Darin Petkovb72cf402011-11-22 14:51:39 +0100112
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400113 void HelpRegisterDerivedStringmap(
114 const std::string &name,
115 Stringmap(CellularService::*get)(Error *error),
116 void(CellularService::*set)(const Stringmap &value, Error *error));
117
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800118 virtual std::string GetDeviceRpcId(Error *error);
Paul Stewartac4ac002011-08-26 12:04:26 -0700119
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400120 Stringmap GetApn(Error *error);
121 void SetApn(const Stringmap &value, Error *error);
122 static void SaveApn(StoreInterface *storage,
123 const std::string &storage_group,
124 const Stringmap *apn_info,
125 const std::string &keytag);
126 static void SaveApnField(StoreInterface *storage,
127 const std::string &storage_group,
128 const Stringmap *apn_info,
129 const std::string &keytag,
130 const std::string &apntag);
131 static void LoadApn(StoreInterface *storage,
132 const std::string &storage_group,
133 const std::string &keytag,
134 Stringmap *apn_info);
135 static bool LoadApnField(StoreInterface *storage,
136 const std::string &storage_group,
137 const std::string &keytag,
138 const std::string &apntag,
139 Stringmap *apn_info);
140
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700141 // Properties
142 std::string activation_state_;
Darin Petkov3335b372011-08-22 11:05:32 -0700143 Cellular::Operator serving_operator_;
Darin Petkovb72cf402011-11-22 14:51:39 +0100144 std::string network_technology_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700145 std::string roaming_state_;
Darin Petkov381928f2012-02-02 23:00:12 +0100146 OLP olp_;
Darin Petkovb27e5442011-08-16 14:36:45 -0700147 std::string usage_url_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700148
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400149 Stringmap apn_info_;
150 Stringmap last_good_apn_info_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700151
Darin Petkov31332412012-01-28 01:50:02 +0100152 std::string storage_identifier_;
153
Chris Masone2b105542011-06-22 10:58:09 -0700154 CellularRefPtr cellular_;
Darin Petkovd9661952011-08-03 16:25:42 -0700155
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700156 DISALLOW_COPY_AND_ASSIGN(CellularService);
157};
158
159} // namespace shill
160
161#endif // SHILL_CELLULAR_SERVICE_