blob: fab11b008517b02bbd00bcf01c73ad8815b8af5e [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
Chris Masone8fe2c7e2011-06-09 15:51:19 -07005#include "shill/manager.h"
6
Paul Stewart75897df2011-04-27 09:05:53 -07007#include <time.h>
Paul Stewart75897df2011-04-27 09:05:53 -07008#include <stdio.h>
Chris Masoneee929b72011-05-10 10:02:18 -07009
Paul Stewart75897df2011-04-27 09:05:53 -070010#include <string>
11
Chris Masoneee929b72011-05-10 10:02:18 -070012#include <base/logging.h>
Chris Masone9be4a9d2011-05-16 15:44:09 -070013#include <base/memory/ref_counted.h>
Chris Masoneee929b72011-05-10 10:02:18 -070014
Chris Masoned0ceb8c2011-06-02 10:05:39 -070015#include "shill/adaptor_interfaces.h"
Paul Stewart75897df2011-04-27 09:05:53 -070016#include "shill/control_interface.h"
Chris Masoned0ceb8c2011-06-02 10:05:39 -070017#include "shill/dbus_adaptor.h"
Chris Masone9be4a9d2011-05-16 15:44:09 -070018#include "shill/device.h"
19#include "shill/device_info.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070020#include "shill/error.h"
Chris Masone9be4a9d2011-05-16 15:44:09 -070021#include "shill/shill_event.h"
22#include "shill/service.h"
Paul Stewart75897df2011-04-27 09:05:53 -070023
24using std::string;
Chris Masone9be4a9d2011-05-16 15:44:09 -070025using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070026
27namespace shill {
28Manager::Manager(ControlInterface *control_interface,
Paul Stewart0af98bf2011-05-10 17:38:08 -070029 EventDispatcher *dispatcher)
Chris Masone413a3192011-05-09 17:10:05 -070030 : adaptor_(control_interface->CreateManagerAdaptor(this)),
Paul Stewartb50f0b92011-05-16 16:31:42 -070031 device_info_(control_interface, dispatcher, this),
Paul Stewart75897df2011-04-27 09:05:53 -070032 running_(false) {
Chris Masoneee929b72011-05-10 10:02:18 -070033 // Initialize Interface monitor, so we can detect new interfaces
Chris Masoneb07006b2011-05-14 16:10:04 -070034 VLOG(2) << "Manager initialized.";
Paul Stewart75897df2011-04-27 09:05:53 -070035}
36
Paul Stewart0af98bf2011-05-10 17:38:08 -070037Manager::~Manager() {}
Paul Stewart75897df2011-04-27 09:05:53 -070038
39void Manager::Start() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070040 LOG(INFO) << "Manager started.";
Paul Stewart75897df2011-04-27 09:05:53 -070041 running_ = true;
Chris Masone413a3192011-05-09 17:10:05 -070042 adaptor_->UpdateRunning();
Paul Stewart0af98bf2011-05-10 17:38:08 -070043 device_info_.Start();
Paul Stewart75897df2011-04-27 09:05:53 -070044}
45
46void Manager::Stop() {
47 running_ = false;
Chris Masone413a3192011-05-09 17:10:05 -070048 adaptor_->UpdateRunning();
Paul Stewart75897df2011-04-27 09:05:53 -070049}
50
Chris Masonec1e50412011-06-07 13:04:53 -070051void Manager::RegisterDevice(DeviceRefPtr to_manage) {
52 vector<DeviceRefPtr>::iterator it;
Chris Masone9be4a9d2011-05-16 15:44:09 -070053 for (it = devices_.begin(); it != devices_.end(); ++it) {
Chris Masonec1e50412011-06-07 13:04:53 -070054 if (to_manage.get() == it->get())
Chris Masone9be4a9d2011-05-16 15:44:09 -070055 return;
56 }
Chris Masonec1e50412011-06-07 13:04:53 -070057 devices_.push_back(to_manage);
Paul Stewartf1ce5d22011-05-19 13:10:20 -070058
59 // TODO(pstew): Should check configuration
60 if (running_)
61 to_manage->Start();
Chris Masone9be4a9d2011-05-16 15:44:09 -070062}
63
Chris Masonec1e50412011-06-07 13:04:53 -070064void Manager::DeregisterDevice(DeviceConstRefPtr to_forget) {
65 vector<DeviceRefPtr>::iterator it;
Chris Masone9be4a9d2011-05-16 15:44:09 -070066 for (it = devices_.begin(); it != devices_.end(); ++it) {
Chris Masonec1e50412011-06-07 13:04:53 -070067 if (to_forget.get() == it->get()) {
Chris Masone9be4a9d2011-05-16 15:44:09 -070068 devices_.erase(it);
69 return;
70 }
71 }
72}
73
Chris Masonec1e50412011-06-07 13:04:53 -070074void Manager::RegisterService(ServiceRefPtr to_manage) {
75 vector<ServiceRefPtr>::iterator it;
Chris Masone9be4a9d2011-05-16 15:44:09 -070076 for (it = services_.begin(); it != services_.end(); ++it) {
Chris Masonec1e50412011-06-07 13:04:53 -070077 if (to_manage.get() == it->get())
Chris Masone9be4a9d2011-05-16 15:44:09 -070078 return;
79 }
Chris Masonec1e50412011-06-07 13:04:53 -070080 services_.push_back(to_manage);
Chris Masone9be4a9d2011-05-16 15:44:09 -070081}
82
Chris Masonec1e50412011-06-07 13:04:53 -070083void Manager::DeregisterService(ServiceConstRefPtr to_forget) {
84 vector<ServiceRefPtr>::iterator it;
Chris Masone9be4a9d2011-05-16 15:44:09 -070085 for (it = services_.begin(); it != services_.end(); ++it) {
Chris Masonec1e50412011-06-07 13:04:53 -070086 if (to_forget.get() == it->get()) {
Chris Masone9be4a9d2011-05-16 15:44:09 -070087 services_.erase(it);
88 return;
89 }
90 }
91}
92
93void Manager::FilterByTechnology(Device::Technology tech,
Chris Masonec1e50412011-06-07 13:04:53 -070094 vector<DeviceRefPtr> *found) {
Chris Masone9be4a9d2011-05-16 15:44:09 -070095 CHECK(found);
Chris Masonec1e50412011-06-07 13:04:53 -070096 vector<DeviceRefPtr>::iterator it;
Chris Masone9be4a9d2011-05-16 15:44:09 -070097 for (it = devices_.begin(); it != devices_.end(); ++it) {
98 if ((*it)->TechnologyIs(tech))
99 found->push_back(*it);
100 }
101}
102
Chris Masonee0dea762011-06-09 09:06:03 -0700103ServiceRefPtr Manager::FindService(const std::string& name) {
Chris Masonec1e50412011-06-07 13:04:53 -0700104 vector<ServiceRefPtr>::iterator it;
Chris Masone9be4a9d2011-05-16 15:44:09 -0700105 for (it = services_.begin(); it != services_.end(); ++it) {
Chris Masonee0dea762011-06-09 09:06:03 -0700106 if (name == (*it)->UniqueName()) {
107 return *it;
108 }
Chris Masone9be4a9d2011-05-16 15:44:09 -0700109 }
Chris Masonee0dea762011-06-09 09:06:03 -0700110 return NULL;
Chris Masone9be4a9d2011-05-16 15:44:09 -0700111}
112
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700113bool Manager::SetBoolProperty(const string& name, bool value, Error *error) {
114 VLOG(2) << "Setting " << name << " as a bool.";
115 // TODO(cmasone): Set actual properties.
116 return true;
117}
118
119bool Manager::SetStringProperty(const string& name,
120 const string& value,
121 Error *error) {
122 VLOG(2) << "Setting " << name << " as a string.";
123 // TODO(cmasone): Set actual properties.
124 return true;
125}
126
Paul Stewart75897df2011-04-27 09:05:53 -0700127} // namespace shill