blob: d105570fb8a9e065be0fa70b903c90e54d1716e1 [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 Masoned7732e42011-05-20 11:08:56 -070017#include "shill/dbus_adaptor.h"
Chris Masone9be4a9d2011-05-16 15:44:09 -070018#include "shill/shill_event.h"
19#include "shill/service.h"
Paul Stewart75897df2011-04-27 09:05:53 -070020
21using std::string;
Chris Masone9be4a9d2011-05-16 15:44:09 -070022using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070023
24namespace shill {
25Manager::Manager(ControlInterface *control_interface,
Paul Stewart0af98bf2011-05-10 17:38:08 -070026 EventDispatcher *dispatcher)
Chris Masone413a3192011-05-09 17:10:05 -070027 : adaptor_(control_interface->CreateManagerAdaptor(this)),
Paul Stewartb50f0b92011-05-16 16:31:42 -070028 device_info_(control_interface, dispatcher, this),
Paul Stewart75897df2011-04-27 09:05:53 -070029 running_(false) {
Chris Masoneee929b72011-05-10 10:02:18 -070030 // Initialize Interface monitor, so we can detect new interfaces
Chris Masoneb07006b2011-05-14 16:10:04 -070031 VLOG(2) << "Manager initialized.";
Paul Stewart75897df2011-04-27 09:05:53 -070032}
33
Paul Stewart0af98bf2011-05-10 17:38:08 -070034Manager::~Manager() {}
Paul Stewart75897df2011-04-27 09:05:53 -070035
36void Manager::Start() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070037 LOG(INFO) << "Manager started.";
Paul Stewart75897df2011-04-27 09:05:53 -070038 running_ = true;
Chris Masone413a3192011-05-09 17:10:05 -070039 adaptor_->UpdateRunning();
Paul Stewart0af98bf2011-05-10 17:38:08 -070040 device_info_.Start();
Paul Stewart75897df2011-04-27 09:05:53 -070041}
42
43void Manager::Stop() {
44 running_ = false;
Chris Masone413a3192011-05-09 17:10:05 -070045 adaptor_->UpdateRunning();
Paul Stewart75897df2011-04-27 09:05:53 -070046}
47
Chris Masone9be4a9d2011-05-16 15:44:09 -070048void 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 Stewartf1ce5d22011-05-19 13:10:20 -070055
56 // TODO(pstew): Should check configuration
57 if (running_)
58 to_manage->Start();
Chris Masone9be4a9d2011-05-16 15:44:09 -070059}
60
61void 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
71void 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
80void 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
90void 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 Stewartf1ce5d22011-05-19 13:10:20 -0700100Service* Manager::FindService(const std::string& name) {
Chris Masone9be4a9d2011-05-16 15:44:09 -0700101 vector<scoped_refptr<Service> >::iterator it;
102 for (it = services_.begin(); it != services_.end(); ++it) {
103 if (name == (*it)->name())
104 return it->get();
105 }
106}
107
Paul Stewart75897df2011-04-27 09:05:53 -0700108} // namespace shill