blob: 215c24e076007c14d35ab681518417769c7bfaff [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
Chris Masoned0ceb8c2011-06-02 10:05:39 -070013#include "shill/adaptor_interfaces.h"
Paul Stewart75897df2011-04-27 09:05:53 -070014#include "shill/control_interface.h"
Chris Masoned0ceb8c2011-06-02 10:05:39 -070015#include "shill/dbus_adaptor.h"
Chris Masone9be4a9d2011-05-16 15:44:09 -070016#include "shill/device.h"
17#include "shill/device_info.h"
Paul Stewart75897df2011-04-27 09:05:53 -070018#include "shill/manager.h"
Chris Masone9be4a9d2011-05-16 15:44:09 -070019#include "shill/shill_event.h"
20#include "shill/service.h"
Paul Stewart75897df2011-04-27 09:05:53 -070021
22using std::string;
Chris Masone9be4a9d2011-05-16 15:44:09 -070023using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070024
25namespace shill {
26Manager::Manager(ControlInterface *control_interface,
Paul Stewart0af98bf2011-05-10 17:38:08 -070027 EventDispatcher *dispatcher)
Chris Masone413a3192011-05-09 17:10:05 -070028 : adaptor_(control_interface->CreateManagerAdaptor(this)),
Paul Stewartb50f0b92011-05-16 16:31:42 -070029 device_info_(control_interface, dispatcher, this),
Paul Stewart75897df2011-04-27 09:05:53 -070030 running_(false) {
Chris Masoneee929b72011-05-10 10:02:18 -070031 // Initialize Interface monitor, so we can detect new interfaces
Chris Masoneb07006b2011-05-14 16:10:04 -070032 VLOG(2) << "Manager initialized.";
Paul Stewart75897df2011-04-27 09:05:53 -070033}
34
Paul Stewart0af98bf2011-05-10 17:38:08 -070035Manager::~Manager() {}
Paul Stewart75897df2011-04-27 09:05:53 -070036
37void Manager::Start() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070038 LOG(INFO) << "Manager started.";
Paul Stewart75897df2011-04-27 09:05:53 -070039 running_ = true;
Chris Masone413a3192011-05-09 17:10:05 -070040 adaptor_->UpdateRunning();
Paul Stewart0af98bf2011-05-10 17:38:08 -070041 device_info_.Start();
Paul Stewart75897df2011-04-27 09:05:53 -070042}
43
44void Manager::Stop() {
45 running_ = false;
Chris Masone413a3192011-05-09 17:10:05 -070046 adaptor_->UpdateRunning();
Paul Stewart75897df2011-04-27 09:05:53 -070047}
48
Chris Masone9be4a9d2011-05-16 15:44:09 -070049void Manager::RegisterDevice(Device *to_manage) {
50 vector<scoped_refptr<Device> >::iterator it;
51 for (it = devices_.begin(); it != devices_.end(); ++it) {
52 if (to_manage == it->get())
53 return;
54 }
55 devices_.push_back(scoped_refptr<Device>(to_manage));
Paul Stewartf1ce5d22011-05-19 13:10:20 -070056
57 // TODO(pstew): Should check configuration
58 if (running_)
59 to_manage->Start();
Chris Masone9be4a9d2011-05-16 15:44:09 -070060}
61
62void Manager::DeregisterDevice(const Device *to_forget) {
63 vector<scoped_refptr<Device> >::iterator it;
64 for (it = devices_.begin(); it != devices_.end(); ++it) {
65 if (to_forget == it->get()) {
66 devices_.erase(it);
67 return;
68 }
69 }
70}
71
72void Manager::RegisterService(Service *to_manage) {
73 vector<scoped_refptr<Service> >::iterator it;
74 for (it = services_.begin(); it != services_.end(); ++it) {
75 if (to_manage == it->get())
76 return;
77 }
78 services_.push_back(scoped_refptr<Service>(to_manage));
79}
80
81void Manager::DeregisterService(const Service *to_forget) {
82 vector<scoped_refptr<Service> >::iterator it;
83 for (it = services_.begin(); it != services_.end(); ++it) {
84 if (to_forget == it->get()) {
85 services_.erase(it);
86 return;
87 }
88 }
89}
90
91void Manager::FilterByTechnology(Device::Technology tech,
92 vector<scoped_refptr<Device> > *found) {
93 CHECK(found);
94 vector<scoped_refptr<Device> >::iterator it;
95 for (it = devices_.begin(); it != devices_.end(); ++it) {
96 if ((*it)->TechnologyIs(tech))
97 found->push_back(*it);
98 }
99}
100
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700101Service* Manager::FindService(const std::string& name) {
Chris Masone9be4a9d2011-05-16 15:44:09 -0700102 vector<scoped_refptr<Service> >::iterator it;
103 for (it = services_.begin(); it != services_.end(); ++it) {
Chris Masonea82b7112011-05-25 15:16:29 -0700104 if (name == (*it)->UniqueName())
Chris Masone9be4a9d2011-05-16 15:44:09 -0700105 return it->get();
106 }
107}
108
Paul Stewart75897df2011-04-27 09:05:53 -0700109} // namespace shill