blob: d4782be1365daf9c8e3f6be23ef15ffed8e76afe [file] [log] [blame]
Thieu Le3426c8f2012-01-11 17:35:11 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewart75897df2011-04-27 09:05:53 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Darin Petkova7b89492011-07-27 12:48:17 -07005#include "shill/shill_daemon.h"
Paul Stewart75897df2011-04-27 09:05:53 -07006
Darin Petkova7b89492011-07-27 12:48:17 -07007#include <stdio.h>
8
Paul Stewart75897df2011-04-27 09:05:53 -07009#include <string>
Gaurav Shah71354762011-11-28 19:22:49 -080010#include <vector>
Paul Stewart75897df2011-04-27 09:05:53 -070011
Chris Masone2ae797d2011-08-23 20:41:00 -070012#include <base/file_path.h>
Chris Masoneee929b72011-05-10 10:02:18 -070013#include <base/logging.h>
14
Darin Petkova7b89492011-07-27 12:48:17 -070015#include "shill/dhcp_provider.h"
Gaurav Shah71354762011-11-28 19:22:49 -080016#include "shill/error.h"
Darin Petkovab565bb2011-10-06 02:55:51 -070017#include "shill/proxy_factory.h"
Paul Stewartc1dec4d2011-12-08 15:25:28 -080018#include "shill/routing_table.h"
Paul Stewarta3c56f92011-05-26 07:08:52 -070019#include "shill/rtnl_handler.h"
Chris Masone2ae797d2011-08-23 20:41:00 -070020#include "shill/shill_config.h"
Paul Stewart75897df2011-04-27 09:05:53 -070021
Paul Stewart75897df2011-04-27 09:05:53 -070022using std::string;
Gaurav Shah71354762011-11-28 19:22:49 -080023using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070024
25namespace shill {
26
Darin Petkova7b89492011-07-27 12:48:17 -070027Daemon::Daemon(Config *config, ControlInterface *control)
28 : config_(config),
29 control_(control),
Thieu Lefb46caf2012-03-08 11:57:15 -080030 proxy_factory_(ProxyFactory::GetInstance()),
31 rtnl_handler_(RTNLHandler::GetInstance()),
32 routing_table_(RoutingTable::GetInstance()),
33 dhcp_provider_(DHCPProvider::GetInstance()),
34 manager_(new Manager(control_,
35 &dispatcher_,
36 &metrics_,
37 &glib_,
38 config->GetRunDirectory(),
39 config->GetStorageDirectory(),
40 config->GetUserStorageDirectoryFormat())) {
Chris Masone2ae797d2011-08-23 20:41:00 -070041}
Paul Stewart75897df2011-04-27 09:05:53 -070042Daemon::~Daemon() {}
43
mukesh agrawal8f317b62011-07-15 11:53:23 -070044void Daemon::AddDeviceToBlackList(const string &device_name) {
Thieu Lefb46caf2012-03-08 11:57:15 -080045 manager_->AddDeviceToBlackList(device_name);
mukesh agrawal8f317b62011-07-15 11:53:23 -070046}
47
Gaurav Shah71354762011-11-28 19:22:49 -080048void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) {
49 Error error;
Thieu Lefb46caf2012-03-08 11:57:15 -080050 manager_->set_startup_profiles(profile_name_list);
Thieu Le1271d682011-11-02 22:48:19 +000051}
52
Paul Stewart75897df2011-04-27 09:05:53 -070053void Daemon::Run() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070054 Start();
Chris Masoneb07006b2011-05-14 16:10:04 -070055 VLOG(1) << "Running main loop.";
Chris Masonec5b392e2011-05-14 16:31:01 -070056 dispatcher_.DispatchForever();
Thieu Le1271d682011-11-02 22:48:19 +000057 VLOG(1) << "Exited main loop.";
58 Stop();
59}
60
61void Daemon::Quit() {
Eric Shienbrood3e20a232012-02-16 11:35:56 -050062 dispatcher_.PostTask(MessageLoop::QuitClosure());
Paul Stewart75897df2011-04-27 09:05:53 -070063}
64
Gaurav Shah71354762011-11-28 19:22:49 -080065void Daemon::Start() {
66 glib_.TypeInit();
Thieu Lefb46caf2012-03-08 11:57:15 -080067 proxy_factory_->Init();
68 rtnl_handler_->Start(&dispatcher_, &sockets_);
69 routing_table_->Start();
70 dhcp_provider_->Init(control_, &dispatcher_, &glib_);
71 manager_->Start();
Gaurav Shah71354762011-11-28 19:22:49 -080072}
73
74void Daemon::Stop() {
Thieu Lefb46caf2012-03-08 11:57:15 -080075 manager_->Stop();
Gaurav Shah71354762011-11-28 19:22:49 -080076}
Paul Stewart75897df2011-04-27 09:05:53 -070077
78} // namespace shill