Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
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 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 10 | #include <map> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 11 | #include <string> |
Chris Masone | 52cd19b | 2011-06-29 17:23:04 -0700 | [diff] [blame] | 12 | #include <vector> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 13 | |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 14 | #include <base/file_util.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 15 | #include <base/logging.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 16 | #include <base/memory/ref_counted.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 17 | #include <chromeos/dbus/service_constants.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 18 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 19 | #include "shill/adaptor_interfaces.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 20 | #include "shill/control_interface.h" |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 21 | #include "shill/dbus_adaptor.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 22 | #include "shill/default_profile.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 23 | #include "shill/device.h" |
| 24 | #include "shill/device_info.h" |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 25 | #include "shill/ephemeral_profile.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 26 | #include "shill/error.h" |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 27 | #include "shill/key_file_store.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 28 | #include "shill/profile.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 29 | #include "shill/property_accessor.h" |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 30 | #include "shill/resolver.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 31 | #include "shill/shill_event.h" |
| 32 | #include "shill/service.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 33 | #include "shill/wifi.h" |
| 34 | #include "shill/wifi_service.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 35 | |
| 36 | using std::string; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 37 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 38 | |
| 39 | namespace shill { |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 40 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 41 | // static |
| 42 | const char Manager::kManagerErrorNoDevice[] = "no wifi devices available"; |
| 43 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 44 | Manager::Manager(ControlInterface *control_interface, |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 45 | EventDispatcher *dispatcher, |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 46 | GLib *glib, |
| 47 | const string &run_directory, |
| 48 | const string &storage_directory, |
| 49 | const string &user_storage_format) |
| 50 | : run_path_(FilePath(run_directory)), |
| 51 | storage_path_(FilePath(storage_directory)), |
| 52 | user_storage_format_(user_storage_format), |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 53 | adaptor_(control_interface->CreateManagerAdaptor(this)), |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 54 | device_info_(control_interface, dispatcher, this), |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 55 | modem_info_(control_interface, dispatcher, this, glib), |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 56 | running_(false), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 57 | ephemeral_profile_(new EphemeralProfile(control_interface, this)), |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 58 | control_interface_(control_interface), |
| 59 | glib_(glib) { |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 60 | HelpRegisterDerivedString(flimflam::kActiveProfileProperty, |
| 61 | &Manager::GetActiveProfileName, |
| 62 | NULL); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 63 | HelpRegisterDerivedStrings(flimflam::kAvailableTechnologiesProperty, |
| 64 | &Manager::AvailableTechnologies, |
| 65 | NULL); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 66 | store_.RegisterString(flimflam::kCheckPortalListProperty, |
| 67 | &props_.check_portal_list); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 68 | HelpRegisterDerivedStrings(flimflam::kConnectedTechnologiesProperty, |
| 69 | &Manager::ConnectedTechnologies, |
| 70 | NULL); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 71 | store_.RegisterString(flimflam::kCountryProperty, &props_.country); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 72 | HelpRegisterDerivedString(flimflam::kDefaultTechnologyProperty, |
| 73 | &Manager::DefaultTechnology, |
| 74 | NULL); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 75 | HelpRegisterDerivedStrings(flimflam::kDevicesProperty, |
| 76 | &Manager::EnumerateDevices, |
| 77 | NULL); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 78 | HelpRegisterDerivedStrings(flimflam::kEnabledTechnologiesProperty, |
| 79 | &Manager::EnabledTechnologies, |
| 80 | NULL); |
| 81 | store_.RegisterBool(flimflam::kOfflineModeProperty, &props_.offline_mode); |
| 82 | store_.RegisterString(flimflam::kPortalURLProperty, &props_.portal_url); |
| 83 | HelpRegisterDerivedString(flimflam::kStateProperty, |
| 84 | &Manager::CalculateState, |
| 85 | NULL); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 86 | HelpRegisterDerivedStrings(flimflam::kServicesProperty, |
| 87 | &Manager::EnumerateAvailableServices, |
| 88 | NULL); |
| 89 | HelpRegisterDerivedStrings(flimflam::kServiceWatchListProperty, |
| 90 | &Manager::EnumerateWatchedServices, |
| 91 | NULL); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 92 | |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 93 | // TODO(cmasone): Wire these up once we actually put in profile support. |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 94 | // known_properties_.push_back(flimflam::kProfilesProperty); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 95 | profiles_.push_back(new DefaultProfile(control_interface_, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 96 | this, |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 97 | storage_path_, |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 98 | props_)); |
Chris Masone | b07006b | 2011-05-14 16:10:04 -0700 | [diff] [blame] | 99 | VLOG(2) << "Manager initialized."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 102 | Manager::~Manager() { |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 103 | profiles_.clear(); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 104 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 105 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 106 | void Manager::AddDeviceToBlackList(const string &device_name) { |
| 107 | device_info_.AddDeviceToBlackList(device_name); |
| 108 | } |
| 109 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 110 | void Manager::Start() { |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 111 | LOG(INFO) << "Manager started."; |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 112 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 113 | CHECK(file_util::CreateDirectory(run_path_)) << run_path_.value(); |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 114 | Resolver::GetInstance()->set_path(run_path_.Append("resolv.conf")); |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 115 | |
| 116 | CHECK(file_util::CreateDirectory(storage_path_)) << storage_path_.value(); |
| 117 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 118 | running_ = true; |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 119 | adaptor_->UpdateRunning(); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 120 | device_info_.Start(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 121 | modem_info_.Start(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void Manager::Stop() { |
| 125 | running_ = false; |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 126 | // Persist profile, device, service information to disk. |
| 127 | vector<ProfileRefPtr>::iterator it; |
| 128 | for (it = profiles_.begin(); it != profiles_.end(); ++it) { |
| 129 | KeyFileStore storage(glib_); |
| 130 | FilePath profile_path; |
| 131 | CHECK((*it)->GetStoragePath(&profile_path)); |
| 132 | storage.set_path(profile_path); |
| 133 | if (storage.Open()) { |
| 134 | (*it)->Finalize(&storage); |
| 135 | storage.Close(); |
| 136 | } else { |
| 137 | LOG(ERROR) << "Could not open storage at " << profile_path.value(); |
| 138 | } |
| 139 | } |
| 140 | ephemeral_profile_->Finalize(NULL); |
| 141 | |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 142 | adaptor_->UpdateRunning(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 143 | modem_info_.Stop(); |
| 144 | device_info_.Stop(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 147 | const ProfileRefPtr &Manager::ActiveProfile() { |
| 148 | return profiles_.back(); |
| 149 | } |
| 150 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 151 | bool Manager::MoveToActiveProfile(const ProfileRefPtr &from, |
| 152 | const ServiceRefPtr &to_move) { |
| 153 | return ActiveProfile()->AdoptService(to_move) && |
| 154 | from->AbandonService(to_move->UniqueName()); |
| 155 | } |
| 156 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 157 | void Manager::RegisterDevice(const DeviceRefPtr &to_manage) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 158 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 159 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 160 | if (to_manage.get() == it->get()) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 161 | return; |
| 162 | } |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 163 | devices_.push_back(to_manage); |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 164 | |
| 165 | // TODO(pstew): Should check configuration |
| 166 | if (running_) |
| 167 | to_manage->Start(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 168 | } |
| 169 | |
mukesh agrawal | 5029c6c | 2011-08-25 11:12:40 -0700 | [diff] [blame] | 170 | void Manager::DeregisterDevice(const DeviceRefPtr &to_forget) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 171 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 172 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 173 | if (to_forget.get() == it->get()) { |
mukesh agrawal | 5029c6c | 2011-08-25 11:12:40 -0700 | [diff] [blame] | 174 | VLOG(2) << "Deregistered device: " << to_forget->UniqueName(); |
| 175 | to_forget->Stop(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 176 | devices_.erase(it); |
| 177 | return; |
| 178 | } |
| 179 | } |
mukesh agrawal | 5029c6c | 2011-08-25 11:12:40 -0700 | [diff] [blame] | 180 | VLOG(2) << __func__ << " unknown device: " << to_forget->UniqueName(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 183 | void Manager::RegisterService(const ServiceRefPtr &to_manage) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 184 | // This should look for |to_manage| in the real profiles and, if found, |
| 185 | // do...something...to merge the meaningful state, I guess. |
| 186 | |
| 187 | // If not found, add it to the ephemeral profile |
| 188 | ephemeral_profile_->AdoptService(to_manage); |
| 189 | |
| 190 | // Now add to OUR list. |
| 191 | // TODO(cmasone): Keep this list sorted. |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 192 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 193 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 194 | if (to_manage->UniqueName() == (*it)->UniqueName()) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 195 | return; |
| 196 | } |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 197 | services_.push_back(to_manage); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 198 | |
| 199 | vector<string> service_paths; |
| 200 | for (it = services_.begin(); it != services_.end(); ++it) { |
| 201 | service_paths.push_back((*it)->GetRpcIdentifier()); |
| 202 | } |
| 203 | adaptor_->EmitRpcIdentifierArrayChanged(flimflam::kServicesProperty, |
| 204 | service_paths); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 207 | void Manager::DeregisterService(const ServiceConstRefPtr &to_forget) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 208 | // If the service is in the ephemeral profile, destroy it. |
| 209 | if (!ephemeral_profile_->AbandonService(to_forget->UniqueName())) { |
| 210 | // if it's in one of the real profiles...um...I guess mark it unconnectable? |
| 211 | } |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 212 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 213 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 214 | if (to_forget->UniqueName() == (*it)->UniqueName()) { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 215 | services_.erase(it); |
| 216 | return; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 221 | void Manager::UpdateService(const ServiceConstRefPtr &to_update) { |
| 222 | LOG(INFO) << "Service " << to_update->UniqueName() << " updated;" |
| 223 | << " state: " << to_update->state() << " failure: " |
| 224 | << to_update->failure(); |
| 225 | // TODO(pstew): This should trigger re-sorting of services, autoconnect, etc. |
| 226 | } |
| 227 | |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame^] | 228 | void Manager::FilterByTechnology(Technology::Identifier tech, |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 229 | vector<DeviceRefPtr> *found) { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 230 | CHECK(found); |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 231 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 232 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
| 233 | if ((*it)->TechnologyIs(tech)) |
| 234 | found->push_back(*it); |
| 235 | } |
| 236 | } |
| 237 | |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 238 | ServiceRefPtr Manager::FindService(const std::string& name) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 239 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 240 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 241 | if (name == (*it)->UniqueName()) |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 242 | return *it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 243 | } |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 244 | return NULL; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 247 | void Manager::HelpRegisterDerivedString(const string &name, |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 248 | string(Manager::*get)(void), |
| 249 | bool(Manager::*set)(const string&)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 250 | store_.RegisterDerivedString( |
| 251 | name, |
| 252 | StringAccessor(new CustomAccessor<Manager, string>(this, get, set))); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 255 | void Manager::HelpRegisterDerivedStrings(const string &name, |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 256 | Strings(Manager::*get)(void), |
| 257 | bool(Manager::*set)(const Strings&)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 258 | store_.RegisterDerivedStrings( |
| 259 | name, |
| 260 | StringsAccessor(new CustomAccessor<Manager, Strings>(this, get, set))); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | string Manager::CalculateState() { |
| 264 | return flimflam::kStateOffline; |
| 265 | } |
| 266 | |
| 267 | vector<string> Manager::AvailableTechnologies() { |
| 268 | return vector<string>(); |
| 269 | } |
| 270 | |
| 271 | vector<string> Manager::ConnectedTechnologies() { |
| 272 | return vector<string>(); |
| 273 | } |
| 274 | |
| 275 | string Manager::DefaultTechnology() { |
| 276 | return ""; |
| 277 | } |
| 278 | |
| 279 | vector<string> Manager::EnabledTechnologies() { |
| 280 | return vector<string>(); |
| 281 | } |
| 282 | |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 283 | vector<string> Manager::EnumerateDevices() { |
| 284 | vector<string> device_rpc_ids; |
| 285 | for (vector<DeviceRefPtr>::const_iterator it = devices_.begin(); |
| 286 | it != devices_.end(); |
| 287 | ++it) { |
| 288 | device_rpc_ids.push_back((*it)->GetRpcIdentifier()); |
| 289 | } |
| 290 | return device_rpc_ids; |
| 291 | } |
| 292 | |
| 293 | vector<string> Manager::EnumerateAvailableServices() { |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 294 | vector<string> service_rpc_ids; |
| 295 | for (vector<ServiceRefPtr>::const_iterator it = services_.begin(); |
| 296 | it != services_.end(); |
| 297 | ++it) { |
| 298 | service_rpc_ids.push_back((*it)->GetRpcIdentifier()); |
| 299 | } |
| 300 | return service_rpc_ids; |
| 301 | } |
| 302 | |
| 303 | vector<string> Manager::EnumerateWatchedServices() { |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 304 | // TODO(cmasone): Filter this list for services in appropriate states. |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 305 | return EnumerateAvailableServices(); |
| 306 | } |
| 307 | |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 308 | string Manager::GetActiveProfileName() { |
Chris Masone | 7df0c67 | 2011-07-15 10:24:54 -0700 | [diff] [blame] | 309 | return ActiveProfile()->GetFriendlyName(); |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 310 | } |
| 311 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 312 | // called via RPC (e.g., from ManagerDBusAdaptor) |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 313 | WiFiServiceRefPtr Manager::GetWifiService(const KeyValueStore &args, |
| 314 | Error *error) { |
| 315 | std::vector<DeviceRefPtr> wifi_devices; |
| 316 | FilterByTechnology(Device::kWifi, &wifi_devices); |
| 317 | if (wifi_devices.empty()) { |
| 318 | error->Populate(Error::kInvalidArguments, kManagerErrorNoDevice); |
| 319 | return NULL; |
| 320 | } else { |
| 321 | WiFi *wifi = dynamic_cast<WiFi *>(wifi_devices.front().get()); |
| 322 | CHECK(wifi); |
| 323 | return wifi->GetService(args, error); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // called via RPC (e.g., from ManagerDBusAdaptor) |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 328 | void Manager::RequestScan(const std::string &technology, Error *error) { |
| 329 | if (technology == flimflam::kTypeWifi || technology == "") { |
| 330 | vector<DeviceRefPtr> wifi_devices; |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame^] | 331 | FilterByTechnology(Technology::kWifi, &wifi_devices); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 332 | |
| 333 | for (vector<DeviceRefPtr>::iterator it = wifi_devices.begin(); |
| 334 | it != wifi_devices.end(); |
| 335 | ++it) { |
Darin Petkov | c086531 | 2011-09-16 15:31:20 -0700 | [diff] [blame] | 336 | (*it)->Scan(error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 337 | } |
| 338 | } else { |
| 339 | // TODO(quiche): support scanning for other technologies? |
| 340 | const string kMessage = "Unrecognized technology " + technology; |
| 341 | LOG(ERROR) << kMessage; |
| 342 | CHECK(error); |
| 343 | error->Populate(Error::kInvalidArguments, kMessage); |
| 344 | } |
| 345 | } |
| 346 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 347 | } // namespace shill |