mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 5 | #include "shill/manager.h" |
| 6 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | #include <time.h> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 8 | #include <stdio.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 9 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 10 | #include <algorithm> |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 11 | #include <set> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 12 | #include <string> |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 13 | #include <vector> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 14 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 15 | #include <base/bind.h> |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 16 | #include <base/file_util.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 17 | #include <base/logging.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 18 | #include <base/memory/ref_counted.h> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 19 | #include <base/stringprintf.h> |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 20 | #include <base/string_util.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 21 | #include <chromeos/dbus/service_constants.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 22 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 23 | #include "shill/adaptor_interfaces.h" |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 24 | #include "shill/connection.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 25 | #include "shill/control_interface.h" |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 26 | #include "shill/dbus_adaptor.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 27 | #include "shill/default_profile.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 28 | #include "shill/device.h" |
| 29 | #include "shill/device_info.h" |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 30 | #include "shill/ephemeral_profile.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 31 | #include "shill/error.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 32 | #include "shill/event_dispatcher.h" |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 33 | #include "shill/key_file_store.h" |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 34 | #include "shill/metrics.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 35 | #include "shill/profile.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 36 | #include "shill/property_accessor.h" |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 37 | #include "shill/proxy_factory.h" |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 38 | #include "shill/resolver.h" |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 39 | #include "shill/scope_logger.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 40 | #include "shill/service.h" |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 41 | #include "shill/service_sorter.h" |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 42 | #include "shill/vpn_service.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 43 | #include "shill/wifi.h" |
| 44 | #include "shill/wifi_service.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 45 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 46 | using base::Bind; |
| 47 | using base::StringPrintf; |
| 48 | using base::Unretained; |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 49 | using std::set; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 50 | using std::string; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 51 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 52 | |
| 53 | namespace shill { |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 54 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 55 | // statics |
| 56 | const char Manager::kErrorNoDevice[] = "no wifi devices available"; |
| 57 | const char Manager::kErrorTypeRequired[] = "must specify service type"; |
| 58 | const char Manager::kErrorUnsupportedServiceType[] = |
| 59 | "service type is unsupported"; |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 60 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 61 | Manager::Manager(ControlInterface *control_interface, |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 62 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 63 | Metrics *metrics, |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 64 | GLib *glib, |
| 65 | const string &run_directory, |
| 66 | const string &storage_directory, |
| 67 | const string &user_storage_format) |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 68 | : dispatcher_(dispatcher), |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 69 | run_path_(FilePath(run_directory)), |
| 70 | storage_path_(FilePath(storage_directory)), |
| 71 | user_storage_format_(user_storage_format), |
| 72 | adaptor_(control_interface->CreateManagerAdaptor(this)), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 73 | device_info_(control_interface, dispatcher, metrics, this), |
| 74 | modem_info_(control_interface, dispatcher, metrics, this, glib), |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 75 | vpn_provider_(control_interface, dispatcher, metrics, this), |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 76 | wimax_provider_(control_interface, dispatcher, metrics, this), |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 77 | running_(false), |
| 78 | connect_profiles_to_rpc_(true), |
| 79 | ephemeral_profile_(new EphemeralProfile(control_interface, this)), |
| 80 | control_interface_(control_interface), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 81 | metrics_(metrics), |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 82 | glib_(glib), |
| 83 | use_startup_portal_list_(false) { |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 84 | HelpRegisterDerivedString(flimflam::kActiveProfileProperty, |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 85 | &Manager::GetActiveProfileRpcIdentifier, |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 86 | NULL); |
Paul Stewart | d408fdf | 2012-05-07 17:15:57 -0700 | [diff] [blame] | 87 | store_.RegisterBool(flimflam::kArpGatewayProperty, &props_.arp_gateway); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 88 | HelpRegisterDerivedStrings(flimflam::kAvailableTechnologiesProperty, |
| 89 | &Manager::AvailableTechnologies, |
| 90 | NULL); |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 91 | HelpRegisterDerivedString(flimflam::kCheckPortalListProperty, |
| 92 | &Manager::GetCheckPortalList, |
| 93 | &Manager::SetCheckPortalList); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 94 | HelpRegisterDerivedStrings(flimflam::kConnectedTechnologiesProperty, |
| 95 | &Manager::ConnectedTechnologies, |
| 96 | NULL); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 97 | store_.RegisterString(flimflam::kCountryProperty, &props_.country); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 98 | HelpRegisterDerivedString(flimflam::kDefaultTechnologyProperty, |
| 99 | &Manager::DefaultTechnology, |
| 100 | NULL); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 101 | HelpRegisterDerivedStrings(flimflam::kDevicesProperty, |
| 102 | &Manager::EnumerateDevices, |
| 103 | NULL); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 104 | HelpRegisterDerivedStrings(flimflam::kEnabledTechnologiesProperty, |
| 105 | &Manager::EnabledTechnologies, |
| 106 | NULL); |
| 107 | store_.RegisterBool(flimflam::kOfflineModeProperty, &props_.offline_mode); |
| 108 | store_.RegisterString(flimflam::kPortalURLProperty, &props_.portal_url); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 109 | store_.RegisterInt32(kPortalCheckIntervalProperty, |
| 110 | &props_.portal_check_interval_seconds); |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 111 | HelpRegisterDerivedStrings(flimflam::kProfilesProperty, |
| 112 | &Manager::EnumerateProfiles, |
| 113 | NULL); |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 114 | store_.RegisterString(kHostNameProperty, &props_.host_name); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 115 | HelpRegisterDerivedString(flimflam::kStateProperty, |
| 116 | &Manager::CalculateState, |
| 117 | NULL); |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 118 | HelpRegisterConstDerivedRpcIdentifiers(flimflam::kServicesProperty, |
| 119 | &Manager::EnumerateAvailableServices); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 120 | HelpRegisterDerivedStrings(flimflam::kServiceWatchListProperty, |
| 121 | &Manager::EnumerateWatchedServices, |
| 122 | NULL); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 123 | |
mukesh agrawal | 84de5d2 | 2012-02-17 19:29:15 -0800 | [diff] [blame] | 124 | // Set default technology order "by hand", to avoid invoking side |
| 125 | // effects of SetTechnologyOrder. |
| 126 | technology_order_.push_back( |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 127 | Technology::IdentifierFromName(flimflam::kTypeVPN)); |
| 128 | technology_order_.push_back( |
mukesh agrawal | 84de5d2 | 2012-02-17 19:29:15 -0800 | [diff] [blame] | 129 | Technology::IdentifierFromName(flimflam::kTypeEthernet)); |
| 130 | technology_order_.push_back( |
Darin Petkov | e08d919 | 2012-05-21 12:21:15 +0200 | [diff] [blame] | 131 | Technology::IdentifierFromName(flimflam::kTypeWimax)); |
| 132 | technology_order_.push_back( |
mukesh agrawal | 84de5d2 | 2012-02-17 19:29:15 -0800 | [diff] [blame] | 133 | Technology::IdentifierFromName(flimflam::kTypeWifi)); |
| 134 | technology_order_.push_back( |
| 135 | Technology::IdentifierFromName(flimflam::kTypeCellular)); |
| 136 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 137 | SLOG(Manager, 2) << "Manager initialized."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 140 | Manager::~Manager() { |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 141 | profiles_.clear(); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 142 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 143 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 144 | void Manager::AddDeviceToBlackList(const string &device_name) { |
| 145 | device_info_.AddDeviceToBlackList(device_name); |
| 146 | } |
| 147 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 148 | void Manager::Start() { |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 149 | LOG(INFO) << "Manager started."; |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 150 | |
Gary Morain | ac1bdb4 | 2012-02-16 17:42:29 -0800 | [diff] [blame] | 151 | power_manager_.reset(new PowerManager(ProxyFactory::GetInstance())); |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 152 | // TODO(ers): weak ptr for metrics_? |
| 153 | PowerManager::PowerStateCallback cb = |
| 154 | Bind(&Metrics::NotifyPowerStateChange, Unretained(metrics_)); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 155 | power_manager_->AddStateChangeCallback(Metrics::kMetricPowerManagerKey, cb); |
| 156 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 157 | CHECK(file_util::CreateDirectory(run_path_)) << run_path_.value(); |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 158 | Resolver::GetInstance()->set_path(run_path_.Append("resolv.conf")); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 159 | |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 160 | InitializeProfiles(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 161 | running_ = true; |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 162 | adaptor_->UpdateRunning(); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 163 | device_info_.Start(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 164 | modem_info_.Start(); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 165 | vpn_provider_.Start(); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 166 | wimax_provider_.Start(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void Manager::Stop() { |
| 170 | running_ = false; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 171 | // Persist profile, device, service information to disk. |
| 172 | vector<ProfileRefPtr>::iterator it; |
| 173 | for (it = profiles_.begin(); it != profiles_.end(); ++it) { |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 174 | // Since this happens in a loop, the current manager state is stored to |
| 175 | // all default profiles in the stack. This is acceptable because the |
| 176 | // only time multiple default profiles are loaded are during autotests. |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 177 | (*it)->Save(); |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 178 | } |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 179 | |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 180 | vector<ServiceRefPtr>::iterator services_it; |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 181 | Error e; |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 182 | for (services_it = services_.begin(); services_it != services_.end(); |
| 183 | ++services_it) { |
mukesh agrawal | 0ed0f2e | 2011-12-05 20:36:17 +0000 | [diff] [blame] | 184 | (*services_it)->Disconnect(&e); |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 187 | adaptor_->UpdateRunning(); |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 188 | wimax_provider_.Stop(); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 189 | vpn_provider_.Stop(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 190 | modem_info_.Stop(); |
| 191 | device_info_.Stop(); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 192 | |
| 193 | // Some unit tests do not call Manager::Start(). |
| 194 | if (power_manager_.get()) |
| 195 | power_manager_->RemoveStateChangeCallback(Metrics::kMetricPowerManagerKey); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 198 | void Manager::InitializeProfiles() { |
| 199 | DCHECK(profiles_.empty()); |
| 200 | // The default profile must go first on the stack. |
| 201 | CHECK(file_util::CreateDirectory(storage_path_)) << storage_path_.value(); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 202 | scoped_refptr<DefaultProfile> |
| 203 | default_profile(new DefaultProfile(control_interface_, |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 204 | this, |
| 205 | storage_path_, |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 206 | DefaultProfile::kDefaultId, |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 207 | props_)); |
Paul Stewart | 870523b | 2012-01-11 17:00:42 -0800 | [diff] [blame] | 208 | CHECK(default_profile->InitStorage(glib_, Profile::kCreateOrOpenExisting, |
| 209 | NULL)); |
| 210 | CHECK(default_profile->LoadManagerProperties(&props_)); |
| 211 | profiles_.push_back(default_profile.release()); |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 212 | Error error; |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 213 | string path; |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 214 | for (vector<string>::iterator it = startup_profiles_.begin(); |
| 215 | it != startup_profiles_.end(); ++it) |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 216 | PushProfile(*it, &path, &error); |
Gaurav Shah | 7135476 | 2011-11-28 19:22:49 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 219 | void Manager::CreateProfile(const string &name, string *path, Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 220 | SLOG(Manager, 2) << __func__ << " " << name; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 221 | Profile::Identifier ident; |
| 222 | if (!Profile::ParseIdentifier(name, &ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 223 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 224 | "Invalid profile name " + name); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 225 | return; |
| 226 | } |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 227 | |
| 228 | ProfileRefPtr profile; |
| 229 | if (ident.user.empty()) { |
| 230 | profile = new DefaultProfile(control_interface_, |
| 231 | this, |
| 232 | storage_path_, |
| 233 | ident.identifier, |
| 234 | props_); |
| 235 | } else { |
| 236 | profile = new Profile(control_interface_, |
| 237 | this, |
| 238 | ident, |
| 239 | user_storage_format_, |
Gary Morain | b672d35 | 2012-04-25 09:19:06 -0700 | [diff] [blame] | 240 | true); |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 243 | if (!profile->InitStorage(glib_, Profile::kCreateNew, error)) { |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 244 | // |error| will have been populated by InitStorage(). |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 245 | return; |
| 246 | } |
| 247 | |
| 248 | // Save profile data out, and then let the scoped pointer fall out of scope. |
| 249 | if (!profile->Save()) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 250 | Error::PopulateAndLog(error, Error::kInternalError, |
| 251 | "Profile name " + name + " could not be saved"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 252 | return; |
| 253 | } |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 254 | |
| 255 | *path = profile->GetRpcIdentifier(); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 258 | void Manager::PushProfile(const string &name, string *path, Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 259 | SLOG(Manager, 2) << __func__ << " " << name; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 260 | Profile::Identifier ident; |
| 261 | if (!Profile::ParseIdentifier(name, &ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 262 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 263 | "Invalid profile name " + name); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 264 | return; |
| 265 | } |
| 266 | |
| 267 | for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin(); |
| 268 | it != profiles_.end(); |
| 269 | ++it) { |
| 270 | if ((*it)->MatchesIdentifier(ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 271 | Error::PopulateAndLog(error, Error::kAlreadyExists, |
| 272 | "Profile name " + name + " is already on stack"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 273 | return; |
| 274 | } |
| 275 | } |
| 276 | |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 277 | ProfileRefPtr profile; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 278 | if (ident.user.empty()) { |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 279 | // Allow a machine-wide-profile to be pushed on the stack only if the |
| 280 | // profile stack is empty, or if the topmost profile on the stack is |
| 281 | // also a machine-wide (non-user) profile. |
| 282 | if (!profiles_.empty() && !profiles_.back()->GetUser().empty()) { |
| 283 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 284 | "Cannot load non-default global profile " + name + |
| 285 | " on top of a user profile"); |
| 286 | return; |
| 287 | } |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 288 | |
Paul Stewart | d0a3b81 | 2012-03-28 22:48:22 -0700 | [diff] [blame] | 289 | scoped_refptr<DefaultProfile> |
| 290 | default_profile(new DefaultProfile(control_interface_, |
| 291 | this, |
| 292 | storage_path_, |
| 293 | ident.identifier, |
| 294 | props_)); |
| 295 | if (!default_profile->InitStorage(glib_, Profile::kOpenExisting, error)) { |
| 296 | // |error| will have been populated by InitStorage(). |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | if (!default_profile->LoadManagerProperties(&props_)) { |
| 301 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 302 | "Could not load Manager properties from profile " + |
| 303 | name); |
| 304 | return; |
| 305 | } |
| 306 | profile = default_profile; |
| 307 | } else { |
| 308 | profile = new Profile(control_interface_, |
| 309 | this, |
| 310 | ident, |
| 311 | user_storage_format_, |
| 312 | connect_profiles_to_rpc_); |
| 313 | if (!profile->InitStorage(glib_, Profile::kOpenExisting, error)) { |
| 314 | // |error| will have been populated by InitStorage(). |
| 315 | return; |
| 316 | } |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Paul Stewart | a849a3d | 2011-11-03 05:54:09 -0700 | [diff] [blame] | 319 | profiles_.push_back(profile); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 320 | |
| 321 | // Offer each registered Service the opportunity to join this new Profile. |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 322 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
| 323 | it != services_.end(); ++it) { |
Paul Stewart | bba6a5b | 2011-11-02 18:45:59 -0700 | [diff] [blame] | 324 | profile->ConfigureService(*it); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 327 | // Shop the Profile contents around to Devices which can create |
| 328 | // non-visible services. |
| 329 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 330 | it != devices_.end(); ++it) { |
| 331 | profile->ConfigureDevice(*it); |
| 332 | } |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 333 | |
Paul Stewart | 6681533 | 2012-04-09 18:09:36 -0700 | [diff] [blame] | 334 | // Offer the Profile contents to the VPNProvider which will create |
| 335 | // new VPN services if necessary. |
| 336 | vpn_provider_.CreateServicesFromProfile(profile); |
| 337 | |
Paul Stewart | 19c871d | 2011-12-15 16:10:13 -0800 | [diff] [blame] | 338 | *path = profile->GetRpcIdentifier(); |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 339 | SortServices(); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void Manager::PopProfileInternal() { |
| 343 | CHECK(!profiles_.empty()); |
| 344 | ProfileRefPtr active_profile = profiles_.back(); |
| 345 | profiles_.pop_back(); |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 346 | vector<ServiceRefPtr>::iterator it; |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 347 | for (it = services_.begin(); it != services_.end();) { |
| 348 | if ((*it)->profile().get() != active_profile.get() || |
| 349 | MatchProfileWithService(*it) || |
| 350 | !UnloadService(&it)) { |
| 351 | LOG(ERROR) << "Skipping unload of service"; |
| 352 | ++it; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 355 | SortServices(); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 358 | void Manager::PopProfile(const string &name, Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 359 | SLOG(Manager, 2) << __func__ << " " << name; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 360 | Profile::Identifier ident; |
| 361 | if (profiles_.empty()) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 362 | Error::PopulateAndLog(error, Error::kNotFound, "Profile stack is empty"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 363 | return; |
| 364 | } |
| 365 | ProfileRefPtr active_profile = profiles_.back(); |
| 366 | if (!Profile::ParseIdentifier(name, &ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 367 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 368 | "Invalid profile name " + name); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 369 | return; |
| 370 | } |
| 371 | if (!active_profile->MatchesIdentifier(ident)) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 372 | Error::PopulateAndLog(error, Error::kNotSupported, |
| 373 | name + " is not the active profile"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 374 | return; |
| 375 | } |
| 376 | PopProfileInternal(); |
| 377 | } |
| 378 | |
| 379 | void Manager::PopAnyProfile(Error *error) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 380 | SLOG(Manager, 2) << __func__; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 381 | Profile::Identifier ident; |
| 382 | if (profiles_.empty()) { |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 383 | Error::PopulateAndLog(error, Error::kNotFound, "Profile stack is empty"); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 384 | return; |
| 385 | } |
| 386 | PopProfileInternal(); |
| 387 | } |
| 388 | |
Paul Stewart | e73d05c | 2012-03-29 16:26:05 -0700 | [diff] [blame] | 389 | void Manager::RemoveProfile(const string &name, Error *error) { |
| 390 | Profile::Identifier ident; |
| 391 | if (!Profile::ParseIdentifier(name, &ident)) { |
| 392 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 393 | "Invalid profile name " + name); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin(); |
| 398 | it != profiles_.end(); |
| 399 | ++it) { |
| 400 | if ((*it)->MatchesIdentifier(ident)) { |
| 401 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 402 | "Cannot remove profile name " + name + |
| 403 | " since it is on stack"); |
| 404 | return; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | ProfileRefPtr profile; |
| 409 | if (ident.user.empty()) { |
| 410 | profile = new DefaultProfile(control_interface_, |
| 411 | this, |
| 412 | storage_path_, |
| 413 | ident.identifier, |
| 414 | props_); |
| 415 | } else { |
| 416 | profile = new Profile(control_interface_, |
| 417 | this, |
| 418 | ident, |
| 419 | user_storage_format_, |
| 420 | false); |
| 421 | } |
| 422 | |
| 423 | |
| 424 | // |error| will have been populated if RemoveStorage fails. |
| 425 | profile->RemoveStorage(glib_, error); |
| 426 | |
| 427 | return; |
| 428 | } |
| 429 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 430 | bool Manager::HandleProfileEntryDeletion(const ProfileRefPtr &profile, |
| 431 | const std::string &entry_name) { |
| 432 | bool moved_services = false; |
| 433 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 434 | it != services_.end();) { |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 435 | if ((*it)->profile().get() == profile.get() && |
| 436 | (*it)->GetStorageIdentifier() == entry_name) { |
| 437 | profile->AbandonService(*it); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 438 | if (MatchProfileWithService(*it) || |
| 439 | !UnloadService(&it)) { |
| 440 | ++it; |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 441 | } |
| 442 | moved_services = true; |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 443 | } else { |
| 444 | ++it; |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | return moved_services; |
| 448 | } |
| 449 | |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 450 | ServiceRefPtr Manager::GetServiceWithStorageIdentifier( |
| 451 | const ProfileRefPtr &profile, const std::string &entry_name, Error *error) { |
| 452 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
| 453 | it != services_.end(); ++it) { |
| 454 | if ((*it)->profile().get() == profile.get() && |
| 455 | (*it)->GetStorageIdentifier() == entry_name) { |
| 456 | return *it; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | Error::PopulateAndLog(error, Error::kNotFound, |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 461 | StringPrintf("Entry %s is not registered in the manager", |
| 462 | entry_name.c_str())); |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 463 | return NULL; |
| 464 | } |
| 465 | |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 466 | ServiceRefPtr Manager::GetServiceWithGUID( |
| 467 | const std::string &guid, Error *error) { |
| 468 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
| 469 | it != services_.end(); ++it) { |
| 470 | if ((*it)->guid() == guid) { |
| 471 | return *it; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | Error::PopulateAndLog(error, Error::kNotFound, |
| 476 | StringPrintf("Service wth GUID %s is not registered in the manager", |
| 477 | guid.c_str())); |
| 478 | return NULL; |
| 479 | } |
| 480 | |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 481 | ServiceRefPtr Manager::GetDefaultService() const { |
| 482 | if (services_.empty() || !services_[0]->connection().get()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 483 | SLOG(Manager, 2) << "In " << __func__ << ": No default connection exists."; |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 484 | return NULL; |
| 485 | } |
| 486 | return services_[0]; |
| 487 | } |
| 488 | |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 489 | bool Manager::IsPortalDetectionEnabled(Technology::Identifier tech) { |
| 490 | Error error; |
| 491 | vector<Technology::Identifier> portal_technologies; |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 492 | return Technology::GetTechnologyVectorFromString(GetCheckPortalList(NULL), |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 493 | &portal_technologies, |
| 494 | &error) && |
| 495 | std::find(portal_technologies.begin(), portal_technologies.end(), |
| 496 | tech) != portal_technologies.end(); |
| 497 | } |
| 498 | |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 499 | void Manager::SetStartupPortalList(const string &portal_list) { |
| 500 | startup_portal_list_ = portal_list; |
| 501 | use_startup_portal_list_ = true; |
| 502 | } |
| 503 | |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 504 | bool Manager::IsServiceEphemeral(const ServiceConstRefPtr &service) const { |
| 505 | return service->profile() == ephemeral_profile_; |
| 506 | } |
| 507 | |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 508 | const ProfileRefPtr &Manager::ActiveProfile() const { |
Eric Shienbrood | c74cf9c | 2012-03-02 15:00:35 -0500 | [diff] [blame] | 509 | DCHECK_NE(profiles_.size(), 0U); |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 510 | return profiles_.back(); |
| 511 | } |
| 512 | |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 513 | bool Manager::IsActiveProfile(const ProfileRefPtr &profile) const { |
| 514 | return (profiles_.size() > 0 && |
| 515 | ActiveProfile().get() == profile.get()); |
| 516 | } |
| 517 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 518 | void Manager::SaveActiveProfile() { |
| 519 | if (!profiles_.empty()) { |
| 520 | ActiveProfile()->Save(); |
| 521 | } |
| 522 | } |
| 523 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 524 | bool Manager::MoveServiceToProfile(const ServiceRefPtr &to_move, |
| 525 | const ProfileRefPtr &destination) { |
| 526 | const ProfileRefPtr from = to_move->profile(); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 527 | SLOG(Manager, 2) << "Moving service " |
| 528 | << to_move->UniqueName() |
| 529 | << " to profile " |
| 530 | << destination->GetFriendlyName() |
| 531 | << " from " |
| 532 | << from->GetFriendlyName(); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 533 | return destination->AdoptService(to_move) && |
| 534 | from->AbandonService(to_move); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 537 | ProfileRefPtr Manager::LookupProfileByRpcIdentifier( |
| 538 | const string &profile_rpcid) { |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 539 | for (vector<ProfileRefPtr>::iterator it = profiles_.begin(); |
| 540 | it != profiles_.end(); |
| 541 | ++it) { |
| 542 | if (profile_rpcid == (*it)->GetRpcIdentifier()) { |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 543 | return *it; |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 544 | } |
| 545 | } |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 546 | return NULL; |
| 547 | } |
| 548 | |
| 549 | void Manager::SetProfileForService(const ServiceRefPtr &to_set, |
| 550 | const string &profile_rpcid, |
| 551 | Error *error) { |
| 552 | ProfileRefPtr profile = LookupProfileByRpcIdentifier(profile_rpcid); |
| 553 | if (!profile) { |
| 554 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 555 | StringPrintf("Unknown Profile %s requested for " |
| 556 | "Service", profile_rpcid.c_str())); |
| 557 | return; |
| 558 | } |
| 559 | |
| 560 | if (to_set->profile().get() == profile.get()) { |
| 561 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 562 | "Service is already connected to this profile"); |
| 563 | } else if (!MoveServiceToProfile(to_set, profile)) { |
| 564 | Error::PopulateAndLog(error, Error::kInternalError, |
| 565 | "Unable to move service to profile"); |
| 566 | } |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 567 | } |
| 568 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 569 | void Manager::EnableTechnology(const std::string &technology_name, |
| 570 | Error *error, |
| 571 | const ResultCallback &callback) { |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 572 | CHECK(error != NULL); |
| 573 | DCHECK(error->IsOngoing()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 574 | Technology::Identifier id = Technology::IdentifierFromName(technology_name); |
| 575 | if (id == Technology::kUnknown) { |
| 576 | error->Populate(Error::kInvalidArguments, "Unknown technology"); |
| 577 | return; |
| 578 | } |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 579 | bool deferred = false; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 580 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 581 | it != devices_.end(); ++it) { |
| 582 | DeviceRefPtr device = *it; |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 583 | if (device->TechnologyIs(id) && !device->enabled()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 584 | device->SetEnabledPersistent(true, error, callback); |
| 585 | // Continue with other devices even if one fails |
| 586 | // TODO(ers): Decide whether an error should be returned |
| 587 | // for the overall EnableTechnology operation if some |
| 588 | // devices succeed and some fail. |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 589 | if (error->IsOngoing()) |
| 590 | deferred = true; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 591 | } |
| 592 | } |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 593 | // If no device has deferred work, then clear the error to |
| 594 | // communicate to the caller that all work is done. |
| 595 | if (!deferred) |
| 596 | error->Reset(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | void Manager::DisableTechnology(const std::string &technology_name, |
| 600 | Error *error, |
| 601 | const ResultCallback &callback) { |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 602 | CHECK(error != NULL); |
| 603 | DCHECK(error->IsOngoing()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 604 | Technology::Identifier id = Technology::IdentifierFromName(technology_name); |
| 605 | if (id == Technology::kUnknown) { |
| 606 | error->Populate(Error::kInvalidArguments, "Unknown technology"); |
| 607 | return; |
| 608 | } |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 609 | bool deferred = false; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 610 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 611 | it != devices_.end(); ++it) { |
| 612 | DeviceRefPtr device = *it; |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 613 | if (device->TechnologyIs(id) && device->enabled()) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 614 | device->SetEnabledPersistent(false, error, callback); |
| 615 | // Continue with other devices even if one fails |
| 616 | // TODO(ers): Decide whether an error should be returned |
| 617 | // for the overall DisableTechnology operation if some |
| 618 | // devices succeed and some fail. |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 619 | if (error->IsOngoing()) |
| 620 | deferred = true; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 621 | } |
| 622 | } |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 623 | // If no device has deferred work, then clear the error to |
| 624 | // communicate to the caller that all work is done. |
| 625 | if (!deferred) |
| 626 | error->Reset(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | void Manager::UpdateEnabledTechnologies() { |
| 630 | Error error; |
| 631 | adaptor_->EmitStringsChanged(flimflam::kEnabledTechnologiesProperty, |
| 632 | EnabledTechnologies(&error)); |
| 633 | } |
| 634 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 635 | void Manager::RegisterDevice(const DeviceRefPtr &to_manage) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 636 | SLOG(Manager, 2) << __func__ << "(" << to_manage->FriendlyName() << ")"; |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 637 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 638 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 639 | if (to_manage.get() == it->get()) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 640 | return; |
| 641 | } |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 642 | devices_.push_back(to_manage); |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 643 | |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 644 | // We are applying device properties from the DefaultProfile, and adding |
| 645 | // the union of hidden services in all loaded profiles to the device. |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 646 | for (vector<ProfileRefPtr>::iterator it = profiles_.begin(); |
| 647 | it != profiles_.end(); |
| 648 | ++it) { |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 649 | // Load device configuration, if any exists, as well as hidden services. |
| 650 | (*it)->ConfigureDevice(to_manage); |
| 651 | |
| 652 | // Currently the only profile for which "Save" is implemented is the |
| 653 | // DefaultProfile. It iterates over all Devices and stores their state. |
| 654 | // We perform the Save now in case the device we have just registered |
| 655 | // is new and needs to be added to the stored DefaultProfile. |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 656 | (*it)->Save(); |
| 657 | } |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 658 | |
| 659 | // In normal usage, running_ will always be true when we are here, however |
| 660 | // unit tests sometimes do things in otherwise invalid states. |
Eric Shienbrood | 7fce52c | 2012-04-13 19:11:02 -0400 | [diff] [blame] | 661 | if (running_ && (to_manage->enabled_persistent() || |
| 662 | to_manage->IsUnderlyingDeviceEnabled())) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 663 | to_manage->SetEnabled(true); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 664 | |
Eric Shienbrood | 8839a89 | 2012-03-29 10:33:48 -0400 | [diff] [blame] | 665 | EmitDeviceProperties(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 666 | } |
| 667 | |
mukesh agrawal | 5029c6c | 2011-08-25 11:12:40 -0700 | [diff] [blame] | 668 | void Manager::DeregisterDevice(const DeviceRefPtr &to_forget) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 669 | SLOG(Manager, 2) << __func__ << "(" << to_forget->FriendlyName() << ")"; |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 670 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 671 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 672 | if (to_forget.get() == it->get()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 673 | SLOG(Manager, 2) << "Deregistered device: " << to_forget->UniqueName(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 674 | to_forget->SetEnabled(false); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 675 | devices_.erase(it); |
Eric Shienbrood | 8839a89 | 2012-03-29 10:33:48 -0400 | [diff] [blame] | 676 | EmitDeviceProperties(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 677 | return; |
| 678 | } |
| 679 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 680 | SLOG(Manager, 2) << __func__ << " unknown device: " |
| 681 | << to_forget->UniqueName(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Eric Shienbrood | 8839a89 | 2012-03-29 10:33:48 -0400 | [diff] [blame] | 684 | void Manager::EmitDeviceProperties() { |
| 685 | vector<DeviceRefPtr>::iterator it; |
| 686 | vector<string> device_paths; |
| 687 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
| 688 | device_paths.push_back((*it)->GetRpcIdentifier()); |
| 689 | } |
| 690 | adaptor_->EmitRpcIdentifierArrayChanged(flimflam::kDevicesProperty, |
| 691 | device_paths); |
| 692 | Error error; |
| 693 | adaptor_->EmitStringsChanged(flimflam::kAvailableTechnologiesProperty, |
| 694 | AvailableTechnologies(&error)); |
| 695 | adaptor_->EmitStringsChanged(flimflam::kEnabledTechnologiesProperty, |
| 696 | EnabledTechnologies(&error)); |
| 697 | } |
| 698 | |
mukesh agrawal | 4eb4d78 | 2011-12-05 17:34:37 +0000 | [diff] [blame] | 699 | bool Manager::HasService(const ServiceRefPtr &service) { |
| 700 | vector<ServiceRefPtr>::iterator it; |
| 701 | for (it = services_.begin(); it != services_.end(); ++it) { |
| 702 | if ((*it)->UniqueName() == service->UniqueName()) |
| 703 | return true; |
| 704 | } |
| 705 | return false; |
| 706 | } |
| 707 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 708 | void Manager::RegisterService(const ServiceRefPtr &to_manage) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 709 | SLOG(Manager, 2) << "In " << __func__ << "(): Registering service " |
| 710 | << to_manage->UniqueName(); |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 711 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 712 | MatchProfileWithService(to_manage); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 713 | |
| 714 | // Now add to OUR list. |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 715 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 716 | for (it = services_.begin(); it != services_.end(); ++it) { |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 717 | CHECK(to_manage->UniqueName() != (*it)->UniqueName()); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 718 | } |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 719 | services_.push_back(to_manage); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 720 | SortServices(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 723 | void Manager::DeregisterService(const ServiceRefPtr &to_forget) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 724 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 725 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 726 | if (to_forget->UniqueName() == (*it)->UniqueName()) { |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 727 | DCHECK(!(*it)->connection()); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 728 | services_.erase(it); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 729 | SortServices(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 730 | return; |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 735 | bool Manager::UnloadService(vector<ServiceRefPtr>::iterator *service_iterator) { |
| 736 | if (!(**service_iterator)->Unload()) { |
| 737 | return false; |
| 738 | } |
| 739 | |
| 740 | DCHECK(!(**service_iterator)->connection()); |
| 741 | *service_iterator = services_.erase(*service_iterator); |
| 742 | |
| 743 | return true; |
| 744 | } |
| 745 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 746 | void Manager::UpdateService(const ServiceRefPtr &to_update) { |
| 747 | CHECK(to_update); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 748 | LOG(INFO) << "Service " << to_update->UniqueName() << " updated;" |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 749 | << " state: " << Service::ConnectStateToString(to_update->state()) |
| 750 | << " failure: " |
| 751 | << Service::ConnectFailureToString(to_update->failure()); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 752 | SLOG(Manager, 2) << "IsConnected(): " << to_update->IsConnected(); |
| 753 | SLOG(Manager, 2) << "IsConnecting(): " << to_update->IsConnecting(); |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 754 | if (to_update->IsConnected()) { |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 755 | to_update->MakeFavorite(); |
Gary Morain | d93615e | 2012-04-27 11:50:03 -0700 | [diff] [blame] | 756 | // Persists the updated favorite setting in the profile. |
| 757 | SaveServiceToProfile(to_update); |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 758 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 759 | SortServices(); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Gary Morain | d93615e | 2012-04-27 11:50:03 -0700 | [diff] [blame] | 762 | void Manager::SaveServiceToProfile(const ServiceRefPtr &to_update) { |
| 763 | if (IsServiceEphemeral(to_update)) { |
| 764 | if (profiles_.empty()) { |
| 765 | LOG(ERROR) << "Cannot assign profile to service: no profiles exist!"; |
| 766 | } else { |
| 767 | MoveServiceToProfile(to_update, profiles_.back()); |
| 768 | } |
| 769 | } else { |
| 770 | to_update->profile()->UpdateService(to_update); |
| 771 | } |
| 772 | } |
| 773 | |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 774 | void Manager::FilterByTechnology(Technology::Identifier tech, |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 775 | vector<DeviceRefPtr> *found) { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 776 | CHECK(found); |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 777 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 778 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
| 779 | if ((*it)->TechnologyIs(tech)) |
| 780 | found->push_back(*it); |
| 781 | } |
| 782 | } |
| 783 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 784 | ServiceRefPtr Manager::FindService(const string& name) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 785 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 786 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 787 | if (name == (*it)->UniqueName()) |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 788 | return *it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 789 | } |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 790 | return NULL; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 791 | } |
| 792 | |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 793 | void Manager::HelpRegisterConstDerivedRpcIdentifiers( |
| 794 | const string &name, |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 795 | RpcIdentifiers(Manager::*get)(Error *error)) { |
mukesh agrawal | 2366eed | 2012-03-20 18:21:50 -0700 | [diff] [blame] | 796 | store_.RegisterDerivedRpcIdentifiers( |
| 797 | name, |
| 798 | RpcIdentifiersAccessor( |
| 799 | new CustomAccessor<Manager, RpcIdentifiers>(this, get, NULL))); |
| 800 | } |
| 801 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 802 | void Manager::HelpRegisterDerivedString( |
| 803 | const string &name, |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 804 | string(Manager::*get)(Error *), |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 805 | void(Manager::*set)(const string&, Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 806 | store_.RegisterDerivedString( |
| 807 | name, |
| 808 | StringAccessor(new CustomAccessor<Manager, string>(this, get, set))); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 809 | } |
| 810 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 811 | void Manager::HelpRegisterDerivedStrings( |
| 812 | const string &name, |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 813 | Strings(Manager::*get)(Error *), |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 814 | void(Manager::*set)(const Strings &, Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 815 | store_.RegisterDerivedStrings( |
| 816 | name, |
| 817 | StringsAccessor(new CustomAccessor<Manager, Strings>(this, get, set))); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 820 | void Manager::SortServices() { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 821 | SLOG(Manager, 4) << "In " << __func__; |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 822 | ServiceRefPtr default_service; |
| 823 | |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 824 | if (!services_.empty()) { |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 825 | // Keep track of the service that is the candidate for the default |
| 826 | // service. We have not yet tested to see if this service has a |
| 827 | // connection. |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 828 | default_service = services_[0]; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 829 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 830 | sort(services_.begin(), services_.end(), ServiceSorter(technology_order_)); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 831 | |
| 832 | vector<string> service_paths; |
| 833 | vector<ServiceRefPtr>::iterator it; |
| 834 | for (it = services_.begin(); it != services_.end(); ++it) { |
| 835 | if ((*it)->IsVisible()) { |
| 836 | service_paths.push_back((*it)->GetRpcIdentifier()); |
| 837 | } |
| 838 | } |
| 839 | adaptor_->EmitRpcIdentifierArrayChanged(flimflam::kServicesProperty, |
| 840 | service_paths); |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 841 | |
| 842 | Error error; |
| 843 | adaptor_->EmitStringsChanged(flimflam::kConnectedTechnologiesProperty, |
| 844 | ConnectedTechnologies(&error)); |
| 845 | adaptor_->EmitStringChanged(flimflam::kDefaultTechnologyProperty, |
| 846 | DefaultTechnology(&error)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 847 | |
| 848 | if (!services_.empty()) { |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 849 | ConnectionRefPtr default_connection = default_service->connection(); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 850 | if (default_connection.get() && |
| 851 | (services_[0]->connection().get() != default_connection.get())) { |
| 852 | default_connection->SetIsDefault(false); |
| 853 | } |
| 854 | if (services_[0]->connection().get()) { |
| 855 | services_[0]->connection()->SetIsDefault(true); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 856 | default_service = services_[0]; |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 857 | } else { |
| 858 | default_service = NULL; |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 859 | } |
| 860 | } |
Paul Stewart | e2bad7c | 2012-03-14 08:55:33 -0700 | [diff] [blame] | 861 | metrics_->NotifyDefaultServiceChanged(default_service); |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 862 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 863 | AutoConnect(); |
| 864 | } |
| 865 | |
Paul Stewart | 7522551 | 2012-01-26 22:51:33 -0800 | [diff] [blame] | 866 | bool Manager::MatchProfileWithService(const ServiceRefPtr &service) { |
| 867 | vector<ProfileRefPtr>::reverse_iterator it; |
| 868 | for (it = profiles_.rbegin(); it != profiles_.rend(); ++it) { |
| 869 | if ((*it)->ConfigureService(service)) { |
| 870 | break; |
| 871 | } |
| 872 | } |
| 873 | if (it == profiles_.rend()) { |
| 874 | ephemeral_profile_->AdoptService(service); |
| 875 | return false; |
| 876 | } |
| 877 | return true; |
| 878 | } |
| 879 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 880 | void Manager::AutoConnect() { |
| 881 | // We might be called in the middle of another request (e.g., as a |
| 882 | // consequence of Service::SetState calling UpdateService). To avoid |
| 883 | // re-entrancy issues in dbus-c++, defer to the event loop. |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 884 | dispatcher_->PostTask(Bind(&Manager::AutoConnectTask, AsWeakPtr())); |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | void Manager::AutoConnectTask() { |
| 888 | if (services_.empty()) { |
| 889 | LOG(INFO) << "No services."; |
| 890 | return; |
| 891 | } |
| 892 | |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 893 | if (SLOG_IS_ON(Manager, 4)) { |
| 894 | SLOG(Manager, 4) << "Sorted service list: "; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 895 | for (size_t i = 0; i < services_.size(); ++i) { |
| 896 | ServiceRefPtr service = services_[i]; |
| 897 | const char *compare_reason = NULL; |
| 898 | if (i + 1 < services_.size()) { |
| 899 | Service::Compare( |
| 900 | service, services_[i+1], technology_order_, &compare_reason); |
| 901 | } else { |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 902 | compare_reason = "last"; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 903 | } |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 904 | SLOG(Manager, 4) << "Service " << service->friendly_name() |
| 905 | << " IsConnected: " << service->IsConnected() |
| 906 | << " IsConnecting: " << service->IsConnecting() |
| 907 | << " IsFailed: " << service->IsFailed() |
| 908 | << " connectable: " << service->connectable() |
| 909 | << " auto_connect: " << service->auto_connect() |
| 910 | << " favorite: " << service->favorite() |
| 911 | << " priority: " << service->priority() |
| 912 | << " security_level: " << service->security_level() |
| 913 | << " strength: " << service->strength() |
| 914 | << " UniqueName: " << service->UniqueName() |
| 915 | << " sorted: " << compare_reason; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 919 | // Perform auto-connect. |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 920 | for (vector<ServiceRefPtr>::iterator it = services_.begin(); |
| 921 | it != services_.end(); ++it) { |
| 922 | if ((*it)->auto_connect()) { |
mukesh agrawal | 592516d | 2012-01-12 14:01:00 -0800 | [diff] [blame] | 923 | LOG(INFO) << "Requesting autoconnect to service " |
| 924 | << (*it)->friendly_name() << "."; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 925 | (*it)->AutoConnect(); |
Paul Stewart | 3d9bcf5 | 2011-12-12 15:02:22 -0800 | [diff] [blame] | 926 | } |
| 927 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 930 | string Manager::CalculateState(Error */*error*/) { |
Gary Morain | 028545d | 2012-04-07 14:55:52 -0700 | [diff] [blame] | 931 | // |services_| is sorted such that connected services are first. |
| 932 | if (!services_.empty() && |
| 933 | services_.front()->IsConnected()) { |
| 934 | return flimflam::kStateOnline; |
| 935 | } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 936 | return flimflam::kStateOffline; |
| 937 | } |
| 938 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 939 | vector<string> Manager::AvailableTechnologies(Error */*error*/) { |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 940 | set<string> unique_technologies; |
| 941 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 942 | it != devices_.end(); ++it) { |
| 943 | unique_technologies.insert( |
| 944 | Technology::NameFromIdentifier((*it)->technology())); |
| 945 | } |
| 946 | return vector<string>(unique_technologies.begin(), unique_technologies.end()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 949 | vector<string> Manager::ConnectedTechnologies(Error */*error*/) { |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 950 | set<string> unique_technologies; |
| 951 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 952 | it != devices_.end(); ++it) { |
| 953 | if ((*it)->IsConnected()) |
| 954 | unique_technologies.insert( |
| 955 | Technology::NameFromIdentifier((*it)->technology())); |
| 956 | } |
| 957 | return vector<string>(unique_technologies.begin(), unique_technologies.end()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 960 | string Manager::DefaultTechnology(Error *error) { |
| 961 | return (!services_.empty() && services_[0]->IsConnected()) ? |
| 962 | services_[0]->GetTechnologyString(error) : ""; |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 965 | vector<string> Manager::EnabledTechnologies(Error */*error*/) { |
| 966 | set<string> unique_technologies; |
| 967 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 968 | it != devices_.end(); ++it) { |
| 969 | if ((*it)->enabled()) |
| 970 | unique_technologies.insert( |
| 971 | Technology::NameFromIdentifier((*it)->technology())); |
| 972 | } |
| 973 | return vector<string>(unique_technologies.begin(), unique_technologies.end()); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 976 | vector<string> Manager::EnumerateDevices(Error */*error*/) { |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 977 | vector<string> device_rpc_ids; |
| 978 | for (vector<DeviceRefPtr>::const_iterator it = devices_.begin(); |
| 979 | it != devices_.end(); |
| 980 | ++it) { |
| 981 | device_rpc_ids.push_back((*it)->GetRpcIdentifier()); |
| 982 | } |
| 983 | return device_rpc_ids; |
| 984 | } |
| 985 | |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 986 | vector<string> Manager::EnumerateProfiles(Error */*error*/) { |
| 987 | vector<string> profile_rpc_ids; |
| 988 | for (vector<ProfileRefPtr>::const_iterator it = profiles_.begin(); |
| 989 | it != profiles_.end(); |
| 990 | ++it) { |
| 991 | profile_rpc_ids.push_back((*it)->GetRpcIdentifier()); |
| 992 | } |
| 993 | return profile_rpc_ids; |
| 994 | } |
| 995 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 996 | vector<string> Manager::EnumerateAvailableServices(Error */*error*/) { |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 997 | vector<string> service_rpc_ids; |
| 998 | for (vector<ServiceRefPtr>::const_iterator it = services_.begin(); |
| 999 | it != services_.end(); |
| 1000 | ++it) { |
| 1001 | service_rpc_ids.push_back((*it)->GetRpcIdentifier()); |
| 1002 | } |
| 1003 | return service_rpc_ids; |
| 1004 | } |
| 1005 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 1006 | vector<string> Manager::EnumerateWatchedServices(Error *error) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 1007 | // TODO(cmasone): Filter this list for services in appropriate states. |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 1008 | return EnumerateAvailableServices(error); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Paul Stewart | 1b25314 | 2012-01-26 14:05:52 -0800 | [diff] [blame] | 1011 | string Manager::GetActiveProfileRpcIdentifier(Error */*error*/) { |
| 1012 | return ActiveProfile()->GetRpcIdentifier(); |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 1015 | string Manager::GetCheckPortalList(Error */*error*/) { |
Jason Glasgow | df7c553 | 2012-05-14 14:41:45 -0400 | [diff] [blame] | 1016 | return use_startup_portal_list_ ? startup_portal_list_ : |
| 1017 | props_.check_portal_list; |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | void Manager::SetCheckPortalList(const string &portal_list, Error *error) { |
| 1021 | props_.check_portal_list = portal_list; |
| 1022 | use_startup_portal_list_ = false; |
| 1023 | } |
| 1024 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1025 | // called via RPC (e.g., from ManagerDBusAdaptor) |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1026 | ServiceRefPtr Manager::GetService(const KeyValueStore &args, Error *error) { |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1027 | if (args.ContainsString(flimflam::kGuidProperty)) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1028 | SLOG(Manager, 2) << __func__ << ": searching by GUID"; |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1029 | ServiceRefPtr service = |
| 1030 | GetServiceWithGUID(args.GetString(flimflam::kGuidProperty), NULL); |
| 1031 | if (service) { |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1032 | service->Configure(args, error); |
Paul Stewart | 13ed225 | 2012-03-21 12:52:46 -0700 | [diff] [blame] | 1033 | return service; |
| 1034 | } |
| 1035 | } |
| 1036 | |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1037 | if (!args.ContainsString(flimflam::kTypeProperty)) { |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1038 | Error::PopulateAndLog(error, Error::kInvalidArguments, kErrorTypeRequired); |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1039 | return NULL; |
| 1040 | } |
| 1041 | |
| 1042 | string type = args.GetString(flimflam::kTypeProperty); |
| 1043 | if (type == flimflam::kTypeWifi) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1044 | SLOG(Manager, 2) << __func__ << ": getting WiFi Service"; |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1045 | return GetWifiService(args, error); |
| 1046 | } |
| 1047 | if (type == flimflam::kTypeVPN) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1048 | SLOG(Manager, 2) << __func__ << ": getting VPN Service"; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 1049 | return vpn_provider_.GetService(args, error); |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1050 | } |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 1051 | Error::PopulateAndLog(error, Error::kNotSupported, |
| 1052 | kErrorUnsupportedServiceType); |
Darin Petkov | b65c245 | 2012-02-23 15:17:06 +0100 | [diff] [blame] | 1053 | return NULL; |
| 1054 | } |
| 1055 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1056 | WiFiServiceRefPtr Manager::GetWifiService(const KeyValueStore &args, |
| 1057 | Error *error) { |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 1058 | vector<DeviceRefPtr> wifi_devices; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1059 | FilterByTechnology(Technology::kWifi, &wifi_devices); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1060 | if (wifi_devices.empty()) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 1061 | Error::PopulateAndLog(error, Error::kInvalidArguments, kErrorNoDevice); |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1062 | return NULL; |
| 1063 | } else { |
| 1064 | WiFi *wifi = dynamic_cast<WiFi *>(wifi_devices.front().get()); |
| 1065 | CHECK(wifi); |
| 1066 | return wifi->GetService(args, error); |
| 1067 | } |
| 1068 | } |
| 1069 | |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1070 | // called via RPC (e.g., from ManagerDBusAdaptor) |
| 1071 | void Manager::ConfigureService(const KeyValueStore &args, Error *error) { |
| 1072 | ProfileRefPtr profile = ActiveProfile(); |
| 1073 | bool profile_specified = args.ContainsString(flimflam::kProfileProperty); |
| 1074 | if (profile_specified) { |
| 1075 | string profile_rpcid = args.GetString(flimflam::kProfileProperty); |
| 1076 | profile = LookupProfileByRpcIdentifier(profile_rpcid); |
| 1077 | if (!profile) { |
| 1078 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 1079 | "Invalid profile name " + profile_rpcid); |
| 1080 | return; |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | ServiceRefPtr service = GetService(args, error); |
| 1085 | if (error->IsFailure() || !service) { |
| 1086 | LOG(ERROR) << "GetService failed; returning upstream error."; |
| 1087 | return; |
| 1088 | } |
| 1089 | |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 1090 | // Overwrite the profile data with the resulting configured service. |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1091 | if (!profile->UpdateService(service)) { |
| 1092 | Error::PopulateAndLog(error, Error::kInternalError, |
| 1093 | "Unable to save service to profile"); |
| 1094 | return; |
| 1095 | } |
| 1096 | |
| 1097 | if (HasService(service)) { |
| 1098 | // If the service has been registered (it may not be -- as is the case |
| 1099 | // with invisible WiFi networks), we can now transfer the service between |
| 1100 | // profiles. |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 1101 | if (IsServiceEphemeral(service) || |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1102 | (profile_specified && service->profile() != profile)) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1103 | SLOG(Manager, 2) << "Moving service to profile " |
| 1104 | << profile->GetFriendlyName(); |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1105 | if (!MoveServiceToProfile(service, profile)) { |
| 1106 | Error::PopulateAndLog(error, Error::kInternalError, |
| 1107 | "Unable to move service to profile"); |
| 1108 | } |
| 1109 | } |
| 1110 | } |
Paul Stewart | 4357f4e | 2012-04-26 17:39:26 -0700 | [diff] [blame] | 1111 | |
| 1112 | // Notify the service that a profile has been configured for it. |
| 1113 | service->OnProfileConfigured(); |
Paul Stewart | 7f61e52 | 2012-03-22 11:13:45 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Paul Stewart | c681fa0 | 2012-03-02 19:40:04 -0800 | [diff] [blame] | 1116 | void Manager::RecheckPortal(Error */*error*/) { |
| 1117 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 1118 | it != devices_.end(); ++it) { |
| 1119 | if ((*it)->RequestPortalDetection()) { |
| 1120 | // Only start Portal Detection on the device with the default connection. |
| 1121 | // We will get a "true" return value when we've found that device, and |
| 1122 | // can end our loop early as a result. |
| 1123 | break; |
| 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1128 | void Manager::RecheckPortalOnService(const ServiceRefPtr &service) { |
| 1129 | for (vector<DeviceRefPtr>::iterator it = devices_.begin(); |
| 1130 | it != devices_.end(); ++it) { |
| 1131 | if ((*it)->IsConnectedToService(service)) { |
| 1132 | // As opposed to RecheckPortal() above, we explicitly stop and then |
| 1133 | // restart portal detection, since the service to recheck was explicitly |
| 1134 | // specified. |
| 1135 | (*it)->RestartPortalDetection(); |
| 1136 | break; |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 1141 | // called via RPC (e.g., from ManagerDBusAdaptor) |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1142 | void Manager::RequestScan(const string &technology, Error *error) { |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1143 | if (technology == flimflam::kTypeWifi || technology == "") { |
| 1144 | vector<DeviceRefPtr> wifi_devices; |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 1145 | FilterByTechnology(Technology::kWifi, &wifi_devices); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1146 | |
| 1147 | for (vector<DeviceRefPtr>::iterator it = wifi_devices.begin(); |
| 1148 | it != wifi_devices.end(); |
| 1149 | ++it) { |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 1150 | (*it)->Scan(error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1151 | } |
| 1152 | } else { |
| 1153 | // TODO(quiche): support scanning for other technologies? |
Paul Stewart | be00517 | 2011-11-02 18:10:29 -0700 | [diff] [blame] | 1154 | Error::PopulateAndLog(error, Error::kInvalidArguments, |
| 1155 | "Unrecognized technology " + technology); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 1156 | } |
| 1157 | } |
| 1158 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1159 | string Manager::GetTechnologyOrder() { |
| 1160 | vector<string> technology_names; |
| 1161 | for (vector<Technology::Identifier>::iterator it = technology_order_.begin(); |
| 1162 | it != technology_order_.end(); |
| 1163 | ++it) { |
| 1164 | technology_names.push_back(Technology::NameFromIdentifier(*it)); |
| 1165 | } |
| 1166 | |
| 1167 | return JoinString(technology_names, ','); |
| 1168 | } |
| 1169 | |
| 1170 | void Manager::SetTechnologyOrder(const string &order, Error *error) { |
| 1171 | vector<Technology::Identifier> new_order; |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 1172 | SLOG(Manager, 2) << "Setting technology order to " << order; |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 1173 | if (!Technology::GetTechnologyVectorFromString(order, &new_order, error)) { |
| 1174 | return; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | technology_order_ = new_order; |
| 1178 | SortServices(); |
| 1179 | } |
| 1180 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 1181 | } // namespace shill |