blob: ce125fca0b52a9035305b2d3b99b0fee68aafc70 [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 Petkov3c5e4dc2012-04-02 14:44:27 +020017#include "shill/nss.h"
Darin Petkovab565bb2011-10-06 02:55:51 -070018#include "shill/proxy_factory.h"
Paul Stewartc1dec4d2011-12-08 15:25:28 -080019#include "shill/routing_table.h"
Paul Stewarta3c56f92011-05-26 07:08:52 -070020#include "shill/rtnl_handler.h"
Ben Chanfad4a0b2012-04-18 15:49:59 -070021#include "shill/scope_logger.h"
Chris Masone2ae797d2011-08-23 20:41:00 -070022#include "shill/shill_config.h"
Paul Stewart75897df2011-04-27 09:05:53 -070023
Paul Stewart75897df2011-04-27 09:05:53 -070024using std::string;
Gaurav Shah71354762011-11-28 19:22:49 -080025using std::vector;
Paul Stewart75897df2011-04-27 09:05:53 -070026
27namespace shill {
28
Darin Petkova7b89492011-07-27 12:48:17 -070029Daemon::Daemon(Config *config, ControlInterface *control)
30 : config_(config),
31 control_(control),
Darin Petkov3c5e4dc2012-04-02 14:44:27 +020032 nss_(NSS::GetInstance()),
Thieu Lefb46caf2012-03-08 11:57:15 -080033 proxy_factory_(ProxyFactory::GetInstance()),
34 rtnl_handler_(RTNLHandler::GetInstance()),
35 routing_table_(RoutingTable::GetInstance()),
36 dhcp_provider_(DHCPProvider::GetInstance()),
37 manager_(new Manager(control_,
38 &dispatcher_,
39 &metrics_,
40 &glib_,
41 config->GetRunDirectory(),
42 config->GetStorageDirectory(),
43 config->GetUserStorageDirectoryFormat())) {
Chris Masone2ae797d2011-08-23 20:41:00 -070044}
Paul Stewart75897df2011-04-27 09:05:53 -070045Daemon::~Daemon() {}
46
mukesh agrawal8f317b62011-07-15 11:53:23 -070047void Daemon::AddDeviceToBlackList(const string &device_name) {
Thieu Lefb46caf2012-03-08 11:57:15 -080048 manager_->AddDeviceToBlackList(device_name);
mukesh agrawal8f317b62011-07-15 11:53:23 -070049}
50
Gaurav Shah71354762011-11-28 19:22:49 -080051void Daemon::SetStartupProfiles(const vector<string> &profile_name_list) {
52 Error error;
Thieu Lefb46caf2012-03-08 11:57:15 -080053 manager_->set_startup_profiles(profile_name_list);
Thieu Le1271d682011-11-02 22:48:19 +000054}
55
Paul Stewart75897df2011-04-27 09:05:53 -070056void Daemon::Run() {
Paul Stewart0af98bf2011-05-10 17:38:08 -070057 Start();
Ben Chanfad4a0b2012-04-18 15:49:59 -070058 SLOG(Daemon, 1) << "Running main loop.";
Chris Masonec5b392e2011-05-14 16:31:01 -070059 dispatcher_.DispatchForever();
Ben Chanfad4a0b2012-04-18 15:49:59 -070060 SLOG(Daemon, 1) << "Exited main loop.";
Thieu Le1271d682011-11-02 22:48:19 +000061 Stop();
62}
63
64void Daemon::Quit() {
Eric Shienbrood3e20a232012-02-16 11:35:56 -050065 dispatcher_.PostTask(MessageLoop::QuitClosure());
Paul Stewart75897df2011-04-27 09:05:53 -070066}
67
Gaurav Shah71354762011-11-28 19:22:49 -080068void Daemon::Start() {
69 glib_.TypeInit();
Darin Petkov3c5e4dc2012-04-02 14:44:27 +020070 nss_->Init(&glib_);
Thieu Lefb46caf2012-03-08 11:57:15 -080071 proxy_factory_->Init();
72 rtnl_handler_->Start(&dispatcher_, &sockets_);
73 routing_table_->Start();
74 dhcp_provider_->Init(control_, &dispatcher_, &glib_);
75 manager_->Start();
Gaurav Shah71354762011-11-28 19:22:49 -080076}
77
78void Daemon::Stop() {
Thieu Lefb46caf2012-03-08 11:57:15 -080079 manager_->Stop();
Gaurav Shah71354762011-11-28 19:22:49 -080080}
Paul Stewart75897df2011-04-27 09:05:53 -070081
82} // namespace shill