blob: 9b77f8e7f2473a6dec31c139dc0c04539e7e4d11 [file] [log] [blame]
Paul Stewart75897df2011-04-27 09:05:53 -07001// 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 Stewart75897df2011-04-27 09:05:53 -07006#include <stdio.h>
Chris Masoneee929b72011-05-10 10:02:18 -07007
Paul Stewart75897df2011-04-27 09:05:53 -07008#include <string>
9
Chris Masoneee929b72011-05-10 10:02:18 -070010#include <base/logging.h>
Chris Masone9be4a9d2011-05-16 15:44:09 -070011#include <base/memory/ref_counted.h>
Chris Masoneee929b72011-05-10 10:02:18 -070012
Paul Stewart75897df2011-04-27 09:05:53 -070013#include "shill/control_interface.h"
Chris Masone9be4a9d2011-05-16 15:44:09 -070014#include "shill/device.h"
15#include "shill/device_info.h"
Paul Stewart75897df2011-04-27 09:05:53 -070016#include "shill/manager.h"
Chris Masone9be4a9d2011-05-16 15:44:09 -070017#include "shill/shill_event.h"
18#include "shill/service.h"
Paul Stewart75897df2011-04-27 09:05:53 -070019
20using std::string;
Chris Masone9be4a9d2011-05-16 15:44:09 -070021using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070022
23namespace shill {
24Manager::Manager(ControlInterface *control_interface,
Paul Stewart0af98bf2011-05-10 17:38:08 -070025 EventDispatcher *dispatcher)
Chris Masone413a3192011-05-09 17:10:05 -070026 : adaptor_(control_interface->CreateManagerAdaptor(this)),
Paul Stewart0af98bf2011-05-10 17:38:08 -070027 device_info_(dispatcher),
Paul Stewart75897df2011-04-27 09:05:53 -070028 running_(false) {
Chris Masoneee929b72011-05-10 10:02:18 -070029 // Initialize Interface monitor, so we can detect new interfaces
Chris Masoneb07006b2011-05-14 16:10:04 -070030 VLOG(2) << "Manager initialized.";
Paul Stewart75897df2011-04-27 09:05:53 -070031}
32
Paul Stewart0af98bf2011-05-10 17:38:08 -070033Manager::~Manager() {}
Paul Stewart75897df2011-04-27 09:05:53 -070034
35void Manager::Start() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070036 LOG(INFO) << "Manager started.";
Paul Stewart75897df2011-04-27 09:05:53 -070037 running_ = true;
Chris Masone413a3192011-05-09 17:10:05 -070038 adaptor_->UpdateRunning();
Paul Stewart0af98bf2011-05-10 17:38:08 -070039 device_info_.Start();
Paul Stewart75897df2011-04-27 09:05:53 -070040}
41
42void Manager::Stop() {
43 running_ = false;
Chris Masone413a3192011-05-09 17:10:05 -070044 adaptor_->UpdateRunning();
Paul Stewart75897df2011-04-27 09:05:53 -070045}
46
Chris Masone9be4a9d2011-05-16 15:44:09 -070047void 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
56void 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
66void 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
75void 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
85void 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
95Service* 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 Stewart75897df2011-04-27 09:05:53 -0700103} // namespace shill