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