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