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> |
| 11 | |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 12 | #include <base/logging.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 13 | #include <base/memory/ref_counted.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 14 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 15 | #include "shill/adaptor_interfaces.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 16 | #include "shill/control_interface.h" |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 17 | #include "shill/dbus_adaptor.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 18 | #include "shill/device.h" |
| 19 | #include "shill/device_info.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 20 | #include "shill/error.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 21 | #include "shill/shill_event.h" |
| 22 | #include "shill/service.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 23 | |
| 24 | using std::string; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 25 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 26 | |
| 27 | namespace shill { |
| 28 | Manager::Manager(ControlInterface *control_interface, |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 29 | EventDispatcher *dispatcher) |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 30 | : adaptor_(control_interface->CreateManagerAdaptor(this)), |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 31 | device_info_(control_interface, dispatcher, this), |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 32 | running_(false) { |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 33 | // Initialize Interface monitor, so we can detect new interfaces |
Chris Masone | b07006b | 2011-05-14 16:10:04 -0700 | [diff] [blame] | 34 | VLOG(2) << "Manager initialized."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 37 | Manager::~Manager() {} |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 38 | |
| 39 | void Manager::Start() { |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 40 | LOG(INFO) << "Manager started."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 41 | running_ = true; |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 42 | adaptor_->UpdateRunning(); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 43 | device_info_.Start(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void Manager::Stop() { |
| 47 | running_ = false; |
Chris Masone | 413a319 | 2011-05-09 17:10:05 -0700 | [diff] [blame] | 48 | adaptor_->UpdateRunning(); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 51 | void Manager::RegisterDevice(DeviceRefPtr to_manage) { |
| 52 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 53 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 54 | if (to_manage.get() == it->get()) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 55 | return; |
| 56 | } |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 57 | devices_.push_back(to_manage); |
Paul Stewart | f1ce5d2 | 2011-05-19 13:10:20 -0700 | [diff] [blame] | 58 | |
| 59 | // TODO(pstew): Should check configuration |
| 60 | if (running_) |
| 61 | to_manage->Start(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 64 | void Manager::DeregisterDevice(DeviceConstRefPtr to_forget) { |
| 65 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 66 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 67 | if (to_forget.get() == it->get()) { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 68 | devices_.erase(it); |
| 69 | return; |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 74 | void Manager::RegisterService(ServiceRefPtr to_manage) { |
| 75 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 76 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 77 | if (to_manage.get() == it->get()) |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 78 | return; |
| 79 | } |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 80 | services_.push_back(to_manage); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 83 | void Manager::DeregisterService(ServiceConstRefPtr to_forget) { |
| 84 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 85 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 86 | if (to_forget.get() == it->get()) { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 87 | services_.erase(it); |
| 88 | return; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void Manager::FilterByTechnology(Device::Technology tech, |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 94 | vector<DeviceRefPtr> *found) { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 95 | CHECK(found); |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 96 | vector<DeviceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 97 | for (it = devices_.begin(); it != devices_.end(); ++it) { |
| 98 | if ((*it)->TechnologyIs(tech)) |
| 99 | found->push_back(*it); |
| 100 | } |
| 101 | } |
| 102 | |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 103 | ServiceRefPtr Manager::FindService(const std::string& name) { |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 104 | vector<ServiceRefPtr>::iterator it; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 105 | for (it = services_.begin(); it != services_.end(); ++it) { |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 106 | if (name == (*it)->UniqueName()) { |
| 107 | return *it; |
| 108 | } |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 109 | } |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 110 | return NULL; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 113 | bool Manager::SetBoolProperty(const string& name, bool value, Error *error) { |
| 114 | VLOG(2) << "Setting " << name << " as a bool."; |
| 115 | // TODO(cmasone): Set actual properties. |
| 116 | return true; |
| 117 | } |
| 118 | |
| 119 | bool Manager::SetStringProperty(const string& name, |
| 120 | const string& value, |
| 121 | Error *error) { |
| 122 | VLOG(2) << "Setting " << name << " as a string."; |
| 123 | // TODO(cmasone): Set actual properties. |
| 124 | return true; |
| 125 | } |
| 126 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 127 | } // namespace shill |