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