blob: 3f968b151cfe9bf9e7092b57ac34ed3dfdb2ba51 [file] [log] [blame]
mukesh agrawal8a3188d2011-12-01 20:56:44 +00001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewart75897df2011-04-27 09:05:53 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Chris Masone9be4a9d2011-05-16 15:44:09 -07005#ifndef SHILL_SERVICE_
6#define SHILL_SERVICE_
Paul Stewart75897df2011-04-27 09:05:53 -07007
Chris Masone9be4a9d2011-05-16 15:44:09 -07008#include <string>
Chris Masone8fe2c7e2011-06-09 15:51:19 -07009#include <map>
Paul Stewartcb59fed2012-03-21 21:14:46 -070010#include <set>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070011#include <vector>
Chris Masone9be4a9d2011-05-16 15:44:09 -070012
13#include <base/memory/ref_counted.h>
Paul Stewartba41b992011-05-26 07:02:46 -070014#include <base/memory/scoped_ptr.h>
Darin Petkovba40dd32011-07-11 20:06:39 -070015#include <gtest/gtest_prod.h> // for FRIEND_TEST
Paul Stewart75897df2011-04-27 09:05:53 -070016
Eric Shienbrood9a245532012-03-07 14:20:39 -050017#include "shill/adaptor_interfaces.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070018#include "shill/accessor_interface.h"
Eric Shienbrood9a245532012-03-07 14:20:39 -050019#include "shill/callbacks.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070020#include "shill/property_store.h"
Chris Masone7aa5f902011-07-11 11:13:35 -070021#include "shill/refptr_types.h"
Paul Stewartbe5f5b32011-12-07 17:11:11 -080022#include "shill/sockets.h"
Paul Stewart22aa71b2011-09-16 12:15:11 -070023#include "shill/technology.h"
Chris Masonec1e50412011-06-07 13:04:53 -070024
Thieu Leb84ba342012-03-02 15:15:19 -080025namespace chromeos_metrics {
26class Timer;
27}
28
Paul Stewart75897df2011-04-27 09:05:53 -070029namespace shill {
30
Paul Stewart75897df2011-04-27 09:05:53 -070031class Configuration;
Chris Masone9be4a9d2011-05-16 15:44:09 -070032class ControlInterface;
Paul Stewart75897df2011-04-27 09:05:53 -070033class Endpoint;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070034class Error;
Chris Masone9be4a9d2011-05-16 15:44:09 -070035class EventDispatcher;
Paul Stewartbe5f5b32011-12-07 17:11:11 -080036class HTTPProxy;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070037class KeyValueStore;
Chris Masone6791a432011-07-12 13:23:19 -070038class Manager;
Thieu Le48e6d6d2011-12-06 00:40:27 +000039class Metrics;
Chris Masone9be4a9d2011-05-16 15:44:09 -070040class ServiceAdaptorInterface;
Darin Petkovba40dd32011-07-11 20:06:39 -070041class StoreInterface;
Paul Stewart75897df2011-04-27 09:05:53 -070042
Chris Masone7aa5f902011-07-11 11:13:35 -070043// A Service is a uniquely named entity, which the system can
44// connect in order to begin sending and receiving network traffic.
45// All Services are bound to an Entry, which represents the persistable
46// state of the Service. If the Entry is populated at the time of Service
47// creation, that information is used to prime the Service. If not, the Entry
48// becomes populated over time.
Chris Masone27c4aa52011-07-02 13:10:14 -070049class Service : public base::RefCounted<Service> {
Paul Stewart75897df2011-04-27 09:05:53 -070050 public:
Darin Petkovba40dd32011-07-11 20:06:39 -070051 static const char kCheckPortalAuto[];
52 static const char kCheckPortalFalse[];
53 static const char kCheckPortalTrue[];
54
Paul Stewart0756db92012-01-27 08:34:47 -080055 // TODO(pstew): Storage constants shouldn't need to be public
56 // crosbug.com/25813
57 static const char kStorageAutoConnect[];
58 static const char kStorageCheckPortal[];
59 static const char kStorageEapAnonymousIdentity[];
60 static const char kStorageEapCACert[];
61 static const char kStorageEapCACertID[];
62 static const char kStorageEapCertID[];
63 static const char kStorageEapClientCert[];
64 static const char kStorageEapEap[];
65 static const char kStorageEapIdentity[];
66 static const char kStorageEapInnerEap[];
67 static const char kStorageEapKeyID[];
68 static const char kStorageEapKeyManagement[];
69 static const char kStorageEapPIN[];
70 static const char kStorageEapPassword[];
71 static const char kStorageEapPrivateKey[];
72 static const char kStorageEapPrivateKeyPassword[];
73 static const char kStorageEapUseSystemCAs[];
74 static const char kStorageError[];
75 static const char kStorageFavorite[];
76 static const char kStorageGUID[];
77 static const char kStorageName[];
78 static const char kStoragePriority[];
79 static const char kStorageProxyConfig[];
80 static const char kStorageSaveCredentials[];
81 static const char kStorageType[];
82 static const char kStorageUIData[];
83
mukesh agrawal8f3f7752012-02-17 19:42:09 -080084 static const uint8 kStrengthMax;
85 static const uint8 kStrengthMin;
86
Paul Stewart75897df2011-04-27 09:05:53 -070087 enum ConnectFailure {
Paul Stewart03dba0b2011-08-22 16:32:45 -070088 kFailureUnknown,
89 kFailureActivationFailure,
90 kFailureOutOfRange,
91 kFailurePinMissing,
92 kFailureConfigurationFailed,
93 kFailureBadCredentials,
94 kFailureNeedEVDO,
95 kFailureNeedHomeNetwork,
96 kFailureOTASPFailure,
Thieu Le48e6d6d2011-12-06 00:40:27 +000097 kFailureAAAFailure,
98 kFailureMax
Paul Stewart75897df2011-04-27 09:05:53 -070099 };
Chris Masone9be4a9d2011-05-16 15:44:09 -0700100 enum ConnectState {
Paul Stewart03dba0b2011-08-22 16:32:45 -0700101 kStateUnknown,
102 kStateIdle,
103 kStateAssociating,
104 kStateConfiguring,
105 kStateConnected,
106 kStateDisconnected,
Thieu Le48e6d6d2011-12-06 00:40:27 +0000107 kStatePortal,
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800108 kStateFailure,
109 kStateOnline
Chris Masone9be4a9d2011-05-16 15:44:09 -0700110 };
Chris Masoneb2e326b2011-07-12 13:28:51 -0700111 struct EapCredentials {
112 EapCredentials() : use_system_cas(false) {}
113 std::string identity;
114 std::string eap;
115 std::string inner_eap;
116 std::string anonymous_identity;
117 std::string client_cert;
118 std::string cert_id;
119 std::string private_key;
120 std::string private_key_password;
121 std::string key_id;
122 std::string ca_cert;
123 std::string ca_cert_id;
124 bool use_system_cas;
125 std::string pin;
126 std::string password;
127 std::string key_management;
128 };
Chris Masone9be4a9d2011-05-16 15:44:09 -0700129
Paul Stewartac4ac002011-08-26 12:04:26 -0700130 static const int kPriorityNone;
131
Chris Masone9be4a9d2011-05-16 15:44:09 -0700132 // A constructor for the Service object
133 Service(ControlInterface *control_interface,
134 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -0800135 Metrics *metrics,
mukesh agrawal7a4e4002011-09-06 11:26:05 -0700136 Manager *manager,
Gaurav Shah435de2c2011-11-17 19:01:07 -0800137 Technology::Identifier technology);
Chris Masone9be4a9d2011-05-16 15:44:09 -0700138 virtual ~Service();
Darin Petkovba40dd32011-07-11 20:06:39 -0700139
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000140 // AutoConnect MAY choose to ignore the connection request in some
141 // cases. For example, if the corresponding Device only supports one
142 // concurrent connection, and another Service is already connected
143 // or connecting.
144 //
145 // AutoConnect MAY issue RPCs immediately. So AutoConnect MUST NOT
146 // be called from a D-Bus signal handler context.
147 virtual void AutoConnect();
148 // Queue up a connection attempt.
mukesh agrawaladb68482012-01-17 16:31:51 -0800149 virtual void Connect(Error *error);
150 // Disconnect this service. The service will not be eligible for
151 // auto-connect until a subsequent call to Connect, or Load.
152 virtual void Disconnect(Error *error);
Chris Masonea82b7112011-05-25 15:16:29 -0700153
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500154 // The default implementation returns the error kInvalidArguments.
155 virtual void ActivateCellularModem(const std::string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500156 Error *error,
157 const ResultCallback &callback);
Darin Petkovc408e692011-08-17 13:47:15 -0700158
Paul Stewart22aa71b2011-09-16 12:15:11 -0700159 // Base method always returns false.
160 virtual bool TechnologyIs(const Technology::Identifier type) const;
161
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800162 virtual bool IsActive(Error *error);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700163
164 virtual ConnectState state() const { return state_; }
165 // Updates the state of the Service and alerts the manager. Also
166 // clears |failure_| if the new state isn't a failure.
167 virtual void SetState(ConnectState state);
168
Paul Stewart22aa71b2011-09-16 12:15:11 -0700169 // State utility functions
Paul Stewart20088d82012-02-16 06:58:55 -0800170 virtual bool IsConnected() const {
171 return state() == kStateConnected || state() == kStatePortal ||
172 state() == kStateOnline;
173 }
Gaurav Shah435de2c2011-11-17 19:01:07 -0800174 virtual bool IsConnecting() const {
Paul Stewart22aa71b2011-09-16 12:15:11 -0700175 return state() == kStateAssociating || state() == kStateConfiguring;
176 }
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000177 virtual bool IsFailed() const {
178 return state() == kStateFailure;
179 }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700180
Paul Stewart03dba0b2011-08-22 16:32:45 -0700181 virtual ConnectFailure failure() const { return failure_; }
182 // Records the failure mode, and sets the Service state to "Failure".
183 virtual void SetFailure(ConnectFailure failure);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700184
Darin Petkovba40dd32011-07-11 20:06:39 -0700185 // Returns a string that is guaranteed to uniquely identify this Service
186 // instance.
mukesh agrawald835b202011-10-07 15:26:47 -0700187 const std::string &UniqueName() const { return unique_name_; }
Darin Petkovafa6fc42011-06-21 16:21:08 -0700188
Chris Masone6791a432011-07-12 13:23:19 -0700189 virtual std::string GetRpcIdentifier() const;
Chris Masone3c3f6a12011-07-01 10:01:41 -0700190
Darin Petkovba40dd32011-07-11 20:06:39 -0700191 // Returns the unique persistent storage identifier for the service.
Chris Masone6515aab2011-10-12 16:19:09 -0700192 virtual std::string GetStorageIdentifier() const = 0;
Darin Petkovba40dd32011-07-11 20:06:39 -0700193
Paul Stewartbba6a5b2011-11-02 18:45:59 -0700194 // Returns whether the service configuration can be loaded from |storage|.
195 virtual bool IsLoadableFrom(StoreInterface *storage) const;
196
Darin Petkovba40dd32011-07-11 20:06:39 -0700197 // Loads the service from persistent |storage|. Returns true on success.
Chris Masone9d779932011-08-25 16:33:41 -0700198 virtual bool Load(StoreInterface *storage);
Darin Petkovba40dd32011-07-11 20:06:39 -0700199
Paul Stewarta41e38d2011-11-11 07:47:29 -0800200 // Indicate to service that it is no longer persisted to storage. It
201 // should purge any stored profile state (e.g., credentials).
202 virtual void Unload();
203
Darin Petkovba40dd32011-07-11 20:06:39 -0700204 // Saves the service to persistent |storage|. Returns true on success.
Chris Masone9d779932011-08-25 16:33:41 -0700205 virtual bool Save(StoreInterface *storage);
Darin Petkovba40dd32011-07-11 20:06:39 -0700206
Thieu Led4e9e552012-02-16 16:26:07 -0800207 // Saves the service to the current profile.
208 virtual bool SaveToCurrentProfile();
209
Paul Stewartcb59fed2012-03-21 21:14:46 -0700210 // Applies all the properties in |args| to this service object's mutable
211 // store, except for those in parameters_ignored_for_configure_.
212 // Returns an error in |error| if one or more parameter set attempts
213 // fails, but will only return the first error.
214 virtual void Configure(const KeyValueStore &args, Error *error);
215
Paul Stewarta41e38d2011-11-11 07:47:29 -0800216 // Returns true if the service RPC identifier should be part of the
217 // manager's advertised services list, false otherwise.
218 virtual bool IsVisible() const { return true; }
219
Paul Stewart20088d82012-02-16 06:58:55 -0800220 // Returns true if there is a proxy configuration set on this service.
221 virtual bool HasProxyConfig() const { return !proxy_config_.empty(); }
222
mukesh agrawal00917ce2011-11-22 23:56:55 +0000223 virtual void MakeFavorite();
224
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800225 // Set the connection for this service. If the connection is
226 // non-NULL, create an HTTP Proxy that will utilize this service's
227 // connection to serve requests.
228 virtual void SetConnection(ConnectionRefPtr connection);
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800229
Gaurav Shah10109f22011-11-11 20:16:22 -0800230 // Examines the EAP credentials for the service and returns true if a
231 // connection attempt can be made.
232 bool Is8021xConnectable() const;
233
Thieu Le48e6d6d2011-12-06 00:40:27 +0000234 // The inherited class should register any custom metrics in this method.
235 virtual void InitializeCustomMetrics() const {}
236
237 // The inherited class that needs to send metrics after the service has
Thieu Leb84ba342012-03-02 15:15:19 -0800238 // transitioned to the ready state should override this method.
239 // |time_resume_to_ready_milliseconds| holds the elapsed time from when
240 // the system was resumed until when the service transitioned to the
241 // connected state. This value is non-zero for the first service transition
242 // to the connected state after a resume.
243 virtual void SendPostReadyStateMetrics(
244 int64 /*time_resume_to_ready_milliseconds*/) const {}
Thieu Le48e6d6d2011-12-06 00:40:27 +0000245
Darin Petkovafa6fc42011-06-21 16:21:08 -0700246 bool auto_connect() const { return auto_connect_; }
247 void set_auto_connect(bool connect) { auto_connect_ = connect; }
Paul Stewart75897df2011-04-27 09:05:53 -0700248
Gaurav Shah435de2c2011-11-17 19:01:07 -0800249 bool connectable() const { return connectable_; }
mukesh agrawal29c13a12011-11-24 00:09:19 +0000250 void set_connectable(bool connectable);
Gaurav Shah435de2c2011-11-17 19:01:07 -0800251
Thieu Le67370f62012-02-14 23:01:42 +0000252 virtual bool explicitly_disconnected() const {
253 return explicitly_disconnected_;
254 }
255
Paul Stewart22aa71b2011-09-16 12:15:11 -0700256 bool favorite() const { return favorite_; }
mukesh agrawal00917ce2011-11-22 23:56:55 +0000257 // Setter is deliberately omitted; use MakeFavorite.
Paul Stewart22aa71b2011-09-16 12:15:11 -0700258
mukesh agrawal15908392011-11-16 18:29:25 +0000259 const std::string &friendly_name() const { return friendly_name_; }
Darin Petkov7f060332012-03-14 11:46:47 +0100260 void set_friendly_name(const std::string &n) { friendly_name_ = n; }
mukesh agrawal15908392011-11-16 18:29:25 +0000261
Paul Stewart4c561612012-03-21 12:49:01 -0700262 const std::string &guid() const { return guid_; }
263 void set_guid(const std::string &guid) { guid_ = guid; }
264
Paul Stewart22aa71b2011-09-16 12:15:11 -0700265 int32 priority() const { return priority_; }
266 void set_priority(int32 priority) { priority_ = priority; }
267
Paul Stewart1ca3e852011-11-04 07:50:49 -0700268 int32 security_level() const { return security_level_; }
269 void set_security_level(int32 security) { security_level_ = security; }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700270
Darin Petkovd78ee7e2012-01-12 11:21:10 +0100271 void SetStrength(uint8 strength);
mukesh agrawale1d90e92012-02-15 17:36:08 -0800272
273 // uint8 streams out as a char. Coerce to a larger type, so that
274 // it prints as a number.
275 uint16 strength() const { return strength_; }
Paul Stewart22aa71b2011-09-16 12:15:11 -0700276
Gaurav Shah435de2c2011-11-17 19:01:07 -0800277 virtual Technology::Identifier technology() const { return technology_; }
278 std::string GetTechnologyString(Error *error);
279
Gaurav Shah10109f22011-11-11 20:16:22 -0800280 const EapCredentials &eap() const { return eap_; }
281 virtual void set_eap(const EapCredentials &eap);
282
Darin Petkov51489002011-08-18 13:13:20 -0700283 const std::string &error() const { return error_; }
284 void set_error(const std::string &error) { error_ = error; }
285
Gaurav Shahc6d6c722011-11-17 18:59:39 -0800286 static const char *ConnectFailureToString(const ConnectFailure &state);
287 static const char *ConnectStateToString(const ConnectState &state);
288
Paul Stewart22aa71b2011-09-16 12:15:11 -0700289 // Compare two services. Returns true if Service a should be displayed
290 // above Service b
291 static bool Compare(ServiceRefPtr a,
292 ServiceRefPtr b,
mukesh agrawalddc378f2012-02-17 18:26:20 -0800293 const std::vector<Technology::Identifier> &tech_order,
294 const char **reason);
Paul Stewart22aa71b2011-09-16 12:15:11 -0700295
Chris Masone34af2182011-08-22 11:59:36 -0700296 // These are defined in service.cc so that we don't have to include profile.h
Chris Masone9d779932011-08-25 16:33:41 -0700297 // TODO(cmasone): right now, these are here only so that we can get the
298 // profile name as a property. Can we store just the name, and then handle
299 // setting the profile for this service via |manager_|?
Chris Masone6791a432011-07-12 13:23:19 -0700300 const ProfileRefPtr &profile() const;
301 void set_profile(const ProfileRefPtr &p);
302
mukesh agrawalde29fa82011-09-16 16:16:36 -0700303 PropertyStore *mutable_store() { return &store_; }
304 const PropertyStore &store() const { return store_; }
Paul Stewartce4ec192012-03-14 12:53:46 -0700305 virtual const ConnectionRefPtr &connection() const { return connection_; }
Chris Masone27c4aa52011-07-02 13:10:14 -0700306
mukesh agrawalb54601c2011-06-07 17:39:22 -0700307 protected:
Chris Masone34af2182011-08-22 11:59:36 -0700308 // Returns true if a character is allowed to be in a service storage id.
309 static bool LegalChar(char a) { return isalnum(a) || a == '_'; }
310
Darin Petkov31332412012-01-28 01:50:02 +0100311 // Returns true if a character is disallowed to be in a service storage id.
312 static bool IllegalChar(char a) { return !LegalChar(a); }
313
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800314 virtual std::string CalculateState(Error *error);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700315
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000316 // Returns whether this service is in a state conducive to auto-connect.
317 // This should include any tests used for computing connectable(),
318 // as well as other critera such as whether the device associated with
319 // this service is busy with another connection.
mukesh agrawalbf14e942012-03-02 14:36:34 -0800320 //
321 // If the service is not auto-connectable, |*reason| will be set to
322 // point to C-string explaining why the service is not auto-connectable.
323 virtual bool IsAutoConnectable(const char **reason) const;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000324
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800325 // HelpRegisterDerived*: Expose a property over RPC, with the name |name|.
326 //
327 // Reads of the property will be handled by invoking |get|.
328 // Writes to the property will be handled by invoking |set|.
329 // Clearing the property will be handled by PropertyStore.
mukesh agrawalffa3d042011-10-06 15:26:10 -0700330 void HelpRegisterDerivedBool(
331 const std::string &name,
Hristo Stefanoved2c28c2011-11-29 15:37:30 -0800332 bool(Service::*get)(Error *error),
333 void(Service::*set)(const bool &value, Error *error));
mukesh agrawalffa3d042011-10-06 15:26:10 -0700334 void HelpRegisterDerivedString(
335 const std::string &name,
Hristo Stefanoved2c28c2011-11-29 15:37:30 -0800336 std::string(Service::*get)(Error *error),
337 void(Service::*set)(const std::string &value, Error *error));
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800338 void HelpRegisterDerivedUint16(
339 const std::string &name,
340 uint16(Service::*get)(Error *error),
341 void(Service::*set)(const uint16 &value, Error *error));
mukesh agrawal292dc0f2012-01-26 18:02:46 -0800342 // Expose a property over RPC, with the name |name|.
343 //
344 // Reads of the property will be handled by invoking |get|.
345 // Writes to the property will be handled by invoking |set|.
346 //
347 // Clearing the property will be handled by invoking |clear|, or
348 // calling |set| with |default_value| (whichever is non-NULL). It
349 // is an error to call this method with both |clear| and
350 // |default_value| non-NULL.
351 void HelpRegisterWriteOnlyDerivedString(
352 const std::string &name,
353 void(Service::*set)(const std::string &value, Error *error),
354 void(Service::*clear)(Error *error),
355 const std::string *default_value);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700356
Darin Petkovb72cf402011-11-22 14:51:39 +0100357 ServiceAdaptorInterface *adaptor() const { return adaptor_.get(); }
358
Darin Petkovba40dd32011-07-11 20:06:39 -0700359 // Assigns |value| to |key| in |storage| if |value| is non-empty and |save| is
360 // true. Otherwise, removes |key| from |storage|. If |crypted| is true, the
361 // value is encrypted.
362 void SaveString(StoreInterface *storage,
Chris Masone34af2182011-08-22 11:59:36 -0700363 const std::string &id,
Darin Petkovba40dd32011-07-11 20:06:39 -0700364 const std::string &key,
365 const std::string &value,
366 bool crypted,
367 bool save);
368
Chris Masone34af2182011-08-22 11:59:36 -0700369 void LoadEapCredentials(StoreInterface *storage, const std::string &id);
370 void SaveEapCredentials(StoreInterface *storage, const std::string &id);
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800371 void UnloadEapCredentials();
Darin Petkovba40dd32011-07-11 20:06:39 -0700372
Paul Stewartcb59fed2012-03-21 21:14:46 -0700373 // Ignore |parameter| when performing a Configure() operation.
374 void IgnoreParameterForConfigure(const std::string &parameter);
375
Paul Stewartac4ac002011-08-26 12:04:26 -0700376 // Property accessors reserved for subclasses
377 EventDispatcher *dispatcher() const { return dispatcher_; }
378 const std::string &GetEAPKeyManagement() const;
379 void SetEAPKeyManagement(const std::string &key_management);
Paul Stewart9f32d192012-01-30 20:37:50 -0800380 void SetEAPPassword(const std::string &password, Error *error);
381 void SetEAPPrivateKeyPassword(const std::string &password, Error *error);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000382 Metrics *metrics() const { return metrics_; }
mukesh agrawalb54601c2011-06-07 17:39:22 -0700383
Paul Stewart75897df2011-04-27 09:05:53 -0700384 private:
Thieu Le48e6d6d2011-12-06 00:40:27 +0000385 friend class MetricsTest;
Paul Stewart0756db92012-01-27 08:34:47 -0800386 friend class ServiceAdaptorInterface;
mukesh agrawale1d90e92012-02-15 17:36:08 -0800387 friend class WiFiServiceTest;
Paul Stewartcb59fed2012-03-21 21:14:46 -0700388 FRIEND_TEST(ServiceTest, ConfigureIgnoredProperty);
389 FRIEND_TEST(ServiceTest, ConfigureStringProperty);
Darin Petkovba40dd32011-07-11 20:06:39 -0700390 FRIEND_TEST(ServiceTest, Constructor);
Thieu Le284fe792012-01-31 17:53:19 -0800391 FRIEND_TEST(ServiceTest, GetProperties);
mukesh agrawal76d13882012-01-12 15:23:11 -0800392 FRIEND_TEST(ServiceTest, IsAutoConnectable);
Darin Petkovba40dd32011-07-11 20:06:39 -0700393 FRIEND_TEST(ServiceTest, Save);
394 FRIEND_TEST(ServiceTest, SaveString);
395 FRIEND_TEST(ServiceTest, SaveStringCrypted);
396 FRIEND_TEST(ServiceTest, SaveStringDontSave);
397 FRIEND_TEST(ServiceTest, SaveStringEmpty);
mukesh agrawal6bb9e7c2012-01-30 14:57:54 -0800398 FRIEND_TEST(ServiceTest, SetProperty);
Paul Stewartd8ad3c42012-01-09 12:39:38 -0800399 FRIEND_TEST(ServiceTest, Unload);
Darin Petkovba40dd32011-07-11 20:06:39 -0700400
mukesh agrawalbf14e942012-03-02 14:36:34 -0800401 static const char kAutoConnConnected[];
402 static const char kAutoConnConnecting[];
403 static const char kAutoConnExplicitDisconnect[];
404 static const char kAutoConnNotConnectable[];
405
mukesh agrawalddc378f2012-02-17 18:26:20 -0800406 static const char kServiceSortConnectEtc[];
407 static const char kServiceSortIsConnected[];
408 static const char kServiceSortIsConnecting[];
409 static const char kServiceSortIsFailed[];
410 static const char kServiceSortTechnology[];
411 static const char kServiceSortSecurityEtc[];
412 static const char kServiceSortUniqueName[];
413
Thieu Le284fe792012-01-31 17:53:19 -0800414 bool GetAutoConnect(Error *error);
415 void SetAutoConnect(const bool &connect, Error *error);
416
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800417 virtual std::string GetDeviceRpcId(Error *error) = 0;
Chris Masone95207da2011-06-29 16:50:49 -0700418
Paul Stewart1b1a7f22012-01-06 16:24:06 -0800419 std::string GetProfileRpcId(Error *error);
420 void SetProfileRpcId(const std::string &profile, Error *error);
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700421
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800422 // Returns TCP port of service's HTTP proxy in host order.
423 uint16 GetHTTPProxyPort(Error *error);
424
Paul Stewart22aa71b2011-09-16 12:15:11 -0700425 // Utility function that returns true if a is different from b. When they
426 // are, "decision" is populated with the boolean value of "a > b".
427 static bool DecideBetween(int a, int b, bool *decision);
428
Thieu Le284fe792012-01-31 17:53:19 -0800429 // For unit testing.
430 void set_favorite(bool favorite) { favorite_ = favorite; }
431
Paul Stewartac4ac002011-08-26 12:04:26 -0700432 ConnectState state_;
433 ConnectFailure failure_;
434 bool auto_connect_;
435 std::string check_portal_;
436 bool connectable_;
437 std::string error_;
mukesh agrawaladb68482012-01-17 16:31:51 -0800438 bool explicitly_disconnected_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700439 bool favorite_;
440 int32 priority_;
Paul Stewart1ca3e852011-11-04 07:50:49 -0700441 int32 security_level_;
Darin Petkovd78ee7e2012-01-12 11:21:10 +0100442 uint8 strength_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700443 std::string proxy_config_;
Paul Stewart987e71e2011-12-05 09:45:06 -0800444 std::string ui_data_;
Paul Stewart4c561612012-03-21 12:49:01 -0700445 std::string guid_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700446 bool save_credentials_;
447 EapCredentials eap_; // Only saved if |save_credentials_| is true.
Gaurav Shah435de2c2011-11-17 19:01:07 -0800448 Technology::Identifier technology_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700449
450 ProfileRefPtr profile_;
451 PropertyStore store_;
Paul Stewartcb59fed2012-03-21 21:14:46 -0700452 std::set<std::string> parameters_ignored_for_configure_;
Paul Stewartac4ac002011-08-26 12:04:26 -0700453
454 EventDispatcher *dispatcher_;
mukesh agrawal51a7e932011-07-27 16:18:26 -0700455 static unsigned int serial_number_;
mukesh agrawald835b202011-10-07 15:26:47 -0700456 std::string unique_name_; // MUST be unique amongst service instances
457 std::string friendly_name_; // MAY be same as |unique_name_|
Paul Stewart75897df2011-04-27 09:05:53 -0700458 bool available_;
459 bool configured_;
Paul Stewart75897df2011-04-27 09:05:53 -0700460 Configuration *configuration_;
Paul Stewartba41b992011-05-26 07:02:46 -0700461 scoped_ptr<ServiceAdaptorInterface> adaptor_;
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800462 scoped_ptr<HTTPProxy> http_proxy_;
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800463 ConnectionRefPtr connection_;
Thieu Le3426c8f2012-01-11 17:35:11 -0800464 Metrics *metrics_;
Chris Masone6791a432011-07-12 13:23:19 -0700465 Manager *manager_;
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800466 Sockets sockets_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700467
mukesh agrawalb54601c2011-06-07 17:39:22 -0700468 DISALLOW_COPY_AND_ASSIGN(Service);
Paul Stewart75897df2011-04-27 09:05:53 -0700469};
470
471} // namespace shill
472
473#endif // SHILL_SERVICE_